Skip to content

Commit 3683226

Browse files
committed
workflow: add release-vfsforgit to automate VFS for Git updates
When a new microsoft/git release is published, VFS for Git needs to pick up the new Git version. Today this is a manual process. This workflow automates it by reacting to GitHub release events. On a full releases: creates a PR in microsoft/VFSForGit to bump the default GIT_VERSION in the build workflow, so future CI runs and manual dispatches use the latest stable Git version. Authentication uses the existing Azure Key Vault + OIDC pattern (matching release-homebrew and release-winget) to retrieve a token with write access to the VFS for Git repository. In a separate effort we'll add another workflow that triggers on push to vfs-* branches to trigger a run of VFS for Git Functional Tests (from the master branch). Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
1 parent fb711f2 commit 3683226

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Update VFS for Git
2+
3+
on:
4+
release:
5+
types: [released]
6+
7+
permissions:
8+
id-token: write # required for Azure login via OIDC
9+
10+
jobs:
11+
update:
12+
runs-on: ubuntu-latest
13+
environment: release
14+
steps:
15+
- name: Compute tag name
16+
id: tag
17+
run: echo "name=${{ github.event.release.tag_name }}" >>$GITHUB_OUTPUT
18+
19+
- name: Log into Azure
20+
uses: azure/login@v2
21+
with:
22+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
23+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
24+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
25+
26+
- name: Retrieve token
27+
id: token
28+
run: |
29+
az keyvault secret show \
30+
--name ${{ secrets.VFSFORGIT_TOKEN_SECRET_NAME }} \
31+
--vault-name ${{ secrets.AZURE_VAULT }} \
32+
--query "value" -o tsv >token &&
33+
sed s/^/::add-mask::/ <token &&
34+
sed s/^/result=/ <token >>$GITHUB_OUTPUT &&
35+
rm token
36+
37+
# Create a PR to bump the default GIT_VERSION
38+
- name: Create VFS for Git version bump PR
39+
env:
40+
# GH_TOKEN overrides the GITHUB_TOKEN provided by the actions runner,
41+
# so that `gh` commands use the VFS for Git repo token from Key Vault.
42+
GH_TOKEN: ${{ steps.token.outputs.result }}
43+
run: |
44+
# Configure gh as the git credential helper and force HTTPS protocol
45+
# so that git clone/push authenticate using GH_TOKEN.
46+
gh auth setup-git
47+
gh config set git_protocol https
48+
49+
TAG="${{ steps.tag.outputs.name }}"
50+
REPO="microsoft/VFSForGit"
51+
BRANCH="automation/gitrelease-$TAG"
52+
FILE=".github/workflows/build.yaml"
53+
54+
# Clone VFS for Git repo
55+
gh repo clone "$REPO" vfsforgit -- --depth=1
56+
cd vfsforgit
57+
58+
# Create new branch
59+
git checkout -b "$BRANCH"
60+
61+
# Update the GIT_VERSION default in build.yaml
62+
sed -i "/GIT_VERSION/s/|| '[^']*' }}/|| '$TAG' }}/" "$FILE"
63+
64+
# Verify the change was made
65+
if ! git diff --quiet "$FILE"; then
66+
git config user.name "github-actions[bot]"
67+
git config user.email "github-actions[bot]@users.noreply.github.com"
68+
69+
git add "$FILE"
70+
git commit -m "Update default Microsoft Git version to $TAG"
71+
72+
# Push the new branch
73+
git push origin "$BRANCH"
74+
75+
# Create the PR
76+
WORKFLOW_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
77+
RELEASE_URL="https://github.com/microsoft/git/releases/tag/$TAG"
78+
PR_TITLE="Update default Microsoft Git version to $TAG"
79+
PR_BODY=$(cat <<EOF
80+
This PR was automatically created by the [microsoft/git release workflow]($WORKFLOW_URL)
81+
to update the default Microsoft Git version to [\`$TAG\`]($RELEASE_URL).
82+
EOF
83+
)
84+
85+
PR_URL=$(gh pr create \
86+
--repo "$REPO" \
87+
--head "$BRANCH" \
88+
--title "$PR_TITLE" \
89+
--body "$PR_BODY")
90+
echo "::notice::Created VFS for Git PR: $PR_URL"
91+
else
92+
echo "::warning::No changes detected in $FILE; GIT_VERSION may already be set to $TAG"
93+
fi

0 commit comments

Comments
 (0)