Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sync-upstream workflows #7

Merged
merged 106 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 93 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
1f3f192
Add ARM64 packer template, update scripts for multiple architectures …
guicaulada May 15, 2024
98b7792
Fix AMIs being deregisterd and minor issues after upstream merge (#5)
guicaulada May 16, 2024
03f0702
Add sync-upstream.yml workflow
guicaulada Jun 10, 2024
b85248f
Add pull_request trigger to test the workflow
guicaulada Jun 10, 2024
12e3a08
Modify workflow to allow PR to be created with conflicts
guicaulada Jun 10, 2024
7fef6b4
Give permissions to workflow so it can edit actions
guicaulada Jun 10, 2024
b576376
Remove unnecessary permissions
guicaulada Jun 10, 2024
acdc3d5
Use temporary github app
guicaulada Jun 11, 2024
4adbeb4
Try to fix issues with token
guicaulada Jun 11, 2024
36b403f
Solve set-output deprecation warning
guicaulada Jun 11, 2024
e6fe186
General improvements to the workflow
guicaulada Jun 11, 2024
293ccae
Set GH_TOKEN env for GitHub CLI
guicaulada Jun 11, 2024
91adcf6
Try to remove configure git to see what happens
guicaulada Jun 11, 2024
4b8fa66
Re-add configure git step
guicaulada Jun 11, 2024
a75e541
Configure git to use bot user
guicaulada Jun 11, 2024
f3bb5ed
Use test bot user
guicaulada Jun 11, 2024
c75b296
Stop the workflow from PR loop
guicaulada Jun 11, 2024
f084b94
Fix shell condition typo
guicaulada Jun 11, 2024
9fcda9f
Add TODO comments to remove test steps and triggers
guicaulada Jun 11, 2024
9181e54
Use the rebase approach
guicaulada Jun 12, 2024
f354804
Remove unnecessary steps
guicaulada Jun 12, 2024
c767c2b
Try using multi-line string for issue
guicaulada Jun 12, 2024
ee5198e
Add message to close issue once update is complete
guicaulada Jun 12, 2024
0f4f4dc
Revert unintended rebase changes
guicaulada Jun 12, 2024
1312088
Add ref main on checkout
guicaulada Jun 12, 2024
460506c
Fall back to creating a PR
guicaulada Jun 14, 2024
1401ffe
Update PR body
guicaulada Jun 14, 2024
4d55518
Fix quotes issue
guicaulada Jun 14, 2024
27c9c90
Escape single quote instead
guicaulada Jun 14, 2024
879593a
Try to fix format
guicaulada Jun 14, 2024
f5e51aa
Add workflow so bot can push changes to main
guicaulada Jun 14, 2024
5c5f624
Rename actions
guicaulada Jun 14, 2024
ab7efcc
Add changes workflow
guicaulada Jun 14, 2024
a046548
Add test step to merge workflow
guicaulada Jun 14, 2024
496b1cd
Fix changes workflow
guicaulada Jun 14, 2024
0e93c6b
Force push on re-runs
guicaulada Jun 14, 2024
a4fa264
Add or option to range-diff check
guicaulada Jun 14, 2024
6e5c5eb
Update changes check
guicaulada Jun 14, 2024
ff6546e
Add gh pr view for reruns
guicaulada Jun 14, 2024
0655439
Add link to workflow on PR.
guicaulada Jun 14, 2024
86e8dd0
Add different body for conflicts
guicaulada Jun 14, 2024
c9d4368
Use GITHUB_OUTPUT
guicaulada Jun 14, 2024
9fdd256
Handle multi line variable on GITHUB_OUTPUT
guicaulada Jun 14, 2024
236115b
Try to escape back-tick
guicaulada Jun 14, 2024
e3feaa6
Use single quotes for PR body
guicaulada Jun 14, 2024
bd73be1
Fix pr-body output
guicaulada Jun 14, 2024
d6965cc
Body has to be in single quotes
guicaulada Jun 14, 2024
29ab8cf
Simulate conflicts
guicaulada Jun 14, 2024
a82260a
Fix conflicts check on pr-body
guicaulada Jun 14, 2024
6e11081
Revert "Simulate conflicts"
guicaulada Jun 14, 2024
ab50398
Use sha references for third-party actions
guicaulada Jun 18, 2024
6d3bc2c
Add details to no conflict PR body
guicaulada Jun 18, 2024
3320a41
Fix sed issue
guicaulada Jun 18, 2024
450d54c
Use different delimiter for sed
guicaulada Jun 18, 2024
b130085
Try to fix sed
guicaulada Jun 18, 2024
c45ab05
Use awk instead of sed for multi-line replace
guicaulada Jun 18, 2024
a3a9c47
Add output too large error message
guicaulada Jun 18, 2024
9470eab
Test details too large
guicaulada Jun 18, 2024
db52431
Revert "Test details too large"
guicaulada Jun 18, 2024
83cd49e
Remove GitHub app
guicaulada Jun 18, 2024
36eac3a
Use upstream sha on manual rebase
guicaulada Jun 18, 2024
9a61409
Push to gc/test for testing
guicaulada Jun 18, 2024
f7783b3
Fix user
guicaulada Jun 18, 2024
c819a7a
Fix variable on push workflow
guicaulada Jun 18, 2024
219b8e0
Use different exit code so for push error
guicaulada Jun 18, 2024
d193c2e
Use ref on checkout
guicaulada Jun 18, 2024
0dae3d1
Remove unnecessary fetch
guicaulada Jun 18, 2024
da3c0e8
Fix grep
guicaulada Jun 18, 2024
a04ba93
Try using fetch for test branch
guicaulada Jun 18, 2024
f3aba88
Fix pushing current branch to main
guicaulada Jun 18, 2024
7f5dbb3
Remove unnecessary close PR step
guicaulada Jun 18, 2024
3bc321d
Tag current main before push
guicaulada Jun 18, 2024
a2786e4
Fix tagging of remote branch
guicaulada Jun 18, 2024
721b75d
Fix pushing tag
guicaulada Jun 18, 2024
ed54dfb
Fix tagging
guicaulada Jun 18, 2024
211db46
Really fix tagging
guicaulada Jun 18, 2024
45f9a74
Fix grep issue on tag
guicaulada Jun 18, 2024
25f4f83
Switch to merge approach
guicaulada Jun 19, 2024
09752fd
Update workflow name
guicaulada Jun 19, 2024
87e65cb
Add GH token environment variable
guicaulada Jun 19, 2024
7f28585
Why is this failing?
guicaulada Jun 19, 2024
52afd54
doesn't make sense
guicaulada Jun 19, 2024
29bac33
Double quotes are important and mac/linux differences are annoying
guicaulada Jun 19, 2024
758f93d
Push to main instead of merging PR
guicaulada Jun 19, 2024
e078315
Minor fixes on wording
guicaulada Jun 19, 2024
333de7c
Fix quotes on merge commit message
guicaulada Jun 19, 2024
fe49c12
Fix merge command
guicaulada Jun 19, 2024
8bbf142
Simulate conflicts
guicaulada Jun 19, 2024
fc563aa
Simulate conflicts and improve PR format
guicaulada Jun 19, 2024
c07c9f3
Add review and approve comment
guicaulada Jun 19, 2024
22de9c2
Fix missing sha on commit message for conflict guide
guicaulada Jun 19, 2024
ea9f249
Revert conflicts simulation
guicaulada Jun 19, 2024
2df77db
Add more TODOs
guicaulada Jun 19, 2024
75a9a1e
Apply suggestions from code review
guicaulada Jun 20, 2024
3cf1b7e
Fix git merge condition
guicaulada Jun 20, 2024
b90727b
Add error comment on push failure
guicaulada Jun 20, 2024
a5d374f
Rename sync-upstream-push to sync-upstream-approve
guicaulada Jun 20, 2024
9f280a1
Rename sync-upstream-approve to approved
guicaulada Jun 20, 2024
d69962d
Add review body check
guicaulada Jun 20, 2024
0f40332
Try using templates for PR body
guicaulada Jun 20, 2024
87df3dc
Add step to merge feature branch on change for testing
guicaulada Jun 20, 2024
0f011b3
Rename workflows to match bot commands
guicaulada Jun 20, 2024
4e290a7
Add command explanation on the PR body
guicaulada Jun 20, 2024
0f37e4f
Apply suggestions from code review
guicaulada Jun 21, 2024
6c912eb
Move pr-body env variables to env block
guicaulada Jun 21, 2024
feea374
Remove TODOs from workflow
guicaulada Jun 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/sync-upstream-change.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Sync with Upstream (change)

on:
pull_request_review:
types: [submitted]

jobs:
sync:
runs-on: ubuntu-latest
if: github.event.review.state == 'changes_requested' && startsWith(github.event.pull_request.head.ref, 'sync-upstream-')
guicaulada marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Checkout the repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}

