|
| 1 | +name: Update VFS for Git |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [released, prereleased] |
| 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 | + # Pre-releases: trigger a VFS for Git build with the new Git version |
| 38 | + - name: Trigger VFS for Git build |
| 39 | + if: github.event.release.prerelease |
| 40 | + env: |
| 41 | + # GH_TOKEN overrides the GITHUB_TOKEN provided by the actions runner, |
| 42 | + # so that `gh` commands use the VFS for Git repo token from Key Vault. |
| 43 | + GH_TOKEN: ${{ steps.token.outputs.result }} |
| 44 | + run: | |
| 45 | + TAG="${{ steps.tag.outputs.name }}" |
| 46 | + REPO="microsoft/VFSForGit" |
| 47 | + WORKFLOW="build.yaml" |
| 48 | + RUN_NAME="VFS for Git (microsoft/git: $TAG)" |
| 49 | +
|
| 50 | + gh workflow run "$WORKFLOW" \ |
| 51 | + --repo "$REPO" \ |
| 52 | + --field git_version="$TAG" \ |
| 53 | + --field run_name="$RUN_NAME" |
| 54 | +
|
| 55 | + # Poll until the dispatched run appears by its display title (timeout 30s) |
| 56 | + RUN_URL="" |
| 57 | + for i in $(seq 1 6); do |
| 58 | + sleep 5 |
| 59 | + RUN_URL=$(gh run list \ |
| 60 | + --workflow="$WORKFLOW" \ |
| 61 | + --repo "$REPO" \ |
| 62 | + --json url,displayTitle \ |
| 63 | + --jq "[.[] | select(.displayTitle == \"$RUN_NAME\")] | .[0].url // empty") |
| 64 | + if [ -n "$RUN_URL" ]; then |
| 65 | + break |
| 66 | + fi |
| 67 | + done |
| 68 | +
|
| 69 | + if [ -n "$RUN_URL" ]; then |
| 70 | + echo "::notice::Triggered VFS for Git build with Git version $TAG: $RUN_URL" |
| 71 | + else |
| 72 | + echo "::warning::Triggered VFS for Git build with Git version $TAG but could not determine run URL" |
| 73 | + fi |
| 74 | +
|
| 75 | + # Full releases: create a PR to bump the default GIT_VERSION |
| 76 | + - name: Create VFS for Git version bump PR |
| 77 | + if: ${{ !github.event.release.prerelease }} |
| 78 | + env: |
| 79 | + # GH_TOKEN overrides the GITHUB_TOKEN provided by the actions runner, |
| 80 | + # so that `gh` commands use the VFS for Git repo token from Key Vault. |
| 81 | + GH_TOKEN: ${{ steps.token.outputs.result }} |
| 82 | + run: | |
| 83 | + # Configure gh as the git credential helper and force HTTPS protocol |
| 84 | + # so that git clone/push authenticate using GH_TOKEN. |
| 85 | + gh auth setup-git |
| 86 | + gh config set git_protocol https |
| 87 | +
|
| 88 | + TAG="${{ steps.tag.outputs.name }}" |
| 89 | + REPO="microsoft/VFSForGit" |
| 90 | + BRANCH="automation/gitrelease-$TAG" |
| 91 | + FILE=".github/workflows/build.yaml" |
| 92 | +
|
| 93 | + # Clone VFS for Git repo |
| 94 | + gh repo clone "$REPO" vfsforgit -- --depth=1 |
| 95 | + cd vfsforgit |
| 96 | +
|
| 97 | + # Create new branch |
| 98 | + git checkout -b "$BRANCH" |
| 99 | +
|
| 100 | + # Update the GIT_VERSION default in build.yaml |
| 101 | + sed -i "/GIT_VERSION/s/|| '[^']*' }}/|| '$TAG' }}/" "$FILE" |
| 102 | +
|
| 103 | + # Verify the change was made |
| 104 | + if ! git diff --quiet "$FILE"; then |
| 105 | + git config user.name "github-actions[bot]" |
| 106 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 107 | +
|
| 108 | + git add "$FILE" |
| 109 | + git commit -m "Update default Microsoft Git version to $TAG" |
| 110 | +
|
| 111 | + # Push the new branch |
| 112 | + git push origin "$BRANCH" |
| 113 | +
|
| 114 | + # Create the PR |
| 115 | + WORKFLOW_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 116 | + RELEASE_URL="https://github.com/microsoft/git/releases/tag/$TAG" |
| 117 | + PR_TITLE="Update default Microsoft Git version to $TAG" |
| 118 | + PR_BODY=$(cat <<EOF |
| 119 | + This PR was automatically created by the [microsoft/git release workflow]($WORKFLOW_URL) |
| 120 | + to update the default Microsoft Git version to [\`$TAG\`]($RELEASE_URL). |
| 121 | + EOF |
| 122 | + ) |
| 123 | +
|
| 124 | + PR_URL=$(gh pr create \ |
| 125 | + --repo "$REPO" \ |
| 126 | + --head "$BRANCH" \ |
| 127 | + --title "$PR_TITLE" \ |
| 128 | + --body "$PR_BODY") |
| 129 | + echo "::notice::Created VFS for Git PR: $PR_URL" |
| 130 | + else |
| 131 | + echo "::warning::No changes detected in $FILE; GIT_VERSION may already be set to $TAG" |
| 132 | + fi |
0 commit comments