forked from actions/runner-images
-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (83 loc) · 3.45 KB
/
sync-upstream-create.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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)"
echo "upstream-sha=$SHA" >> $GITHUB_OUTPUT
if ! git merge -m "Merge commit '$SHA' from actions/runner-images" "${SHA}"; then
echo "conflicts=true" >> $GITHUB_OUTPUT
fi
- 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 --force-with-lease origin sync-upstream-${{ github.run_number }}
- name: Set PR body
id: pr-body
run: |
export GITHUB_SERVER_URL='${{ github.server_url }}'
export GITHUB_REPOSITORY='${{ github.repository }}'
export GITHUB_RUN_ID='${{ github.run_id }}'
export GITHUB_RUN_NUMBER='${{ github.run_number }}'
export UPSTREAM_SHA='${{ steps.merge.outputs.upstream-sha }}'
PR_BODY_NO_CONFLICTS_TEMPLATE='.github/workflows/sync-upstream/templates/pr-body-no-conflicts.txt'
PR_BODY_WITH_CONFLICTS_TEMPLATE='.github/workflows/sync-upstream/templates/pr-body-with-conflicts.txt'
echo 'body<<EOF' >> $GITHUB_OUTPUT
if [ "${{ steps.merge.outputs.conflicts }}" == "true" ]; then
envsubst < $PR_BODY_WITH_CONFLICTS_TEMPLATE >> $GITHUB_OUTPUT
else
envsubst < $PR_BODY_NO_CONFLICTS_TEMPLATE >> $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 }}'