-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (118 loc) · 5 KB
/
build.yml
File metadata and controls
142 lines (118 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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