-
-
Notifications
You must be signed in to change notification settings - Fork 892
185 lines (147 loc) · 7.89 KB
/
Copy pathupdate_vcpkg_baseline.yml
File metadata and controls
185 lines (147 loc) · 7.89 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
---
name: Update vcpkg Baseline
on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch:
concurrency:
group: update-vcpkg-baseline
cancel-in-progress: false
jobs:
update-baseline-on-main:
runs-on: ubuntu-latest
permissions:
actions: write
contents: write
pull-requests: write
if: github.ref == 'refs/heads/main'
outputs:
tag: ${{ steps.vcpkg.outputs.tag }}
baseline: ${{ steps.vcpkg.outputs.baseline }}
needs_update: ${{ steps.vcpkg.outputs.needs_update }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: main
- name: Get latest vcpkg release
id: vcpkg
run: |
LATEST_TAG=$(curl -s https://api.github.com/repos/microsoft/vcpkg/releases/latest | jq -r '.tag_name')
echo "Latest tag: $LATEST_TAG"
LATEST_BASELINE=$(git ls-remote https://github.com/microsoft/vcpkg.git "refs/tags/${LATEST_TAG}^{}" | awk '{print $1}')
if [ -z "$LATEST_BASELINE" ]; then
LATEST_BASELINE=$(git ls-remote https://github.com/microsoft/vcpkg.git "refs/tags/${LATEST_TAG}" | awk '{print $1}')
fi
echo "Baseline SHA: $LATEST_BASELINE"
if [ -z "$LATEST_BASELINE" ] || [ "$LATEST_BASELINE" == "null" ]; then
echo "Error: Invalid baseline detected"
exit 1
fi
CURRENT_BASELINE=$(jq -r '."builtin-baseline"' vcpkg.json)
CURRENT_REGISTRY_BASELINE=$(jq -r '."default-registry".baseline' vcpkg-configuration.json)
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "baseline=$LATEST_BASELINE" >> $GITHUB_OUTPUT
echo "current_builtin=$CURRENT_BASELINE" >> $GITHUB_OUTPUT
echo "current_registry=$CURRENT_REGISTRY_BASELINE" >> $GITHUB_OUTPUT
if [ "$LATEST_BASELINE" != "$CURRENT_BASELINE" ] || [ "$LATEST_BASELINE" != "$CURRENT_REGISTRY_BASELINE" ]; then
echo "needs_update=true" >> $GITHUB_OUTPUT
else
echo "needs_update=false" >> $GITHUB_OUTPUT
fi
- name: Create or update single baseline PR
if: steps.vcpkg.outputs.needs_update == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ steps.vcpkg.outputs.tag }}
PREVIOUS_BUILTIN: ${{ steps.vcpkg.outputs.current_builtin }}
PREVIOUS_REGISTRY: ${{ steps.vcpkg.outputs.current_registry }}
NEW_BASELINE: ${{ steps.vcpkg.outputs.baseline }}
run: |
set -euo pipefail
BRANCH_NAME="chore/update-vcpkg-baseline"
trigger_ci() {
echo "Dispatching CI workflow for ${BRANCH_NAME}"
gh workflow run ci.yml --ref "${BRANCH_NAME}"
}
queue_auto_merge() {
local pr_number="$1"
local merge_subject="chore(vcpkg): update baseline to ${RELEASE_TAG}"
local merge_body="vcpkg baseline: ${NEW_BASELINE}"
if [[ ! "${pr_number}" =~ ^[0-9]+$ ]]; then
echo "::error::Invalid baseline pull request number: ${pr_number}"
return 1
fi
if gh pr merge "${pr_number}" --auto --squash \
--subject "${merge_subject}" \
--body "${merge_body}"; then
echo "Queued native GitHub auto-merge for PR #${pr_number}"
else
echo "::warning::Could not queue auto-merge for PR #${pr_number}. Repository auto-merge may be disabled or branch protection may require a review."
fi
}
sync_update_branch() {
git fetch --prune origin main
if git ls-remote --exit-code --heads origin "${BRANCH_NAME}" >/dev/null 2>&1; then
git fetch origin "+refs/heads/${BRANCH_NAME}:refs/remotes/origin/${BRANCH_NAME}"
git checkout -B "${BRANCH_NAME}" "origin/${BRANCH_NAME}"
git rebase origin/main
git push --force-with-lease origin "${BRANCH_NAME}"
else
git checkout -B "${BRANCH_NAME}" origin/main
fi
}
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
EXISTING_PR=$(gh pr list --state open --base main --head "${GITHUB_REPOSITORY_OWNER}:${BRANCH_NAME}" --limit 1 --json number --jq '.[0].number // empty')
if [ -n "$EXISTING_PR" ]; then
echo "Found existing baseline PR #${EXISTING_PR}, updating it"
sync_update_branch
CURRENT_IN_BRANCH=$(jq -r '."builtin-baseline"' vcpkg.json)
CURRENT_REGISTRY_IN_BRANCH=$(jq -r '."default-registry".baseline' vcpkg-configuration.json)
if [ "$CURRENT_IN_BRANCH" == "${NEW_BASELINE}" ] && [ "$CURRENT_REGISTRY_IN_BRANCH" == "${NEW_BASELINE}" ]; then
echo "PR #${EXISTING_PR} already has baseline ${NEW_BASELINE}"
trigger_ci
queue_auto_merge "${EXISTING_PR}"
exit 0
fi
echo "Updating PR #${EXISTING_PR} from builtin ${CURRENT_IN_BRANCH} and registry ${CURRENT_REGISTRY_IN_BRANCH} to ${NEW_BASELINE}"
jq --arg baseline "${NEW_BASELINE}" '."builtin-baseline" = $baseline' vcpkg.json > vcpkg.json.tmp
mv vcpkg.json.tmp vcpkg.json
jq --arg baseline "${NEW_BASELINE}" '."default-registry".baseline = $baseline' vcpkg-configuration.json > vcpkg-configuration.json.tmp
mv vcpkg-configuration.json.tmp vcpkg-configuration.json
git add vcpkg.json vcpkg-configuration.json
if ! git diff --cached --quiet; then
git commit -m "chore: update vcpkg baseline to ${RELEASE_TAG}"
git push --force-with-lease origin "${BRANCH_NAME}"
fi
gh pr edit ${EXISTING_PR} --title "chore: Update vcpkg baseline to ${RELEASE_TAG}"
printf -v COMMENT_BODY '🔄 Updated to vcpkg **%s**\n\n**Previous builtin baseline:** `%s`\n**Previous registry baseline:** `%s`\n**New baseline:** `%s`\n\n**Release notes:** https://github.com/microsoft/vcpkg/releases/tag/%s' \
"${RELEASE_TAG}" "${CURRENT_IN_BRANCH}" "${CURRENT_REGISTRY_IN_BRANCH}" "${NEW_BASELINE}" "${RELEASE_TAG}"
gh pr comment ${EXISTING_PR} --body "${COMMENT_BODY}"
trigger_ci
queue_auto_merge "${EXISTING_PR}"
echo "Successfully updated PR #${EXISTING_PR}"
else
echo "No existing baseline PR found, creating new one"
sync_update_branch
jq --arg baseline "${NEW_BASELINE}" '."builtin-baseline" = $baseline' vcpkg.json > vcpkg.json.tmp
mv vcpkg.json.tmp vcpkg.json
jq --arg baseline "${NEW_BASELINE}" '."default-registry".baseline = $baseline' vcpkg-configuration.json > vcpkg-configuration.json.tmp
mv vcpkg-configuration.json.tmp vcpkg-configuration.json
git add vcpkg.json vcpkg-configuration.json
git commit -m "chore: update vcpkg baseline to ${RELEASE_TAG}"
git push --force-with-lease origin "${BRANCH_NAME}"
printf -v PR_BODY '## vcpkg Baseline Update\n\nThis PR updates the vcpkg baseline to the latest release.\n\n**Release:** `%s`\n**Previous builtin baseline:** `%s`\n**Previous registry baseline:** `%s`\n**New baseline:** `%s`\n\n**Release notes:** https://github.com/microsoft/vcpkg/releases/tag/%s\n\n---\n🤖 This PR is automatically updated when new vcpkg releases are published' \
"${RELEASE_TAG}" "${PREVIOUS_BUILTIN}" "${PREVIOUS_REGISTRY}" "${NEW_BASELINE}" "${RELEASE_TAG}"
PR_URL=$(gh pr create \
--title "chore: Update vcpkg baseline to ${RELEASE_TAG}" \
--body "${PR_BODY}" \
--base main \
--head ${BRANCH_NAME})
trigger_ci
NEW_PR="${PR_URL##*/}"
queue_auto_merge "${NEW_PR}"
echo "Created new baseline PR"
fi