- name: Reset branch to main
run: |
git reset --hard origin/main

- name: Configure Git
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"

- name: Pull changes from upstream and merge
id: merge
run: |
git remote add upstream https://github.com/actions/runner-images.git
git fetch upstream
SHA=$(git rev-parse upstream/main)
guicaulada marked this conversation as resolved.
Show resolved Hide resolved
echo "upstream-sha=$SHA" >> $GITHUB_OUTPUT
git merge $SHA || echo "conflicts=true" >> $GITHUB_OUTPUT

- name: Push changes to branch
run: |
git push -f origin ${{ github.event.pull_request.head.ref }}

- name: Set PR body
guicaulada marked this conversation as resolved.
Show resolved Hide resolved
id: pr-body
run: |
PR_BODY_CONFLICTS='# :warning: UPSTREAM CHANGES. DO NOT MERGE MANUALLY.

This is an automated PR to merge updates from upstream. Please review the changes and approve. The bot will be responsible for merging the changes to main and closing the PR.

This pull request was created by the [Sync from Upstream (create)](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) workflow.

This PR contains an empty commit due to conflicts during merge. To merge the changes manually, use the following commands:
```
# Checkout the branch
git checkout sync-upstream-${{ github.run_number }}
# Reset the branch to main
git reset --hard origin/main
# Pull changes from upstream
git remote add upstream https://github.com/actions/runner-images.git
git fetch upstream
# Merge the changes
git merge -m "Merge commit '${{ steps.merge.outputs.upstream-sha }}' from actions/runner-images" ${{ steps.merge.outputs.upstream-sha }}

# Solve the conflicts and continue the merge
git merge --continue

# Push the changes to the branch
git push -f origin sync-upstream-${{ github.run_number }}
```

