Skip to content

Commit

Permalink
chore(repo): ensure self mutation updates branch as well (#3922)
Browse files Browse the repository at this point in the history
Pull requests do not actually run workflows on the head of a given branch, it uses the merge commit between that head and the target head (e.g. `main`)

This means that when mutation patches are generated, they assume they're operating on the merge commit. This PR makes that assumption true when applying patches by also updating the branch itself.

adding do-not-merge to test, but feel free to review.

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
MarkMcCulloh authored Aug 23, 2023
1 parent f6a363a commit 116ee64
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ jobs:
name: dist
path: dist/*

# Create patch to go from the PR head to the merge commit
- name: Create git patch for merge
if: github.event_name == 'pull_request'
id: diff
run: |
git diff --binary --patch ${{ github.event.pull_request.head.sha }} ${{ github.sha }} > update.diff
if [ -s update.diff ]; then
echo "Diff found, creating a patch to apply later"
cat update.diff
echo "diff=true" >> $GITHUB_OUTPUT
fi
- name: Upload patch
if: steps.diff.outputs.diff == 'true'
uses: actions/upload-artifact@v3
with:
name: update.diff
path: update.diff

test:
name: Test
timeout-minutes: 30
Expand Down Expand Up @@ -293,8 +312,11 @@ jobs:
run: |
PATCH_COUNT=0
for f in $(find ./*.diff/*.diff); do
PATCH_COUNT=$((PATCH_COUNT + 1))
cat $f
# Exclude update.diff since we don't want to fail if the PR is just not up to date
if [ "$f" != "./update.diff/update.diff" ]; then
PATCH_COUNT=$((PATCH_COUNT + 1))
cat $f
fi
done
if [ $PATCH_COUNT -gt 0 ]; then
echo "Found $PATCH_COUNT patches, build failed. A self-mutation should happen soon."
Expand Down
34 changes: 24 additions & 10 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,35 @@ jobs:
if: steps.download-artifacts.outputs.found_artifact == 'true'
name: Apply downloaded pathes
working-directory: repo
env:
HEAD_REF: ${{ github.event.workflow_run.head_branch }}
run: |
git config user.name "monada-bot[bot]"
git config user.email "[email protected]"
# if ../patches/update.diff/update.diff exists, apply it first
UPDATE_PATCH_FILE="../patches/update.diff/update.diff"
if [ -f $UPDATE_PATCH_FILE ]; then
echo "Updating branch"
git apply --binary $UPDATE_PATCH_FILE
if [ $? -eq 0 ]; then
git add --all
git commit -s -m "Merge branch 'main' into $HEAD_REF"
echo "Patch applied successfully"
rm $UPDATE_PATCH_FILE
else
echo "Patch failed to apply"
cat $UPDATE_PATCH_FILE
exit 1
fi
fi
for f in $(find ../patches/*.diff/*.diff); do
echo "Applying $f"
git apply --binary $f
if [ $? -eq 0 ]; then
git add --all
git commit -s -m "chore: self mutation ($f)"
echo "Patch applied successfully"
rm $f
else
Expand All @@ -84,16 +108,6 @@ jobs:
fi
done
- name: Push changes
if: steps.download-artifacts.outputs.found_artifact == 'true'
working-directory: repo
env:
HEAD_REF: ${{ github.event.workflow_run.head_branch }}
run: |
git config user.name "monada-bot[bot]"
git config user.email "[email protected]"
git add --all
git commit -s -m "chore: self mutation"
git push origin HEAD:$HEAD_REF
- name: Add label to block auto merge
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/pull-request-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ on:
pull_request_target:
types:
- opened
- synchronize
- reopened
- edited
branches-ignore:
- mergify/merge-queue/**
- "mergify/merge-queue/*"

jobs:
validate:
Expand Down

0 comments on commit 116ee64

Please sign in to comment.