-
Notifications
You must be signed in to change notification settings - Fork 1
236 lines (184 loc) · 7.87 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
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
name: Release
on:
release:
types: [published]
env:
RUSTFLAGS: -Dwarnings
CARGO_TERM_COLOR: always
BINARY_NAME: "pwdgen"
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
VT_API_KEY: ${{ secrets.VT_API_KEY }}
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.version_check.outputs.version_match }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check version
id: version_check
shell: pwsh
run: |
$TAG_VERSION = $env:GITHUB_REF -replace '^refs/tags/v', ''
$CARGO_VERSION = (Select-String -Path Cargo.toml -Pattern '^version = "(.+)"').Matches.Groups[1].Value
Write-Output "Tag version: $TAG_VERSION"
Write-Output "Cargo.toml version: $CARGO_VERSION"
if ($TAG_VERSION -eq $CARGO_VERSION) {
Write-Output "version_match=true" >> $env:GITHUB_OUTPUT
Write-Output "Versions match. Proceeding with the release check."
} else {
Write-Output "version_match=false" >> $env:GITHUB_OUTPUT
Write-Output "Version mismatch detected!"
}
- name: Display version_match output
run: echo "${{ steps.version_check.outputs.version_match }}"
check-last-commit:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.check_last_commit.outputs.passed_test }}
checks: ${{ steps.check_last_commit.outputs.checks }}
markdown_checks: ${{ steps.check_last_commit.outputs.markdown_checks }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check last commit status
id: check_last_commit
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$COMMIT_SHA = git rev-parse HEAD
$CHECK_RUNS = gh api repos/$env:GITHUB_REPOSITORY/commits/$COMMIT_SHA/check-runs --jq '.check_runs[] | {name, conclusion}'
# Filter only the runs relevant to check-version and check-last-commit
$SELECTED_CHECK_RUNS = $CHECK_RUNS | Where-Object { $_.name -eq 'check-version' -or $_.name -eq 'check-last-commit' }
$CHECK_RUNS = $SELECTED_CHECK_RUNS
$FAILED_CHECKS = $CHECK_RUNS | ConvertFrom-Json | Where-Object { $_.conclusion -ne 'success' }
$ALL_CHECKS = ($CHECK_RUNS | ConvertFrom-Json | ForEach-Object { "$($_.name): $($_.conclusion)" }) -join ', '
$MARKDOWN_CHECKS = ($CHECK_RUNS | ConvertFrom-Json | ForEach-Object { "- **$($_.name)**: $($_.conclusion)" }) -join "`n"
Write-Output "checks=$ALL_CHECKS" >> $env:GITHUB_OUTPUT
Write-Output "markdown_checks=`n$MARKDOWN_CHECKS" >> $env:GITHUB_OUTPUT
if ($FAILED_CHECKS) {
Write-Output "passed_test=false" >> $env:GITHUB_OUTPUT
$FAILED_NAMES = ($FAILED_CHECKS | ForEach-Object { $_.name }) -join ', '
Write-Output "The last commit does not have all successful tests. Failed checks: $FAILED_NAMES"
} else {
Write-Output "passed_test=true" >> $env:GITHUB_OUTPUT
Write-Output "All checks passed for the last commit."
}
return
- name: Display passed_test output
run: echo "${{ steps.check_last_commit.outputs.passed_test }}"
- name: Display checks output
run: echo "${{ steps.check_last_commit.outputs.markdown_checks }}"
handle-release:
needs: [check-version, check-last-commit]
if: always()
outputs:
status: ${{ steps.handle.outputs.status }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Handle failed checks
id: handle
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$TAG_VERSION = $env:GITHUB_REF -replace '^refs/tags/v', ''
$CHECK_RUNS =
$ISSUE_BODY = ""
if ('${{ needs.check-version.outputs.result }}' -eq 'false') {
$ISSUE_BODY += "## Version\n"
$ISSUE_BODY += "Version mismatch detected between tag and Cargo.toml."
$ISSUE_BODY += " The release has been unpublished.\n"
}
if ('${{ needs.check-last-commit.outputs.result }}' -eq 'false') {
$ISSUE_BODY += "## Tests\n"
$ISSUE_BODY += "The last commit does not have all successful tests.\n"
$ISSUE_BODY += "${{ needs.check-last-commit.outputs.markdown_checks }}"
}
$ISSUE_URL = gh issue create --label bug --title "Release $($TAG_VERSION) Check Failed" --body $ISSUE_BODY --assignee "@me"
if ($env:GITHUB_EVENT_NAME -eq "release") {
Write-Output "status=false" >> $env:GITHUB_OUTPUT
gh release delete $TAG_VERSION --yes
Write-Output "Release has been unpublished due to check failure."
git push origin :refs/tags/v$TAG_VERSION
Write-Output "Tag v$TAG_VERSION has been deleted."
}
Write-Output "status=true" >> $env:GITHUB_OUTPUT
Write-Output "An issue has been created: $ISSUE_URL"
- name: Display status output
run: echo "${{ steps.handle.outputs.status }}"
release:
needs: handle-release
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
rust_version: [stable]
include:
- os: macos-latest
os_name: "macos"
asset_extension: ""
asset_content_type: application/octet-stream
- os: windows-latest
os_name: "windows"
asset_extension: ".exe"
asset_content_type: application/octet-stream
- os: ubuntu-latest
os_name: "ubuntu"
asset_extension: ""
asset_content_type: application/octet-stream
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust_version }}
override: true
- name: Prepare Ubuntu environment
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
sudo apt update
sudo apt install -y libxcb-shape0-dev libxcb-xfixes0-dev
- name: Build release
run: cargo build --release
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: "${{ env.BINARY_NAME }}-${{ github.event.release.tag_name }}-${{ env.BINARY_NAME }}-${{ matrix.os_name }}${{ matrix.asset_extension }}"
path: target/release/${{ env.BINARY_NAME }}${{ matrix.asset_extension }}
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./target/release/${{ env.BINARY_NAME }}${{ matrix.asset_extension }}
asset_name: "${{ env.BINARY_NAME }}-${{ matrix.os_name }}${{ matrix.asset_extension }}"
asset_content_type: ${{ matrix.asset_content_type }}
- name: VirusTotal Scan
uses: crazy-max/ghaction-virustotal@v4
with:
vt_api_key: ${{ env.VT_API_KEY }}
update_release_body: true
files: ./target/release/${{ env.BINARY_NAME }}${{ matrix.asset_extension }}
- name: Notify success
if: success()
run: echo "Release process completed successfully!"
- name: Notify failure
if: failure()
run: echo "Release process failed, check logs for details."
publish-crate:
needs: handle-release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build
run: cargo build --release
- name: Publish to Crates.io
run: cargo publish --token ${CRATES_TOKEN}