-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (68 loc) · 2.4 KB
/
sync-upstream.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
name: Sync upstream
on:
schedule:
- cron: '54 3 * * 0' # every Sunday at 03:54
workflow_dispatch:
jobs:
sync-upstream:
name: 'Sync upstream'
runs-on: elvia-runner
permissions:
contents: write
env:
BASE_BRANCH: 'trunk'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ env.BASE_BRANCH }}
- name: Setup Go
uses: actions/setup-go@v5
- name: Setup Packer
uses: hashicorp/setup-packer@v3
- name: Run update script
run: go run main.go
env:
ACCEPT_ALL: 'true'
- name: Get GitHub App token for repository
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- name: Commit changes and set branch name
run: |
if [[ -z "$(git status --porcelain)" ]]; then
echo 'No changes to commit.'
echo "GIT_CHANGES=false" >> $GITHUB_ENV
exit 0
fi
branch_name="chore/update-runner-image-$(date +%s)"
echo "BRANCH_NAME=$branch_name" >> $GITHUB_ENV
git config user.email '${{ vars.GH_APP_USER_EMAIL }}'
git config user.name '${{ vars.GH_APP_USERNAME }}'
git checkout -b "$branch_name"
git add .
git commit -m 'Update runner image'
git push -u origin "$branch_name"
- name: Create pull request
uses: actions/github-script@v7
if: ${{ env.GIT_CHANGES != 'false' }}
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const { owner, repo } = context.repo;
const title = '⬆️ Runner image update';
const body = `## ${title}
This pull request updates the Packer configuration to the latest commit from [runner-images](https://github.com/actions/runner-images).
It should be automatically merged by **${{ vars.GH_APP_USERNAME }}** once the integration tests pass.
`;
const { data: pullRequest } = await github.rest.pulls.create({
owner,
repo,
title,
head: '${{ env.BRANCH_NAME }}',
base: 'trunk',
body,
})
console.log(`Created pull request: ${pullRequest.html_url}`)