-
Notifications
You must be signed in to change notification settings - Fork 0
222 lines (189 loc) · 7.03 KB
/
Copy pathrelease.yml
File metadata and controls
222 lines (189 loc) · 7.03 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
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
name: Release
# On every push to main the project is built and tested. A release with the
# portable, self-contained executables is published only when <Version> in
# M32LiveConsoleTool.csproj changes (i.e. its tag does not exist yet), so bumping
# that number is the single gesture that ships a new release.
on:
push:
branches: [ main ]
workflow_dispatch:
# Least privilege by default; only the release job is allowed to write (it creates
# the tag and the GitHub release).
permissions:
contents: read
# Never let two runs publish the same release at once, and never abort one midway.
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
env:
PROJECT: M32LiveConsoleTool.csproj
SOLUTION: M32LiveConsoleTool.slnx
DOTNET_VERSION: '10.0.x'
DOTNET_NOLOGO: 'true'
DOTNET_CLI_TELEMETRY_OPTOUT: 'true'
jobs:
validate:
name: Build, test and read version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
should_release: ${{ steps.gate.outputs.should_release }}
steps:
- uses: actions/checkout@v4
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore
run: dotnet restore "$SOLUTION"
- name: Build
run: dotnet build "$SOLUTION" -c Release --no-restore
- name: Test
run: dotnet test "$SOLUTION" -c Release --no-build --verbosity normal
- name: Read version from the project
id: version
run: |
version="$(dotnet msbuild "$PROJECT" -nologo --getProperty:Version)"
version="$(echo "$version" | tr -d '[:space:]')"
if [ -z "$version" ]; then
echo "Could not read <Version> from $PROJECT" >&2
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Project version: $version"
- name: Decide whether to release
id: gate
run: |
version="${{ steps.version.outputs.version }}"
if git ls-remote --tags --exit-code origin "refs/tags/v$version" >/dev/null 2>&1; then
echo "Tag v$version already exists -- nothing to release."
echo "should_release=false" >> "$GITHUB_OUTPUT"
else
echo "Tag v$version does not exist -- a release will be published."
echo "should_release=true" >> "$GITHUB_OUTPUT"
fi
build:
name: Publish ${{ matrix.rid }}
needs: validate
if: needs.validate.outputs.should_release == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
include:
- rid: win-x64
archive: zip
- rid: linux-x64
archive: tar
- rid: osx-x64
archive: tar
- rid: osx-arm64
archive: tar
steps:
- uses: actions/checkout@v4
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# Single self-contained file with the runtime embedded. No trimming, so
# reflection-based JSON config keeps working; compression keeps the size down.
- name: Publish self-contained single file
run: |
dotnet publish "$PROJECT" \
-c Release \
-r "${{ matrix.rid }}" \
--self-contained true \
-p:PublishSingleFile=true \
-p:EnableCompressionInSingleFile=true \
-p:IncludeNativeLibrariesForSelfExtract=true \
-p:DebugType=none \
-p:DebugSymbols=false \
-o "out/${{ matrix.rid }}"
- name: Stage and compress
run: |
version="${{ needs.validate.outputs.version }}"
rid="${{ matrix.rid }}"
name="M32LiveConsoleTool-v$version-$rid"
stage="stage/$name"
mkdir -p "$stage" dist
if [ -f "out/$rid/M32LiveConsoleTool.exe" ]; then
cp "out/$rid/M32LiveConsoleTool.exe" "$stage/"
else
cp "out/$rid/M32LiveConsoleTool" "$stage/"
chmod +x "$stage/M32LiveConsoleTool"
fi
cp LICENSE README.md "$stage/"
if [ "${{ matrix.archive }}" = "zip" ]; then
(cd stage && zip -r -q "../dist/$name.zip" "$name")
else
tar -czf "dist/$name.tar.gz" -C stage "$name"
fi
ls -lh dist
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.rid }}
path: dist/*
if-no-files-found: error
retention-days: 1
release:
name: Publish GitHub release
needs: [ validate, build ]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: dist
pattern: dist-*
merge-multiple: true
- name: Generate checksums
run: |
cd dist
sha256sum * > SHA256SUMS.txt
cat SHA256SUMS.txt
- name: Write release notes
run: |
cat > notes.md <<'EOF'
## Downloads
| Platform | File |
| --- | --- |
| Windows · x64 | `M32LiveConsoleTool-v${{ needs.validate.outputs.version }}-win-x64.zip` |
| Linux · x64 | `M32LiveConsoleTool-v${{ needs.validate.outputs.version }}-linux-x64.tar.gz` |
| macOS · Apple Silicon | `M32LiveConsoleTool-v${{ needs.validate.outputs.version }}-osx-arm64.tar.gz` |
| macOS · Intel | `M32LiveConsoleTool-v${{ needs.validate.outputs.version }}-osx-x64.tar.gz` |
Each archive holds a single self-contained executable with the .NET runtime
embedded -- no installation and no dependencies.
## Run it
**Windows** -- unzip and run `M32LiveConsoleTool.exe`. If SmartScreen warns
about an unrecognized app, choose **More info -> Run anyway**.
**Linux / macOS** -- extract and run it from a terminal:
```bash
tar -xzf M32LiveConsoleTool-v<version>-<platform>.tar.gz
cd M32LiveConsoleTool-v<version>-<platform>
chmod +x M32LiveConsoleTool
./M32LiveConsoleTool
```
On macOS the binary is not code-signed, so Gatekeeper may block it on first
launch. Clear the quarantine attribute and run it again:
```bash
xattr -d com.apple.quarantine M32LiveConsoleTool
```
## Verify the download (optional)
```bash
sha256sum -c SHA256SUMS.txt # Linux
shasum -a 256 -c SHA256SUMS.txt # macOS
```
EOF
cat notes.md
- name: Create release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "v${{ needs.validate.outputs.version }}" dist/* \
--target "${{ github.sha }}" \
--title "M32 Live Console Tool v${{ needs.validate.outputs.version }}" \
--notes-file notes.md