Replaces build workflow with release process #14
Workflow file for this run
This file contains hidden or 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: Release CanonWebAPI | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '9.0.x' | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| $tagName = "${{ github.ref }}" -replace 'refs/tags/v', '' | |
| echo "VERSION=$tagName" >> $env:GITHUB_OUTPUT | |
| echo "Tag version: $tagName" | |
| shell: powershell | |
| - name: Check and update project version | |
| id: version_check | |
| run: | | |
| $tagVersion = "${{ steps.version.outputs.VERSION }}" | |
| # Read current version from project file | |
| $projectFile = "Canon.API/Canon.API.csproj" | |
| $projectContent = Get-Content $projectFile | |
| $currentVersion = "" | |
| foreach ($line in $projectContent) { | |
| if ($line -match '<Version>(.*)</Version>') { | |
| $currentVersion = $matches[1] | |
| break | |
| } | |
| } | |
| echo "Current project version: $currentVersion" | |
| echo "Tag version: $tagVersion" | |
| if ($currentVersion -ne $tagVersion) { | |
| echo "VERSION_MISMATCH=true" >> $env:GITHUB_OUTPUT | |
| echo "Versions do not match - updating project files" | |
| # Update Canon.API project file | |
| $projectContent -replace '<Version>.*</Version>', "<Version>$tagVersion</Version>" -replace '<AssemblyVersion>.*</AssemblyVersion>', "<AssemblyVersion>$tagVersion</AssemblyVersion>" -replace '<FileVersion>.*</FileVersion>', "<FileVersion>$tagVersion</FileVersion>" | Set-Content $projectFile | |
| # Update Canon.Core project file if it has version info | |
| $coreProjectFile = "Canon.Core/Canon.Core.csproj" | |
| if (Test-Path $coreProjectFile) { | |
| $coreContent = Get-Content $coreProjectFile | |
| if ($coreContent -match '<Version>') { | |
| $coreContent -replace '<Version>.*</Version>', "<Version>$tagVersion</Version>" -replace '<AssemblyVersion>.*</AssemblyVersion>', "<AssemblyVersion>$tagVersion</AssemblyVersion>" -replace '<FileVersion>.*</FileVersion>', "<FileVersion>$tagVersion</FileVersion>" | Set-Content $coreProjectFile | |
| } | |
| } | |
| } else { | |
| echo "VERSION_MISMATCH=false" >> $env:GITHUB_OUTPUT | |
| echo "Versions match - no update needed" | |
| } | |
| shell: powershell | |
| - name: Commit version updates | |
| if: steps.version_check.outputs.VERSION_MISMATCH == 'true' | |
| run: | | |
| git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add "*.csproj" | |
| git commit -m "Update project versions to ${{ steps.version.outputs.VERSION }}" | |
| git push origin main | |
| shell: powershell | |
| - name: Restore dependencies | |
| run: dotnet restore CanonSDK.sln | |
| - name: Build solution | |
| run: dotnet build CanonSDK.sln --configuration Release --no-restore | |
| - name: Publish Canon.API | |
| run: dotnet publish Canon.API --configuration Release --output ./publish --no-build | |
| - name: Create release package | |
| run: | | |
| $version = "${{ steps.version.outputs.VERSION }}" | |
| Compress-Archive -Path "./publish/*" -DestinationPath "./CanonWebAPI-v$version.zip" | |
| shell: powershell | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: ./CanonWebAPI-v${{ steps.version.outputs.VERSION }}.zip | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Update AutoUpdater XML | |
| run: | | |
| $version = "${{ steps.version.outputs.VERSION }}" | |
| $releaseUrl = "https://github.com/${{ github.repository }}/releases/download/v$version/CanonWebAPI-v$version.zip" | |
| # Create docs folder if it doesn't exist | |
| if (!(Test-Path "docs")) { | |
| New-Item -ItemType Directory -Path "docs" | |
| } | |
| # Create AutoUpdater XML content | |
| $xmlContent = @" | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <item> | |
| <version>$version</version> | |
| <url>$releaseUrl</url> | |
| <changelog>https://github.com/${{ github.repository }}/releases/tag/v$version</changelog> | |
| <mandatory>true</mandatory> | |
| </item> | |
| "@ | |
| $xmlContent | Out-File -FilePath "docs/autoupdate.xml" -Encoding UTF8 | |
| shell: powershell | |
| - name: Commit AutoUpdater XML | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add docs/autoupdate.xml | |
| if (!(git diff --staged --quiet)) { | |
| git commit -m "Update AutoUpdater XML for version ${{ steps.version.outputs.VERSION }}" | |
| git push origin main | |
| } | |
| shell: powershell |