-
Notifications
You must be signed in to change notification settings - Fork 8
256 lines (244 loc) · 9.64 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
name: Release
on:
push:
tags:
- "v*"
env:
CARGO_TERM_COLOR: always
jobs:
create_release:
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
release_id: ${{ steps.create_release.outputs.id }}
is_pre: ${{ steps.release_type.outputs.is_pre }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Conventional Commit Changelog
id: conventional_commits
shell: bash
run: |
curl -s -L -o./clog.tar.gz https://github.com/clog-tool/clog-cli/releases/download/v0.9.3/clog-v0.9.3-x86_64-unknown-linux-musl.tar.gz
tar -xf ./clog.tar.gz
chmod +x ./clog
# delete current tag locally
git tag -d "$GITHUB_REF_NAME"
if [[ "$GITHUB_REF_NAME" == *"-"* ]]; then
last_tag="$(git tag -l --sort version:refname | tail -n1)"
else
last_tag="$(git tag -l --sort version:refname | grep -v -- - | tail -n1)"
fi
printf 'Using %s as last tag\n' "$last_tag"
echo 'CHANGELOG<<EOF' >> $GITHUB_ENV
./clog --from="$last_tag" --setversion="$GITHUB_REF_NAME" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Determine release type
id: release_type
shell: bash
run: |
is_pre='false'
[[ "$GITHUB_REF_NAME" == *"-"* ]] && is_pre='true'
printf 'is_pre=%s\n' "$is_pre" >> $GITHUB_OUTPUT
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
draft: true
prerelease: ${{ steps.release_type.outputs.is_pre }}
body: ${{ env.CHANGELOG }}
token: ${{ secrets.GITHUB_TOKEN }}
lint:
runs-on: ${{ matrix.os }}
continue-on-error: false
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
features: [default, all]
steps:
- uses: actions/checkout@v4
- name: Install Rust Toolchain
id: rust_toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt, clippy
- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: lint-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-lock-${{ hashFiles('Cargo.lock') }}-features-${{ matrix.features }}-git-${{ github.sha }}
restore-keys: |
lint-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-lock-${{ hashFiles('Cargo.lock') }}-features-${{ matrix.features }}-
lint-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-lock-${{ hashFiles('Cargo.lock') }}-
lint-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-
lint-${{ runner.os }}-
- name: rustfmt
shell: bash
run: |
cargo fmt -- --check
- name: Clippy
shell: bash
run: |
cargo clippy --features=${{ matrix.features }} --locked -- -D warnings
cargo clippy --features=${{ matrix.features }} --locked --tests -- -D warnings
test:
runs-on: ${{ matrix.os }}
continue-on-error: false
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
features:
- [default]
- [all]
- [notification, encryption, yubikey]
steps:
- uses: actions/checkout@v4
- name: Install Rust Toolchain
id: rust_toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: test-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-lock-${{ hashFiles('Cargo.lock') }}-features-${{ join(matrix.features, '+') }}-git-${{ github.sha }}
restore-keys: |
test-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-lock-${{ hashFiles('Cargo.lock') }}-features-${{ join(matrix.features, '+') }}-
test-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-lock-${{ hashFiles('Cargo.lock') }}-
test-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-
test-${{ runner.os }}-
- name: Test
shell: bash
run: |
cargo test --release --features=${{ join(matrix.features) }}
build:
runs-on: ${{ matrix.os }}
needs: create_release
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
features: [default, all]
steps:
- uses: actions/checkout@v4
- name: Install macOS Dependencies
if: contains(matrix.os, 'macos')
run: |
brew install coreutils gnu-tar
echo PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH" >> $GITHUB_ENV
- name: Install Windows Dependencies
if: contains(matrix.os, 'windows')
run: choco install zip
- name: Install Rust Toolchain
id: rust_toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Add macOS Targets
if: contains(matrix.os, 'macos')
run: |
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: build-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-lock-${{ hashFiles('Cargo.lock') }}-features-${{ matrix.features }}-git-${{ github.sha }}
restore-keys: |
build-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-lock-${{ hashFiles('Cargo.lock') }}-features-${{ matrix.features }}-
build-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-lock-${{ hashFiles('Cargo.lock') }}-
build-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-
build-${{ runner.os }}-
- name: "Build (Linux/Windows)"
if: "!contains(matrix.os, 'macos')"
shell: bash
run: |
cargo build --release --features=${{ matrix.features }}
- name: "Build (macOS x86_64)"
if: contains(matrix.os, 'macos')
shell: bash
run: |
cargo build --release --features=${{ matrix.features }} --target=x86_64-apple-darwin
- name: "Build (macOS aarch64)"
if: contains(matrix.os, 'macos')
shell: bash
run: |
cargo build --release --features=${{ matrix.features }} --target=aarch64-apple-darwin
- name: macOS Universal Binary
if: contains(matrix.os, 'macos')
run: |
mkdir -p target/release/
lipo -create -output target/release/git-credential-keepassxc target/x86_64-apple-darwin/release/git-credential-keepassxc target/aarch64-apple-darwin/release/git-credential-keepassxc
file target/release/git-credential-keepassxc
- name: Determine artifact name suffix
id: artifact_suffix
if: "matrix.features == 'default' || matrix.features == 'all'"
shell: bash
run: |
case "${{ matrix.features }}" in
default)
printf 'suffix=%s\n' 'minimal' >> $GITHUB_OUTPUT
;;
all)
printf 'suffix=%s\n' 'full' >> $GITHUB_OUTPUT
;;
*)
exit 1
;;
esac
- name: Pack
id: pack
shell: bash
run: |
zip -j "./${{ matrix.os }}-${{ steps.artifact_suffix.outputs.suffix }}.zip" target/release/git-credential-keepassxc target/release/git-credential-keepassxc.exe
echo "filename=${{ matrix.os }}-${{ steps.artifact_suffix.outputs.suffix }}" >> $GITHUB_OUTPUT
- name: "Hash (Unix)"
if: "!contains(matrix.os, 'windows')"
run: |
echo "$(sha256sum ${{ steps.pack.outputs.filename }}.zip | cut -d ' ' -f 1)" > ${{ steps.pack.outputs.filename }}.zip.sha256sum
cat ${{ steps.pack.outputs.filename }}.zip.sha256sum
- name: "Hash (Windows)"
if: contains(matrix.os, 'windows')
run: |
$FileHash=(certutil -hashfile ${{ steps.pack.outputs.filename }}.zip SHA256 | findstr /v hash | findstr /v SHA).replace(" ", "")
echo "$FileHash"
echo "$FileHash" > ${{ steps.pack.outputs.filename }}.zip.sha256sum
- name: Upload
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./${{ steps.pack.outputs.filename }}.zip
asset_name: ${{ steps.pack.outputs.filename }}.zip
asset_content_type: application/zip
- name: Upload Hash
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./${{ steps.pack.outputs.filename }}.zip.sha256sum
asset_name: ${{ steps.pack.outputs.filename }}.zip.sha256sum
asset_content_type: text/plain
publish_release:
runs-on: ubuntu-latest
needs: [create_release, lint, test, build]
if: ${{ needs.create_release.outputs.is_pre == 'false' }}
steps:
- name: Publish Release
uses: eregon/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ needs.create_release.outputs.release_id }}