Skip to content

Commit e14354c

Browse files
committed
Replaces build workflow with release process
1 parent a2e696f commit e14354c

2 files changed

Lines changed: 58 additions & 64 deletions

File tree

.github/workflows/build.yml

Lines changed: 53 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,86 @@
1-
name: Build Canon.API
1+
name: Release CanonWebAPI
22

33
on:
44
push:
5-
branches: [ main, develop ]
65
tags:
76
- 'v*'
8-
pull_request:
9-
branches: [ main ]
107

118
permissions:
129
contents: write
13-
pages: write
14-
id-token: write
1510

1611
jobs:
17-
build:
12+
release:
1813
runs-on: windows-latest
1914

2015
steps:
2116
- name: Checkout code
22-
uses: actions/checkout@v4
17+
uses: actions/checkout@v5
18+
with:
19+
fetch-depth: 0
20+
token: ${{ secrets.GITHUB_TOKEN }}
2321

2422
- name: Setup .NET
2523
uses: actions/setup-dotnet@v4
2624
with:
2725
dotnet-version: '9.0.x'
2826

2927
- name: Extract version from tag
30-
if: startsWith(github.ref, 'refs/tags/v')
3128
id: version
3229
run: |
3330
$tagName = "${{ github.ref }}" -replace 'refs/tags/v', ''
3431
echo "VERSION=$tagName" >> $env:GITHUB_OUTPUT
3532
echo "Tag version: $tagName"
3633
shell: powershell
3734

