-
-
Notifications
You must be signed in to change notification settings - Fork 18
205 lines (183 loc) · 7.3 KB
/
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
name: Release
on:
workflow_run:
workflows: [ "Cargo Build & Test" ]
branches: [ main ]
types:
- completed
release:
types: [ released ]
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
release:
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
name: Release - ${{ matrix.platform.target }}
strategy:
fail-fast: false
matrix:
platform:
- os: windows-latest
target: x86_64-pc-windows-msvc
inno_arch: x64
- os: windows-latest
target: aarch64-pc-windows-msvc
inno_arch: arm64
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
bins: cargo-deb, cargo-generate-rpm
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
bins: cross, cargo-deb, cargo-generate-rpm
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin
runs-on: ${{ matrix.platform.os }}
steps:
- name: Clone repository
uses: actions/checkout@v4
- uses: moonrepo/setup-rust@v1
with:
targets: ${{ matrix.platform.target }}
bins: ${{ matrix.platform.bins }}
cache: false
- name: Build binary
shell: pwsh
run: |
$tool = if ("${{ matrix.platform.bins }}".Contains("cross")) { "cross" } else { "cargo" }
& $tool build --target ${{ matrix.platform.target }} --release --locked
- name: Create Deb package
if: contains(matrix.platform.bins, 'cargo-deb')
shell: pwsh
run: |
$nightly = if ($env:GITHUB_EVENT_NAME -eq 'workflow_run') { "--deb-version=2.nightly" } else { "" }
cargo deb --target ${{ matrix.platform.target }} --no-build --no-strip $nightly
- name: Create RPM package
if: contains(matrix.platform.bins, 'cargo-generate-rpm')
shell: pwsh
run: |
if ($env:GITHUB_EVENT_NAME -eq 'workflow_run') {
cargo generate-rpm --target ${{ matrix.platform.target }} --set-metadata='version="nightly"'
} else {
cargo generate-rpm --target ${{ matrix.platform.target }}
}
- name: Rename binary
id: rename_binary
shell: pwsh
run: |
$bin = if ($env:RUNNER_OS -eq 'Windows') { "komac.exe" } else { "komac" }
$newName = "komac"
if ($env:GITHUB_EVENT_NAME -eq 'workflow_run') {
$newName += "-nightly"
} else {
$newName += "-$($env:GITHUB_REF_NAME.TrimStart('v'))"
}
$newName += "-${{ matrix.platform.target }}"
if ($env:RUNNER_OS -eq 'Windows') {
$newName += ".exe"
Rename-Item -Path "target/${{ matrix.platform.target }}/release/$bin" -NewName "$newName"
}
"name=$newName" >> $env:GITHUB_OUTPUT
- name: Create Tar archive
if: ${{ runner.os != 'Windows' }}
run: |
tar -czvf ${{ steps.rename_binary.outputs.name }}.tar.gz -C target/${{ matrix.platform.target }}/release komac
rm target/${{ matrix.platform.target }}/release/komac
- name: Create Inno Installer
if: ${{ runner.os == 'Windows' }}
shell: pwsh
run: |
$input = "../target/${{ matrix.platform.target }}/release/${{ steps.rename_binary.outputs.name }}"
iscc.exe assets/installer.iss `
/DInputExecutable=$input `
/DArchitecture=${{ matrix.platform.inno_arch }} `
/F$("${{ steps.rename_binary.outputs.name }}".Replace("komac", "komac-setup").TrimEnd(".exe"))
- name: Compute SHA256 checksum
shell: pwsh
run: |
Get-Item -ErrorAction SilentlyContinue -Path "${{ steps.rename_binary.outputs.name }}.tar.gz","assets/Output/*","target/${{ matrix.platform.target }}/release/*","target/${{ matrix.platform.target }}/debian/*","target/${{ matrix.platform.target }}/generate-rpm/*" -Include "komac-*", "komac*.deb", "komac*.rpm" | ForEach-Object {
$FileHash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash.ToLower()
New-Item -Force -ItemType File -Path $_.DirectoryName -Name "$($_.Name).sha256" -Value "$FileHash *$($_.Name)`n"
}
- name: Set Release variables
id: set_release_vars
shell: pwsh
run: |
if ($env:GITHUB_EVENT_NAME -eq 'workflow_run') {
"name=Nightly release" >> $env:GITHUB_OUTPUT
"tag_name=nightly" >> $env:GITHUB_OUTPUT
"prerelease=true" >> $env:GITHUB_OUTPUT
"generate_release_notes=false" >> $env:GITHUB_OUTPUT
} else {
"prerelease=false" >> $env:GITHUB_OUTPUT
"generate_release_notes=true" >> $env:GITHUB_OUTPUT
}
- name: Release binaries
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.set_release_vars.outputs.name }}
tag_name: ${{ steps.set_release_vars.outputs.tag_name }}
prerelease: ${{ steps.set_release_vars.outputs.prerelease }}
generate_release_notes: ${{ steps.set_release_vars.outputs.generate_release_notes }}
files: |
target/${{ matrix.platform.target }}/release/${{ steps.rename_binary.outputs.name }}
target/${{ matrix.platform.target }}/release/${{ steps.rename_binary.outputs.name }}.sha256
target/${{ matrix.platform.target }}/debian/*.deb
target/${{ matrix.platform.target }}/debian/*.sha256
target/${{ matrix.platform.target }}/generate-rpm/*.rpm
target/${{ matrix.platform.target }}/generate-rpm/*.sha256
${{ steps.rename_binary.outputs.name }}.tar.gz
${{ steps.rename_binary.outputs.name }}.tar.gz.sha256
assets/Output/*
publish-winget:
needs: release
if: ${{ github.event_name != 'workflow_run' }}
runs-on: ubuntu-latest
steps:
- uses: vedantmgoyal9/winget-releaser@main
with:
identifier: RussellBanks.Komac
installers-regex: 'komac-setup.*\.exe$'
token: ${{ secrets.WINGET_TOKEN }}
publish-homebrew-tap:
needs: release
if: ${{ github.event_name != 'workflow_run' }}
runs-on: ubuntu-latest
steps:
- name: Trigger update formula workflow (homebrew-tap)
run: gh workflow run komac.yml -f version=$($env:GITHUB_REF_NAME.TrimStart('v')) -R russellbanks/homebrew-tap
env:
GH_TOKEN: ${{ secrets.WINGET_TOKEN }}
shell: pwsh
upload-virus-total:
needs: release
if: ${{ github.event_name != 'workflow_run' }}
runs-on: ubuntu-latest
steps:
- name: VirusTotal Scan
uses: crazy-max/ghaction-virustotal@v4
with:
vt_api_key: ${{ secrets.VT_API_KEY }}
request_rate: 4
files: |
.exe$
.deb$
.rpm$
.tar.gz$
publish-crates-io:
needs: release
if: ${{ github.event_name != 'workflow_run' }}
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
- uses: moonrepo/setup-rust@v1
with:
cache: false
- name: Publish to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}