-
Notifications
You must be signed in to change notification settings - Fork 3.3k
59 lines (53 loc) · 1.85 KB
/
v2-sync.yml
File metadata and controls
59 lines (53 loc) · 1.85 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
# Automatically creates a PR to merge main (v1) into v2 to keep v2 up to date.
# The oncall is responsible for reviewing and merging the sync PR.
name: "Sync: main -> v2"
on:
schedule:
- cron: '0 6 * * *' # Daily at 6am UTC
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: v2
fetch-depth: 0
token: ${{ secrets.RELEASE_PAT }}
- name: Check for new commits on main
id: check
run: |
git fetch origin main
BEHIND=$(git rev-list --count HEAD..origin/main)
echo "behind=$BEHIND" >> $GITHUB_OUTPUT
if [ "$BEHIND" -eq 0 ]; then
echo "v2 is up to date with main, nothing to sync"
else
echo "v2 is $BEHIND commit(s) behind main"
fi
- name: Check for existing sync PR
if: steps.check.outputs.behind != '0'
id: existing
env:
GH_TOKEN: ${{ github.token }}
run: |
PR=$(gh pr list --base v2 --head main --state open --json number --jq '.[0].number // empty')
if [ -n "$PR" ]; then
echo "Sync PR #$PR already exists, skipping"
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Create sync PR
if: steps.check.outputs.behind != '0' && steps.existing.outputs.exists == 'false'
env:
GH_TOKEN: ${{ secrets.RELEASE_PAT }}
run: |
gh pr create \
--base v2 \
--head main \
--title "chore: sync main -> v2" \
--body "Automated sync of v1 changes from main into v2. The oncall is responsible for reviewing and merging this PR. Resolve conflicts in favor of the v2 implementation."