38-
- name: Update Assembly Version
39-
if: startsWith(github.ref, 'refs/tags/v')
35+
- name: Check and update project version
36+
id: version_check
4037
run: |
41-
$version = "${{ steps.version.outputs.VERSION }}"
38+
$tagVersion = "${{ steps.version.outputs.VERSION }}"
4239
43-
# Update Canon.API AssemblyInfo
44-
$apiAssemblyInfo = "Canon.API/Properties/AssemblyInfo.cs"
45-
if (Test-Path $apiAssemblyInfo) {
46-
(Get-Content $apiAssemblyInfo) -replace 'AssemblyVersion\(".*"\)', "AssemblyVersion(""$version"")" -replace 'AssemblyFileVersion\(".*"\)', "AssemblyFileVersion(""$version"")" | Set-Content $apiAssemblyInfo
47-
}
40+
# Read current version from project file
41+
$projectFile = "Canon.API/Canon.API.csproj"
42+
$projectContent = Get-Content $projectFile
43+
$currentVersion = ""
4844
49-
# Update Canon.Core AssemblyInfo
50-
$coreAssemblyInfo = "Canon.Core/Properties/AssemblyInfo.cs"
51-
if (Test-Path $coreAssemblyInfo) {
52-
(Get-Content $coreAssemblyInfo) -replace 'AssemblyVersion\(".*"\)', "AssemblyVersion(""$version"")" -replace 'AssemblyFileVersion\(".*"\)', "AssemblyFileVersion(""$version"")" | Set-Content $coreAssemblyInfo
45+
foreach ($line in $projectContent) {
46+
if ($line -match '<Version>(.*)</Version>') {
47+
$currentVersion = $matches[1]
48+
break
49+
}
5350
}
5451
55-
# Update project files if they contain version
56-
Get-ChildItem -Recurse -Name "*.csproj" | ForEach-Object {
57-
$content = Get-Content $_
58-
if ($content -match "<Version>") {
59-
$content -replace "<Version>.*</Version>", "<Version>$version</Version>" | Set-Content $_
52+
echo "Current project version: $currentVersion"
53+
echo "Tag version: $tagVersion"
54+
55+
if ($currentVersion -ne $tagVersion) {
56+
echo "VERSION_MISMATCH=true" >> $env:GITHUB_OUTPUT
57+
echo "Versions do not match - updating project files"
58+
59+
# Update Canon.API project file
60+
$projectContent -replace '<Version>.*</Version>', "<Version>$tagVersion</Version>" -replace '<AssemblyVersion>.*</AssemblyVersion>', "<AssemblyVersion>$tagVersion</AssemblyVersion>" -replace '<FileVersion>.*</FileVersion>', "<FileVersion>$tagVersion</FileVersion>" | Set-Content $projectFile
61+
62+
# Update Canon.Core project file if it has version info
63+
$coreProjectFile = "Canon.Core/Canon.Core.csproj"
64+
if (Test-Path $coreProjectFile) {
65+
$coreContent = Get-Content $coreProjectFile
66+
if ($coreContent -match '<Version>') {
67+
$coreContent -replace '<Version>.*</Version>', "<Version>$tagVersion</Version>" -replace '<AssemblyVersion>.*</AssemblyVersion>', "<AssemblyVersion>$tagVersion</AssemblyVersion>" -replace '<FileVersion>.*</FileVersion>', "<FileVersion>$tagVersion</FileVersion>" | Set-Content $coreProjectFile
68+
}
6069
}
70+
} else {
71+
echo "VERSION_MISMATCH=false" >> $env:GITHUB_OUTPUT
72+
echo "Versions match - no update needed"
6173
}
74+
shell: powershell
6275

63-
# Commit assembly version changes
64-
git config --local user.email "action@github.com"
65-
git config --local user.name "GitHub Action"
66-
git fetch origin main
67-
git checkout -B main origin/main
68-
git add -A
69-
if (!(git diff --staged --quiet)) {
70-
git commit -m "Update assembly versions to $version"
71-
git push origin main
72-
}
76+
- name: Commit version updates
77+
if: steps.version_check.outputs.VERSION_MISMATCH == 'true'
78+
run: |
79+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
80+
git config --local user.name "github-actions[bot]"
81+
git add "*.csproj"
82+
git commit -m "Update project versions to ${{ steps.version.outputs.VERSION }}"
83+
git push origin main
7384
shell: powershell
7485

7586
- name: Restore dependencies
@@ -78,41 +89,24 @@ jobs:
7889
- name: Build solution
7990
run: dotnet build CanonSDK.sln --configuration Release --no-restore
8091

81-
- name: Run tests (if any)
82-
run: dotnet test --configuration Release --no-build --verbosity normal
83-
continue-on-error: true
84-
8592
- name: Publish Canon.API
8693
run: dotnet publish Canon.API --configuration Release --output ./publish --no-build
8794

88-
- name: Upload build artifacts
89-
uses: actions/upload-artifact@v4
90-
with:
91-
name: canon-api-build
92-
path: ./publish/
93-
retention-days: 30
94-
95-
- name: Create ZIP for release
96-
if: startsWith(github.ref, 'refs/tags/v')
95+
- name: Create release package
9796
run: |
9897
$version = "${{ steps.version.outputs.VERSION }}"
9998
Compress-Archive -Path "./publish/*" -DestinationPath "./CanonWebAPI-v$version.zip"
10099
shell: powershell
101100

102-
- name: Create Release
103-
if: startsWith(github.ref, 'refs/tags/v')
101+
- name: Create GitHub Release
104102
uses: softprops/action-gh-release@v2
105103
with:
106-
files: |
107-
./CanonWebAPI-v${{ steps.version.outputs.VERSION }}.zip
108-
draft: false
109-
prerelease: false
104+
files: ./CanonWebAPI-v${{ steps.version.outputs.VERSION }}.zip
110105
generate_release_notes: true
111106
env:
112107
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113108

114-
- name: Update GitHub Pages XML
115-
if: startsWith(github.ref, 'refs/tags/v')
109+
- name: Update AutoUpdater XML
116110
run: |
117111
$version = "${{ steps.version.outputs.VERSION }}"
118112
$releaseUrl = "https://github.com/${{ github.repository }}/releases/download/v$version/CanonWebAPI-v$version.zip"
@@ -136,17 +130,12 @@ jobs:
136130
$xmlContent | Out-File -FilePath "docs/autoupdate.xml" -Encoding UTF8
137131
shell: powershell
138132

139-
- name: Commit and push XML changes
140-
if: startsWith(github.ref, 'refs/tags/v')
133+
- name: Commit AutoUpdater XML
141134
run: |
142135
git config --local user.email "action@github.com"
143136
git config --local user.name "GitHub Action"
144-
git fetch origin main
145-
git checkout -B main origin/main
146137
git add docs/autoupdate.xml
147-
if (git diff --staged --quiet) {
148-
Write-Host "No changes to commit"
149-
} else {
138+
if (!(git diff --staged --quiet)) {
150139
git commit -m "Update AutoUpdater XML for version ${{ steps.version.outputs.VERSION }}"
151140
git push origin main
152141
}

Canon.API/Canon.API.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<PlatformTarget>x64</PlatformTarget>
8+
9+
<!-- Assembly Version Configuration -->
10+
<AssemblyVersion>1.0.0.5</AssemblyVersion>
11+
<FileVersion>1.0.0.5</FileVersion>
12+
<Version>1.0.0.5</Version>
813
</PropertyGroup>
914

1015
<ItemGroup>

0 commit comments

Comments
 (0)