diff --git a/.github/workflows/bump.yml b/.github/workflows/bump.yml index d466e1632a8..c39258597c2 100644 --- a/.github/workflows/bump.yml +++ b/.github/workflows/bump.yml @@ -13,11 +13,28 @@ jobs: pull-requests: write steps: - - name: Checkout PR branch (shallow) - uses: actions/checkout@v3 + - name: Get PR Details + id: pr_details + uses: actions/github-script@v6 with: - ref: ${{ github.event.issue.pull_request.head.ref }} - fetch-depth: 1 # Fastest way to get the branch + script: | + const pr = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.name, + pull_number: context.issue.number + }); + return { + head_ref: pr.data.head.ref, + head_sha: pr.data.head.sha, + repo_url: pr.data.head.repo.clone_url + } + + - name: Checkout PR branch + uses: actions/checkout@v4 + with: + ref: ${{ fromJSON(steps.pr_details.outputs.result).head_ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + token: ${{ secrets.GITHUB_TOKEN }} - name: Update Version shell: pwsh @@ -25,26 +42,39 @@ jobs: $filePath = "eng/Versions.props" [xml]$xml = Get-Content $filePath $versionPrefix = $xml.SelectSingleNode("//VersionPrefix") - + $oldVersion = $versionPrefix.InnerText $parts = $oldVersion -split '\.' - $newVersion = "$($parts[0]).$($parts[1]).$($parts[2] + 1)" - + + # Convert the patch version to integer, increment it, and convert back to string + $patchVersion = [int]$parts[2] + $patchVersion++ + $parts[2] = $patchVersion.ToString() + + $newVersion = $parts -join '.' + $versionPrefix.InnerText = $newVersion $xml.Save($filePath) + + # Set output variables + "old_version=$oldVersion" >> $env:GITHUB_ENV + "new_version=$newVersion" >> $env:GITHUB_ENV - echo "old_version=$oldVersion" >> $env:GITHUB_ENV - echo "new_version=$newVersion" >> $env:GITHUB_ENV - - - name: Commit and Push Changes to PR branch + - name: Commit and Push Changes run: | - git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - + git add eng/Versions.props git commit -m "bump: Update patch version from ${{ env.old_version }} to ${{ env.new_version }} Triggered by: @${{ github.event.comment.user.login }} - Timestamp (UTC): $(date -u +"%Y-%m-%d %H:%M:%S")" - - git push origin ${{ github.event.issue.pull_request.head.ref }} + Timestamp (UTC): $(date -u +'%Y-%m-%d %H:%M:%S')" + + # Push with error handling + git push origin HEAD || { + echo "Push failed. Fetching latest changes and retrying..." + git fetch + git rebase origin/${{ fromJSON(steps.pr_details.outputs.result).head_ref }} + git push origin HEAD + }