-
Notifications
You must be signed in to change notification settings - Fork 5
232 lines (214 loc) · 6.62 KB
/
ci.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
name: CI
on:
workflow_dispatch:
pull_request:
branches:
- main
push:
branches:
- main
- ci/*
tags:
- 'v0.[0-9]+.[0-9]+'
- 'v0.[0-9]+.[0-9]+-beta.[0-9]+'
- 'v0.[0-9]+.[0-9]+-alpha.[0-9]+'
jobs:
style:
name: check style
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
components: rustfmt, clippy
- name: rust cache
uses: Swatinem/rust-cache@v2
- name: rust fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
build:
env:
# Emit backtraces on panics.
RUST_BACKTRACE: 1
runs-on: ${{ matrix.os }}
needs: [style]
outputs:
release_id: ${{ steps.release.outputs.id }}
strategy:
matrix:
# build: [linux, linux-arm, macos, winmsvc]
include:
- build: linux
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-musl
usecross: false
# - build: linux-arm
# os: ubuntu-latest
# rust: stable
# target: aarch64-unknown-linux-musl
# usecross: true
- build: macos
os: macos-latest
rust: stable
target: x86_64-apple-darwin
usecross: false
- build: winmsvc
os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
usecross: false
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Get the build metadata
shell: bash
run: |
echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo "CARGO_VERSION=$(grep -m 1 '^version = ' Cargo.toml | cut -f 3 -d ' ' | tr -d \")" >> $GITHUB_ENV
echo "PKG_NAME=$(grep -m 1 '^name = ' Cargo.toml | cut -f 3 -d ' ' | tr -d \")" >> $GITHUB_ENV
- name: Validate git tag and Cargo.toml version
shell: bash
if: startsWith(github.ref, 'refs/tags/')
run: |
if [ "${{ env.VERSION }}" != "v${{ env.CARGO_VERSION }}" ]; then
echo "git tag version (${{ env.VERSION }}) does not match Cargo.toml version (v${{ env.CARGO_VERSION }})"
exit 1
fi
- name: Install musl-tools
if: matrix.build == 'linux'
run: sudo apt install musl-tools
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
profile: minimal
override: true
- name: Build debug
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.usecross }}
command: build
args: --verbose --locked --all --target ${{ matrix.target }}
- name: Build release
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.usecross }}
command: build
args: --verbose --locked --all --release --target ${{ matrix.target }}
- name: Test
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.usecross }}
command: test
args: --verbose --locked --all --release --target ${{ matrix.target }}
- name: Strip release binary (linux and macos only)
if: matrix.build == 'linux' || matrix.build == 'macos'
run: strip "target/${{ matrix.target }}/release/${{ env.PKG_NAME }}"
- name: Build archive
shell: bash
run: |
staging="${{ env.PKG_NAME }}-${{ env.VERSION }}-${{ matrix.target }}"
mkdir -p "$staging"
cp {README.md,LICENSE*} "$staging/"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
cp "target/${{ matrix.target }}/release/${{ env.PKG_NAME }}.exe" "$staging/"
7z a "$staging.zip" "$staging"
echo "ASSET=${staging}.zip" >> $GITHUB_ENV
else
cp "target/${{ matrix.target }}/release/${{ env.PKG_NAME }}" "$staging/"
tar czf "$staging.tar.gz" "$staging"
echo "ASSET=${staging}.tar.gz" >> $GITHUB_ENV
fi
- name: Create draft release and upload asset
id: release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
files: ${{ env.ASSET }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-crate:
name: publish-crate
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: [build]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Login to crates.io
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.usecross }}
command: login
args: ${{ secrets.CRATES_TOKEN }}
- name: Publish to crates.io
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.usecross }}
command: publish
publish-release:
name: publish-release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: ['build', 'publish-crate']
steps:
- name: Publish release
uses: StuYarrow/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
id: ${{ needs.build.outputs.release_id }}
publish-aur:
name: publish-aur
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: ['build', 'publish-crate', 'publish-release']
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Get the build metadata
shell: bash
run: |
echo "PKG_NAME=$(grep -m 1 '^name = ' Cargo.toml | cut -f 3 -d ' ' | tr -d \")" >> $GITHUB_ENV
- name: Create PKGBUILD
shell: bash
run: |
cd ${GITHUB_WORKSPACE}/packages/aur
./genpkgbuild.sh
- name: Publish Release to AUR
uses: KSXGitHub/github-actions-deploy-aur@v2.7.0
with:
pkgname: ${{ env.PKG_NAME }}-bin
pkgbuild: packages/aur/PKGBUILD
commit_username: ${{ secrets.AUR_USERNAME }}
commit_email: ${{ secrets.AUR_EMAIL }}
ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}