Skip to content

Change release filename. #18

Change release filename.

Change release filename. #18

Workflow file for this run

name: Release CanonWebAPI
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
release:
runs-on: windows-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v5
with:
ref: main
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 "action@github.com"
git config --local user.name "GitHub Action"
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 as standalone executable
run: dotnet publish Canon.API/Canon.API.csproj --configuration Release --runtime win-x64 --self-contained true -p:PublishSingleFile=true --output ./publish
- name: Create release package
run: |
Compress-Archive -Path "./publish/*" -DestinationPath "./CanonWebAPI.zip"
shell: powershell
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: ./CanonWebAPI.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.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