Skip to content

Commit

Permalink
Update bump.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
JanProvaznik authored Feb 20, 2025
1 parent 8f335d2 commit f43de0c
Showing 1 changed file with 46 additions and 16 deletions.
62 changes: 46 additions & 16 deletions .github/workflows/bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,68 @@ 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
run: |
$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
}

0 comments on commit f43de0c

Please # to comment.