Skip to content

Update build.yml

Update build.yml #44

Workflow file for this run

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 "branch_name=update-package-version-$prevision" >> $GITHUB_ENV
echo "new_package_version=$new_package_version" >> $GITHUB_ENV
- 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: Create Pull Request
env:
BRANCH_NAME: ${{ steps.update_version.outputs.branch_name }}
run: |
gh pr create \
--title "Update revision number" \
--body "Automated update of PackageVersion" \
--base main \
--head "${{ env.branch_name }}"
- name: Merge Pull Request
run: |
pr_url=$(gh pr view --json url -q .url)
echo "Pull Request URL: $pr_url"
# Attempt auto-merge
if gh pr merge --auto --merge --delete-branch; then
echo "Auto-merge completed successfully."
else
echo "Auto-merge failed. Attempting manual merge."
gh pr merge --merge --delete-branch
fi