Update build.yml #33
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: prs-build | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: windows-latest | |
env: | |
Solution_Name: PRS.sln | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Install .NET 8.0 | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 8.0.x | |
- name: Restore and build the application | |
run: | | |
dotnet restore | |
dotnet build -c Release --no-restore | |
- name: Increase revision number | |
id: update_version | |
shell: pwsh | |
run: | | |
$xml_file = "./src/prs.csproj" | |
$package_version = (Select-String -Path $xml_file -Pattern '<PackageVersion>(.*?)<\/PackageVersion>' -AllMatches).Matches.Groups[1].Value | |
Write-Host "Current PackageVersion: $package_version" | |
$version_parts = $package_version -split '\.' | |
$pmajor, $pminor, $pbuild, $prevision = $version_parts | |
$prevision = [int]$prevision + 1 | |
$new_package_version = "$pmajor.$pminor.$pbuild.$prevision" | |
Write-Host "New PackageVersion: $new_package_version" | |
(Get-Content $xml_file) -replace '<PackageVersion>.*<\/PackageVersion>', "<PackageVersion>$new_package_version</PackageVersion>" | Set-Content $xml_file | |
echo "::set-output name=branch_name::update-package-version-$prevision" | |
echo "::set-output name=new_package_version::$new_package_version" | |
- name: Create Temporary Branch | |
env: | |
BRANCH_NAME: ${{ steps.update_version.outputs.branch_name }} | |
NEW_PACKAGE_VERSION: ${{ steps.update_version.outputs.new_package_version }} | |
run: | | |
git config user.name "prs" | |
git config user.email "prs@example.com" | |
git checkout -b "${{ env.BRANCH_NAME }}" | |
git add . | |
git commit -m "Update revision number to ${{ env.NEW_PACKAGE_VERSION }}" | |
git push origin "${{ env.BRANCH_NAME }}" | |
- name: Merge Temporary Branch | |
env: | |
BRANCH_NAME: ${{ steps.update_version.outputs.branch_name }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh pr create --title "Update revision number" --body "Automated update of PackageVersion" --base main --head "${{ env.BRANCH_NAME }}" | |
gh pr merge --merge --auto --delete-branch |