-
Notifications
You must be signed in to change notification settings - Fork 5
280 lines (267 loc) · 9.29 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
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:
build:
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- x86_64-apple-darwin
- aarch64-apple-darwin
- x86_64-pc-windows-msvc
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
env:
# emit backtraces on panics.
RUST_BACKTRACE: 1
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Get the build metadata
shell: bash
run: |
echo "version=$(grep -m 1 '^version = ' Cargo.toml | cut -f 3 -d ' ' | tr -d \")" >> $GITHUB_ENV
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
override: true
profile: minimal
components: rustfmt, clippy
- name: Install musl tools
if: matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt-get install -y musl-tools
- uses: swatinem/rust-cache@v2.7.3
- 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
- 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: Prepare unix archive
if: matrix.os != 'windows-latest'
working-directory: target/${{ matrix.target }}/release
run: |
strip rblog
tar czvf ../../../rblog-v${{ env.version }}-${{ matrix.target }}.tar.gz rblog
- name: Prepare windows archive
if: matrix.os == 'windows-latest'
working-directory: target/${{ matrix.target }}/release
run: |
strip rblog.exe
7z a ../../../rblog-v${{ env.version }}-${{ matrix.target }}.zip rblog.exe
- name: Upload unix artifact
uses: actions/upload-artifact@v4
if: matrix.os != 'windows-latest'
with:
name: rblog-v${{ env.version }}-${{ matrix.target }}.tar.gz
path: rblog-v${{ env.version }}-${{ matrix.target }}.tar.gz
if-no-files-found: error
- name: Upload windows artifact
uses: actions/upload-artifact@v4
if: matrix.os == 'windows-latest'
with:
name: rblog-v${{ env.version }}-${{ matrix.target }}.zip
path: rblog-v${{ env.version }}-${{ matrix.target }}.zip
if-no-files-found: error
publish_crate:
if: startsWith(github.ref, 'refs/tags/')
needs:
- build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
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:
command: login
args: ${{ secrets.CRATES_TOKEN }}
- name: Publish to crates.io
uses: actions-rs/cargo@v1
with:
command: publish
release:
if: startsWith(github.ref, 'refs/tags/')
needs:
- publish_crate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get the build metadata
shell: bash
run: |
echo "version=$(grep -m 1 '^version = ' Cargo.toml | cut -f 3 -d ' ' | tr -d \")" >> $GITHUB_ENV
- name: Download x86_64-unknown-linux-gnu.tar.gz
uses: actions/download-artifact@v4
with:
name: rblog-v${{ env.version }}-x86_64-unknown-linux-gnu.tar.gz
path: .
- name: Download x86_64-unknown-linux-musl.tar.gz
uses: actions/download-artifact@v4
with:
name: rblog-v${{ env.version }}-x86_64-unknown-linux-musl.tar.gz
path: .
- name: Download rblog-x86_64-apple-darwin.tar.gz
uses: actions/download-artifact@v4
with:
name: rblog-v${{ env.version }}-x86_64-apple-darwin.tar.gz
path: .
- name: Download rblog-aarch64-apple-darwin.tar.gz
uses: actions/download-artifact@v4
with:
name: rblog-v${{ env.version }}-aarch64-apple-darwin.tar.gz
path: .
- name: rblog-x86_64-pc-windows-msvc.zip
uses: actions/download-artifact@v4
with:
name: rblog-v${{ env.version }}-x86_64-pc-windows-msvc.zip
path: .
- name: Generate checksums
run: for file in rblog-*; do openssl dgst -sha256 -r "$file" | awk '{print $1}' > "${file}.sha256"; done
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
files: |
rblog-v${{ env.version }}-x86_64-unknown-linux-gnu.tar.gz
rblog-v${{ env.version }}-x86_64-unknown-linux-gnu.tar.gz.sha256
rblog-v${{ env.version }}-x86_64-unknown-linux-musl.tar.gz
rblog-v${{ env.version }}-x86_64-unknown-linux-musl.tar.gz.sha256
rblog-v${{ env.version }}-x86_64-apple-darwin.tar.gz
rblog-v${{ env.version }}-x86_64-apple-darwin.tar.gz.sha256
rblog-v${{ env.version }}-aarch64-apple-darwin.tar.gz
rblog-v${{ env.version }}-aarch64-apple-darwin.tar.gz.sha256
rblog-v${{ env.version }}-x86_64-pc-windows-msvc.zip
rblog-v${{ env.version }}-x86_64-pc-windows-msvc.zip.sha256
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
needs:
- build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get the build metadata
shell: bash
run: |
echo "version=$(grep -m 1 '^version = ' Cargo.toml | cut -f 3 -d ' ' | tr -d \")" >> $GITHUB_ENV
- name: Download x86_64-unknown-linux-musl.tar.gz
uses: actions/download-artifact@v4
with:
name: rblog-v${{ env.version }}-x86_64-unknown-linux-musl.tar.gz
path: .
- name: Copy rblog binary to docker directory
run: |
tar -xvf rblog-v${{ env.version }}-x86_64-unknown-linux-musl.tar.gz
cp ./rblog ./pkg/docker/rblog
mkdir ./pkg/docker/data
cp ./blog.conf ./pkg/docker/data/
cp -r ./posts ./pkg/docker/data/
- name: Log in to Docker Hub
uses: docker/login-action@v3.2.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push nightly docker image
uses: docker/build-push-action@v6.4.1
with:
context: ./pkg/docker
file: ./pkg/docker/Dockerfile
platforms: linux/amd64
push: ${{ github.ref == 'refs/heads/main' }}
no-cache: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/rblog:nightly
- name: Build and push latest docker image
uses: docker/build-push-action@v6.4.1
if: startsWith(github.ref, 'refs/tags/v')
with:
context: ./pkg/docker
file: ./pkg/docker/Dockerfile
platforms: linux/amd64
push: true
no-cache: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/rblog:${{ github.ref_name }}
${{ secrets.DOCKERHUB_USERNAME }}/rblog:latest
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: prabirshrestha/rblog
publish_aur_package:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs:
- release
steps:
- name: Checkout repository
uses: actions/checkout@v4
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.2
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 }}