Skip to content

Update vcpkg Baseline #305

Update vcpkg Baseline

Update vcpkg Baseline #305

---
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