Once you have merged the changes successfully, please review and approve this pull request.

### :x: CONFLICTS DURING MERGE. PLEASE HANDLE THE CONFLICTS APPROPRIATELY.'

PR_BODY_NO_CONFLICTS='# :warning: UPSTREAM CHANGES. DO NOT MERGE MANUALLY.

This is an automated PR to merge updates from upstream. Please review the changes and approve. The bot will be responsible for pushing the changes to main and closing the PR.

This pull request was created by the [Sync from Upstream (create)](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) workflow.

### :white_check_mark: NO CONFLICTS DURING MERGE.'

echo 'body<<EOF' >> $GITHUB_OUTPUT
if [ "${{ steps.merge.outputs.conflicts }}" == "true" ]; then
echo "$PR_BODY_CONFLICTS" >> $GITHUB_OUTPUT
else
echo "$PR_BODY_NO_CONFLICTS" >> $GITHUB_OUTPUT
fi
echo EOF >> $GITHUB_OUTPUT

- name: Edit pull request
env:
GH_TOKEN: ${{ github.token }}
run: |
gh pr edit sync-upstream-${{ github.run_number }} \
--repo ${{ github.repository }} \
--body '${{ steps.pr-body.outputs.body }}'
122 changes: 122 additions & 0 deletions .github/workflows/sync-upstream-create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Sync with Upstream (create)

on:
schedule:
- cron: "0 0 1 * *" # Runs at 00:00 on the first day of every month
workflow_dispatch:
# TODO: Remove this trigger once the workflow is ready
pull_request:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
sync:
runs-on: ubuntu-latest
# TODO: Remove this condition once the workflow is ready
if: github.event.pull_request.user.login != 'github-actions[bot]'
steps:
- name: Checkout the repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
ref: main

- name: Create new branch from main
run: |
git checkout -b sync-upstream-${{ github.run_number }}

- name: Configure Git
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"

#TODO: Remove this step once the workflow is ready
- name: Merge the feature branch for the workflow
run: |
git merge --squash origin/gc/sync-upstream
git commit -m "Add sync-upstream.yml workflow (#7)"

- name: Pull changes from upstream and merge
id: merge
run: |
git remote add upstream https://github.com/actions/runner-images.git
git fetch upstream
SHA=$(git rev-parse upstream/main)
guicaulada marked this conversation as resolved.
Show resolved Hide resolved
echo "upstream-sha=$SHA" >> $GITHUB_OUTPUT
git merge -m "Merge commit '$SHA' from actions/runner-images" $SHA || echo "conflicts=true" >> $GITHUB_OUTPUT
guicaulada marked this conversation as resolved.
Show resolved Hide resolved

