-
Notifications
You must be signed in to change notification settings - Fork 1
239 lines (205 loc) · 9.02 KB
/
publish-release.yml
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
name: Publish Release
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: write
env:
# Configuring Project
DEVWINUI_GALLERY_PROJECT_PATH: dev/DevWinUI.Gallery/DevWinUI.Gallery.csproj
VSIX_CSPROJ_PATH: VSIX/DevWinUI_Template/DevWinUI_Template/DevWinUI_Template.csproj
VSIX_PROJECT_PATH: VSIX/DevWinUI_Template/DevWinUI_Template
VSIX_MANIFEST_PATH: VSIX/DevWinUI_Template/DevWinUI_Template/source.extension.vsixmanifest
VSIX_OUTPUT_PATH: VSIX/DevWinUI_Template/DevWinUI_Template/bin/Release
VSIX_OUTPUT_BASE_NAME: DevWinUI
APP_NAME: DevWinUIGallery
APP_VERSION: ''
APP_VERSION_SUFFIX: ''
APP_VERSION_PREFIX: ''
VSIX_VERSION: ''
VSIX_IS_PREVIEW: ''
# Check Tag
CHECK_TAG_EXISTENCE_BEFORE_CREATING_TAG: false
# Custom Nuget Source
IS_COMMUNITY_TOOLKIT_NUGET_SOURCE_ENABLED: false
IS_CUSTOM_NUGET_SOURCE_ENABLED: false
CUSTOM_NUGET_SOURCES: '' # Example ('https://api.nuget.org/v3/index.json, https://api.nuget.org/v2/index.json,...')
# Configuring Dotnet Build Commands
PUBLISH_OUTPUT_FOLDER: Publish
PUBLISH_SELF_CONTAINED: true
PUBLISH_SINGLE_FILE: false
PUBLISH_READY_TO_RUN: true
PUBLISH_AOT: false
PUBLISH_TRIMMED: false
PUBLISH_TRIM_MODE: partial # or full
# Configuring GitHub Release
IS_PRE_RELEASE: false
SKIP_IF_RELEASE_EXIST: true
MAKE_LATEST: true
ALLOW_UPDATES: false
ARTIFACT_ERRORS_FAIL_BUILD: false
jobs:
build:
runs-on: windows-latest
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
outputs: # For accessing them from 'release' job
IS_PRE_RELEASE: ${{ env.IS_PRE_RELEASE }}
APP_VERSION: ${{ env.APP_VERSION }}
strategy:
matrix:
platform: [x64] # Change platform if you want to build only a specific platform
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.x.x
9.x.x
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2
with:
vs-prerelease: true
# Add CommunityToolkit Labs and Main nuget sources
- run: |
nuget sources add -name CommunityToolkit-Labs -source https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-Labs/nuget/v3/index.json
nuget sources add -name CommunityToolkit-Main -source https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-MainLatest/nuget/v3/index.json
if: contains(env.IS_COMMUNITY_TOOLKIT_NUGET_SOURCE_ENABLED, 'true')
# Add Custom nuget sources
- run: |
$sources = $env:CUSTOM_NUGET_SOURCES -split ','
$trimmedSources = $sources | ForEach-Object { $_.Trim() }
$prefix = "CUSTOM_SOURCES_"
for ($i = 0; $i -lt $trimmedSources.Length; $i++) {
$sourceName = "${prefix}$($i + 1)"
nuget sources add -name $sourceName -source $trimmedSources[$i]
}
if: contains(env.IS_CUSTOM_NUGET_SOURCE_ENABLED, 'true')
- name: Run MSBuild to Get Version
id: get-version
shell: pwsh
run: |
# Run MSBuild and capture raw version output
$output = & msbuild "${{ env.DEVWINUI_GALLERY_PROJECT_PATH }}" /t:GetVersion /v:m 2>&1
Write-Output "MSBuild Output: $output"
# Extract the version string (assumes the last line contains the version)
$lines = $output -split "`n"
$version = $lines[-1].Trim()
Write-Output "Extracted Version: $version"
# Parse the version into prefix and suffix
if ($version -match '^([^-]+)-(.+)$') {
$prefix = $Matches[1]
$suffix = $Matches[2]
} else {
$prefix = $version
$suffix = ""
}
# Set environment variables
Write-Output "APP_VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append
Write-Output "APP_VERSION_PREFIX=$prefix" | Out-File -FilePath $env:GITHUB_ENV -Append
Write-Output "APP_VERSION_SUFFIX=$suffix" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Verify Environment Variables
run: |
echo "APP_VERSION=${{ env.APP_VERSION }}"
echo "APP_VERSION_PREFIX=${{ env.APP_VERSION_PREFIX }}"
echo "APP_VERSION_SUFFIX=${{ env.APP_VERSION_SUFFIX }}"
# Building with configured commands
- run: |
$runtimeIdentifier = "${{ matrix.platform }}"
dotnet publish ${{ env.DEVWINUI_GALLERY_PROJECT_PATH }} -c Release -r win-$($runtimeIdentifier.ToLower()) /p:GITHUB_ACTIONS=true -p:Platform=${{ matrix.platform }} --self-contained ${{ env.PUBLISH_SELF_CONTAINED }} -p:PublishSingleFile=${{ env.PUBLISH_SINGLE_FILE }} -p:PublishReadyToRun=${{ env.PUBLISH_READY_TO_RUN }} -p:PublishTrimmed=${{ env.PUBLISH_TRIMMED }} -p:TrimMode=${{ env.PUBLISH_TRIM_MODE }} -p:PublishAot=${{ env.PUBLISH_AOT }} --output ${{ env.PUBLISH_OUTPUT_FOLDER }}/${{ matrix.platform }}
# Zipping folder and all files
- uses: vimtor/[email protected]
with:
files: ${{ env.PUBLISH_OUTPUT_FOLDER }}/${{ matrix.platform }}
recursive: true
dest: ${{ env.APP_NAME }}-v${{ env.APP_VERSION }}-${{ matrix.platform }}.zip
# Get VSIX Version from source.extension.vsixmanifest
- name: Get VSIX Version
run: |
[xml]$xml = Get-Content ${{ env.VSIX_MANIFEST_PATH }}
$vsixVersion = $xml.PackageManifest.Metadata.Identity.Version
$isVSIXPreview = $xml.PackageManifest.Metadata.Preview
if (-not $isVSIXPreview) {
# Default value if <Preview> tag is missing
$isVSIXPreview = ""
} elseif ($isVSIXPreview -eq "true") {
# Set property value to "preview" if <Preview> tag exists and is true
$isVSIXPreview = "-Preview"
}
Write-Output "VSIX_VERSION=$vsixVersion" | Out-File -FilePath $env:GITHUB_ENV -Append
Write-Output "VSIX_IS_PREVIEW=$isVSIXPreview" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Verify Environment Variables
run: |
echo "VSIX_VERSION=${{ env.VSIX_VERSION }}"
echo "VSIX_IS_PREVIEW=${{ env.VSIX_IS_PREVIEW }}"
# Uploading all zip files to access them in the 'release' job
- uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.platform }}
path: ${{ env.APP_NAME }}-v${{ env.APP_VERSION }}-${{ matrix.platform }}.zip
# Checking version suffix for words like [alpha, beta, preview, and experiment]. Marking the release as a pre-release if any exists.
- run: |
# Define the list of strings
$list = @("beta", "alpha", "preview", "experiment")
# Define the suffix variable
$suffix = "${{ env.APP_VERSION_SUFFIX }}"
foreach ($item in $list) {
# Convert both strings to lower case for case-insensitive comparison
if ($suffix.ToLower().StartsWith($item.ToLower())) {
echo "IS_PRE_RELEASE=true" >> $env:GITHUB_ENV
break
}
}
release:
needs: build
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
env:
# Read some variables from the 'build' job
APP_VERSION: ${{ needs.build.outputs.APP_VERSION }}
IS_PRE_RELEASE: ${{ needs.build.outputs.IS_PRE_RELEASE }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# Downloading all zip files into the GitHub root directory (uploaded in 'build' job)
- uses: actions/download-artifact@v4
with:
merge-multiple: true
# Configuring git to create a tag
- run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
TAG_NAME="v${{ env.APP_VERSION }}"
if [[ "${{ env.CHECK_TAG_EXISTENCE_BEFORE_CREATING_TAG }}" == "true" ]]; then
git fetch --tags
if [[ $(git tag -l "$TAG_NAME") ]]; then
echo "Tag found (already exist). Skipping to the next step"
else
echo "Tag not found, creating new tag"
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
fi
else
echo "Creating new tag"
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
fi
# Installing a package for generating a changelog file
- run: npm install -g auto-changelog
- run: auto-changelog --tag-pattern .+ --commit-limit false --starting-version v${{ env.APP_VERSION }} --ending-version v${{ env.APP_VERSION }} --hide-credit
# Creating a Release in GitHub
- uses: ncipollo/release-action@v1
with:
artifacts: "${{ env.APP_NAME }}-v${{ env.APP_VERSION }}-*.zip"
bodyFile: "CHANGELOG.md"
name: v${{ env.APP_VERSION }}
tag: v${{ env.APP_VERSION }}
prerelease: ${{ env.IS_PRE_RELEASE }}
skipIfReleaseExists: ${{ env.SKIP_IF_RELEASE_EXIST }}
makeLatest: ${{ env.MAKE_LATEST }}
allowUpdates: ${{ env.ALLOW_UPDATES }}
artifactErrorsFailBuild: ${{ env.ARTIFACT_ERRORS_FAIL_BUILD }}