-
Notifications
You must be signed in to change notification settings - Fork 18
118 lines (104 loc) · 3.71 KB
/
Copy pathauto-update-components.yml
File metadata and controls
118 lines (104 loc) · 3.71 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Auto-update component versions
on:
schedule:
- cron: '0 6 * * *' # daily at 6 AM UTC
workflow_dispatch:
inputs:
branch:
description: 'Update a single branch (leave empty for all)'
required: false
type: string
permissions:
contents: write
pull-requests: write
jobs:
update:
strategy:
matrix:
include:
- branch: main
update_mode: latest
- branch: release-v1.15.x
update_mode: patch
- branch: release-v1.20.x
update_mode: patch
- branch: release-v1.21.x
update_mode: patch
- branch: release-v1.22.x
update_mode: patch
- branch: release-v1.23.x
update_mode: patch
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Check if branch exists
id: check-branch
if: ${{ !inputs.branch || inputs.branch == matrix.branch }}
env:
GH_TOKEN: ${{ github.token }}
MATRIX_BRANCH: ${{ matrix.branch }}
run: |
if gh api "repos/${{ github.repository }}/branches/${MATRIX_BRANCH}" --silent 2>/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "Branch ${MATRIX_BRANCH} does not exist, skipping"
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Fetch update script
if: steps.check-branch.outputs.exists == 'true'
run: |
gh api "repos/${{ github.repository }}/contents/.github/scripts/update-patch-versions.sh?ref=${{ github.ref_name }}" \
--jq '.content' | base64 -d > /tmp/update-patch-versions.sh
env:
GH_TOKEN: ${{ github.token }}
- name: Checkout
if: steps.check-branch.outputs.exists == 'true'
uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
- name: Set up Go
if: steps.check-branch.outputs.exists == 'true'
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Check for updates
if: steps.check-branch.outputs.exists == 'true'
id: update
run: bash /tmp/update-patch-versions.sh
env:
GH_TOKEN: ${{ github.token }}
UPDATE_MODE: ${{ matrix.update_mode }}
- name: Create or update pull request
if: steps.update.outputs.has_updates == 'true'
env:
GH_TOKEN: ${{ github.token }}
MATRIX_BRANCH: ${{ matrix.branch }}
UPDATE_SUMMARY: ${{ steps.update.outputs.summary }}
run: |
PR_BRANCH="auto-update/component-versions/${MATRIX_BRANCH}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -B "${PR_BRANCH}"
git add -A
git commit -m "Update component versions for ${MATRIX_BRANCH}"
git push -f origin "${PR_BRANCH}"
EXISTING_PR=$(gh pr list \
--base "${MATRIX_BRANCH}" \
--head "${PR_BRANCH}" \
--json number \
--jq '.[0].number' 2>/dev/null) || true
if [[ -n "$EXISTING_PR" ]]; then
echo "PR #${EXISTING_PR} updated via force push"
else
gh pr create \
--base "${MATRIX_BRANCH}" \
--head "${PR_BRANCH}" \
--title "[${MATRIX_BRANCH}] Update component versions" \
--body "$(cat <<EOF
## Component version updates
${UPDATE_SUMMARY}
---
*This PR was automatically created by the [auto-update workflow](https://github.com/${{ github.repository }}/actions/workflows/auto-update-components.yml).*
EOF
)"
fi