-
Notifications
You must be signed in to change notification settings - Fork 0
240 lines (210 loc) · 7.9 KB
/
Copy pathrelease.yml
File metadata and controls
240 lines (210 loc) · 7.9 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
name: Release
on:
push:
tags:
- "v*.*.*"
permissions:
contents: write
packages: write
env:
DOTNET_VERSION: 10.0.x
SOLUTION_PATH: src/PictureSortAndDuplicateCleaner.slnx
CLI_PROJECT_PATH: src/PictureSortAndDuplicateCleaner.Cmd/PictureSortAndDuplicateCleaner.Cmd.csproj
IMAGE_NAME: ghcr.io/blubern/picturesortandduplicatecleaner
jobs:
validate:
name: Build and test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6.0.2
- name: Setup .NET
uses: actions/setup-dotnet@v5.2.0
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore
run: dotnet restore "${{ env.SOLUTION_PATH }}"
- name: Build
run: dotnet build "${{ env.SOLUTION_PATH }}" --configuration Release --no-restore
- name: Test
run: dotnet test "${{ env.SOLUTION_PATH }}" --configuration Release --no-build --verbosity normal
native-artifacts:
name: Native artifact (${{ matrix.rid }})
runs-on: ubuntu-latest
needs: validate
strategy:
fail-fast: false
matrix:
include:
- rid: win-x64
asset_name: picturesortandduplicatecleaner-${{ github.ref_name }}-win-x64.zip
app_file: PictureSortAndDuplicateCleaner.Cmd.exe
app_target: picturesortandduplicatecleaner.exe
archive: zip
- rid: linux-x64
asset_name: picturesortandduplicatecleaner-${{ github.ref_name }}-linux-x64.tar.gz
app_file: PictureSortAndDuplicateCleaner.Cmd
app_target: picturesortandduplicatecleaner
archive: tar.gz
- rid: osx-arm64
asset_name: picturesortandduplicatecleaner-${{ github.ref_name }}-osx-arm64.tar.gz
app_file: PictureSortAndDuplicateCleaner.Cmd
app_target: picturesortandduplicatecleaner
archive: tar.gz
steps:
- name: Checkout
uses: actions/checkout@v6.0.2
- name: Setup .NET
uses: actions/setup-dotnet@v5.2.0
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Publish
shell: pwsh
run: |
$version = "${{ github.ref_name }}" -replace '^v', ''
dotnet publish "${{ env.CLI_PROJECT_PATH }}" `
--configuration Release `
--runtime "${{ matrix.rid }}" `
--self-contained true `
--output "artifacts/publish/${{ matrix.rid }}" `
-p:Version="$version" `
-p:InformationalVersion="${{ github.ref_name }}+${{ github.sha }}" `
-p:PublishSingleFile=true `
-p:PublishTrimmed=false `
-p:IncludeNativeLibrariesForSelfExtract=true `
-p:EnableCompressionInSingleFile=true `
-p:DebugType=embedded
- name: Package
shell: pwsh
run: |
$publishDir = "artifacts/publish/${{ matrix.rid }}"
$packageDir = "artifacts/package/${{ matrix.rid }}"
New-Item -ItemType Directory -Force -Path $packageDir | Out-Null
Copy-Item -Path "$publishDir/*" -Destination $packageDir -Recurse -Force
$sourceApp = Join-Path $packageDir "${{ matrix.app_file }}"
$targetApp = Join-Path $packageDir "${{ matrix.app_target }}"
if (Test-Path $sourceApp) {
Rename-Item -Path $sourceApp -NewName "${{ matrix.app_target }}"
}
if ("${{ matrix.archive }}" -eq "tar.gz") {
chmod +x $targetApp
tar -czf "artifacts/${{ matrix.asset_name }}" -C $packageDir .
} else {
Compress-Archive -Path "$packageDir/*" -DestinationPath "artifacts/${{ matrix.asset_name }}" -Force
}
- name: Upload release asset
uses: actions/upload-artifact@v7.0.1
with:
name: release-assets-${{ matrix.rid }}
path: artifacts/${{ matrix.asset_name }}
if-no-files-found: error
retention-days: 1
docker-image:
name: Docker image
runs-on: ubuntu-latest
needs: validate
steps:
- name: Checkout
uses: actions/checkout@v6.0.2
- name: Setup QEMU
uses: docker/setup-qemu-action@v4.0.0
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v4.0.0
- name: Login to GHCR
uses: docker/login-action@v4.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v6.0.0
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ !contains(github.ref_name, '-') }}
labels: |
org.opencontainers.image.title=PictureSortAndDuplicateCleaner
org.opencontainers.image.description=Sort photos and detect duplicates from mounted folders.
org.opencontainers.image.source=https://github.com/Blubern/PictureSortAndDuplicateCleaner
- name: Build and push
uses: docker/build-push-action@v7.2.0
env:
DOCKER_BUILD_SUMMARY: false
DOCKER_BUILD_RECORD_UPLOAD: false
with:
context: .
file: src/PictureSortAndDuplicateCleaner.Cmd/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
github-release:
name: GitHub Release
runs-on: ubuntu-latest
needs:
- native-artifacts
- docker-image
steps:
- name: Download release assets
uses: actions/download-artifact@v8.0.1
with:
pattern: release-assets-*
path: release-assets
merge-multiple: true
- name: Generate checksums
shell: pwsh
run: |
Get-ChildItem -Path release-assets -File |
Where-Object { $_.Name -ne 'SHA256SUMS.txt' } |
Sort-Object Name |
ForEach-Object {
$hash = Get-FileHash -Algorithm SHA256 -Path $_.FullName
"$($hash.Hash.ToLowerInvariant()) $($_.Name)"
} | Set-Content -Path release-assets/SHA256SUMS.txt -Encoding ascii
- name: Publish GitHub Release
uses: softprops/action-gh-release@v3.0.0
with:
tag_name: ${{ github.ref_name }}
name: PictureSortAndDuplicateCleaner ${{ github.ref_name }}
generate_release_notes: true
make_latest: true
files: |
release-assets/*.zip
release-assets/*.tar.gz
release-assets/SHA256SUMS.txt
cleanup:
name: Cleanup workflow artifacts
needs: [github-release]
if: success()
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
actions: write
steps:
- name: Delete this run's workflow artifacts
uses: actions/github-script@v9
with:
script: |
// After a successful release the assets live on the GitHub Release
// page and the image lives in GHCR -- workflow artifacts are pure
// transport between jobs and can be discarded.
const runId = context.runId;
const artifacts = await github.paginate(
github.rest.actions.listWorkflowRunArtifacts,
{ owner: context.repo.owner, repo: context.repo.repo, run_id: runId, per_page: 100 }
);
let deleted = 0;
for (const a of artifacts) {
console.log(`Deleting ${a.name} (id: ${a.id}, size: ${a.size_in_bytes})`);
await github.rest.actions.deleteArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: a.id
});
deleted++;
}
console.log(`Deleted ${deleted} artifact(s) from run ${runId}.`);