Repository navigation
159 lines (139 loc) · 5.94 KB
/
Copy pathsync-develop.yml
File metadata and controls
159 lines (139 loc) · 5.94 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Sync Develop
on:
# Sync once a day rather than on every master push. Each update re-runs the
# synchronization pull request's CI, and develop only needs master daily.
# This runs early enough to merge before the develop full CI at 02:43 UTC.
schedule:
- cron: "7 22 * * *"
workflow_dispatch:
concurrency:
group: sync-master-to-develop
cancel-in-progress: true
permissions: {}
jobs:
sync:
name: Merge master into develop
runs-on: ubuntu-latest
env:
SYNC_BRANCH: integration/master-to-develop
steps:
- name: Create release app token
id: release-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ vars.RELEASE_APP_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
permission-issues: write
permission-workflows: write
- uses: actions/checkout@v7
with:
ref: master
fetch-depth: 0
token: ${{ steps.release-token.outputs.token }}
- uses: $/.github/actions/setup-rust
- name: Create develop on first use
id: develop
env:
GH_TOKEN: ${{ steps.release-token.outputs.token }}
shell: bash
run: |
if git ls-remote --exit-code origin refs/heads/develop >/dev/null 2>&1; then
echo "created=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git push origin "HEAD:refs/heads/develop"
echo "created=true" >> "$GITHUB_OUTPUT"
- name: Open or update the master synchronization pull request
if: steps.develop.outputs.created != 'true'
env:
GH_TOKEN: ${{ steps.release-token.outputs.token }}
shell: bash
run: |
git fetch --no-tags origin refs/heads/develop:refs/remotes/origin/develop
master_sha="$(git rev-parse HEAD)"
# Do not use master itself as a pull request head. A queued develop
# synchronization would then hold the branch that master's own merge
# queue needs to advance. Remove any PR created by the old workflow
# before switching to the dedicated synchronization branch.
legacy_pr="$(
gh pr list \
--repo "$GITHUB_REPOSITORY" \
--state open \
--base develop \
--head master \
--json number,isCrossRepository \
--jq '[.[] | select(.isCrossRepository == false)][0].number // empty'
)"
if [ -n "$legacy_pr" ]; then
gh pr close "$legacy_pr" --repo "$GITHUB_REPOSITORY"
fi
if git merge-base --is-ancestor "$master_sha" origin/develop; then
echo "develop already contains master $master_sha."
exit 0
fi
# Build the disposable branch from the exact merge that CI and develop
# will consume. Cargo.lock can merge cleanly as text while still
# referring to master's released Veryl crates, so re-resolve the HEAD
# dependency graph before publishing a conflict-free merge.
git config user.name "celox-release-bot"
git config user.email "celox-release-bot@users.noreply.github.com"
# Snapshot the remote head before building a replacement. A raw
# master fallback or a synchronization already merged into develop is
# disposable. Any other head contains unresolved work, including a
# human conflict resolution, and must never be force-pushed away.
sync_ref="refs/heads/$SYNC_BRANCH"
remote_sync_sha="$(git ls-remote origin "$sync_ref" | cut -f1)"
if [ -n "$remote_sync_sha" ]; then
git fetch --no-tags origin "$sync_ref"
scripts/check-sync-branch-head.sh \
"$remote_sync_sha" \
"$master_sha" \
"$(git rev-parse origin/develop)"
fi
git switch --force-create "$SYNC_BRANCH" origin/develop
set +e
git merge --no-commit --no-ff "$master_sha"
merge_status="$?"
set -e
if [ "$merge_status" -eq 0 ]; then
cargo update -p veryl-analyzer
cargo metadata --locked --format-version 1 --no-deps >/dev/null
git add Cargo.lock
git commit \
-m "chore(develop): sync master" \
-m "Celox-Sync-Automation: true"
sync_sha="$(git rev-parse HEAD)"
else
# Keep non-dependency conflicts visible and actionable on the PR.
git merge --abort
git switch --force-create "$SYNC_BRANCH" "$master_sha"
sync_sha="$master_sha"
fi
# Also reject a concurrent update made after the snapshot above.
git push origin \
--force-with-lease="$sync_ref:$remote_sync_sha" \
"$sync_sha:$sync_ref"
sync_pr="$(
gh pr list \
--repo "$GITHUB_REPOSITORY" \
--state open \
--base develop \
--head "$SYNC_BRANCH" \
--json number,isCrossRepository \
--jq '[.[] | select(.isCrossRepository == false)][0].number // empty'
)"
if [ -z "$sync_pr" ]; then
sync_pr="$(
gh pr create \
--repo "$GITHUB_REPOSITORY" \
--base develop \
--head "$SYNC_BRANCH" \
--title "chore(develop): sync master" \
--body $'Bring stable-trunk changes into the Veryl HEAD compatibility lane.\n\nThis PR is managed automatically through a dedicated synchronization branch so the develop merge queue never holds `master` itself as a pull request head. A conflict is actionable and must be resolved without replacing the Veryl HEAD dependency on `develop`.'
)"
fi
gh pr edit "$sync_pr" \
--repo "$GITHUB_REPOSITORY" \
--add-label merge-ready