- name: Handle conflicts with empty commit
if: steps.merge.outputs.conflicts == 'true'
run: |
git merge --abort
git commit --allow-empty -m "Empty commit due to merge conflicts"

- name: Push changes to new branch
run: |
git push -f origin sync-upstream-${{ github.run_number }}
guicaulada marked this conversation as resolved.
Show resolved Hide resolved

- name: Set PR body
id: pr-body
run: |
PR_BODY_CONFLICTS='# :warning: UPSTREAM CHANGES. DO NOT MERGE MANUALLY.

This is an automated PR to merge updates from upstream. Please review the changes and approve. The bot will be responsible for pushing the changes to main.

This pull request was created by the [Sync from Upstream (create)](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) workflow.

This PR contains an empty commit due to conflicts during merge. To merge the changes manually, use the following commands:
guicaulada marked this conversation as resolved.
Show resolved Hide resolved
```
# Checkout the branch
git checkout sync-upstream-${{ github.run_number }}
# Reset the branch to main
git reset --hard origin/main
# Pull changes from upstream
git remote add upstream https://github.com/actions/runner-images.git
git fetch upstream
# Merge the changes
git merge -m "Merge commit '${{ steps.merge.outputs.upstream-sha }}' from actions/runner-images" ${{ steps.merge.outputs.upstream-sha }}

# Solve the conflicts and continue the merge
git merge --continue

# Push the changes to the branch
git push -f origin sync-upstream-${{ github.run_number }}
guicaulada marked this conversation as resolved.
Show resolved Hide resolved
```

Once you have merged the changes successfully, please review and approve this pull request.
guicaulada marked this conversation as resolved.
Show resolved Hide resolved

### :x: CONFLICTS DURING MERGE. PLEASE HANDLE THE CONFLICTS APPROPRIATELY.'

PR_BODY_NO_CONFLICTS='# :warning: UPSTREAM CHANGES. DO NOT MERGE MANUALLY.

This is an automated PR to merge updates from upstream. Please review the changes and approve. The bot will be responsible for pushing the changes to main.

This pull request was created by the [Sync from Upstream (create)](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) workflow.

### :white_check_mark: NO CONFLICTS DURING MERGE.'

echo 'body<<EOF' >> $GITHUB_OUTPUT
if [ "${{ steps.merge.outputs.conflicts }}" == "true" ]; then
iainlane marked this conversation as resolved.
Show resolved Hide resolved
echo "$PR_BODY_CONFLICTS" >> $GITHUB_OUTPUT
else
echo "$PR_BODY_NO_CONFLICTS" >> $GITHUB_OUTPUT
fi
echo EOF >> $GITHUB_OUTPUT

# TODO: Change base branch once the workflow is ready
- name: Create pull request
env:
GH_TOKEN: ${{ github.token }}
run: |
gh pr create --title 'Update from upstream' \
--body '${{ steps.pr-body.outputs.body }}' \
--base gc/test --head sync-upstream-${{ github.run_number }} \
--repo ${{ github.repository }} \
|| \
gh pr edit sync-upstream-${{ github.run_number }} \
--repo ${{ github.repository }} \
--body '${{ steps.pr-body.outputs.body }}'
33 changes: 33 additions & 0 deletions .github/workflows/sync-upstream-push.yml
guicaulada marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Sync with Upstream (push)

on:
pull_request_review:
types: [submitted]

permissions:
contents: write
pull-requests: write

jobs:
sync:
runs-on: ubuntu-latest
if: github.event.review.state == 'approved' && startsWith(github.event.pull_request.head.ref, 'sync-upstream-')
guicaulada marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Checkout the repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}

- name: Configure Git
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"

# TODO: Change target branch to main once the workflow is ready
- name: Push changes to main and delete branch
env:
GH_TOKEN: ${{ github.token }}
guicaulada marked this conversation as resolved.
Show resolved Hide resolved
run: |
git push origin ${{ github.event.pull_request.head.ref }}:gc/test
guicaulada marked this conversation as resolved.
Show resolved Hide resolved
git push -d origin ${{ github.event.pull_request.head.ref }}
guicaulada marked this conversation as resolved.
Show resolved Hide resolved