-
Notifications
You must be signed in to change notification settings - Fork 4
179 lines (152 loc) · 4.78 KB
/
CI.yaml
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
name: CI
on:
pull_request:
push:
schedule:
- cron: '0 0 * * *' # Run every day at 00:00 UTC.
env:
RUST_BACKTRACE: full # Shows more info when a test fails.
BINARY_NAME: tindercrypt
jobs:
basic_checks:
name: Basic checks (cargo ${{ matrix.cmd }})
runs-on: ubuntu-latest
strategy:
matrix:
cmd:
- fmt
- doc
include:
- cmd: fmt
args: --all -- --check
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt
- name: cargo ${{ matrix.cmd }}
run: cargo ${{ matrix.cmd }} ${{ matrix.args }}
lint_proto:
name: Lint .proto files
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Uber's prototool
run: |
wget -O prototool \
https://github.com/uber/prototool/releases/download/v1.9.0/prototool-Linux-x86_64
chmod +x prototool
- name: Lint
run: ./prototool lint proto
test:
name: Test ${{ matrix.rust }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
rust:
- stable
- beta
- nightly
os:
- ubuntu-latest
- windows-latest
- macOS-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust (${{ matrix.rust }})
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
# Catch any breaking changes in the dependencies early, by always updating
# them before running the tests.
- name: Update dependencies
run: cargo update
# Regenerate proto module with new dependencies. Else, they may not work
# if the protobuf library gets updated in the previous step.
- name: Generate Rust code from Protobuf definitions
run: cargo build --features proto-gen
- name: Test
run: cargo test -- --nocapture # Allow printing the output of tests
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macOS-latest
include:
- os: ubuntu-latest
arch: linux_amd64
- os: windows-latest
arch: windows_amd64
extension: .exe
- os: macOS-latest
arch: darwin_amd64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build
run: cargo build --release
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: ${{ env.BINARY_NAME }}_${{ matrix.arch }}${{ matrix.extension}}
path: "target/release/${{ env.BINARY_NAME }}${{ matrix.extension }}"
create_release:
name: Create a release
runs-on: ubuntu-latest
needs: ["basic_checks", "test", "build", "lint_proto"]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set release tag
run: echo GITHUB_RELEASE_TAG=${GITHUB_REF#refs/tags/} >> $GITHUB_ENV
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create ${{ env.GITHUB_RELEASE_TAG }} \
--title "Release ${{ env.GITHUB_RELEASE_TAG }}" \
--draft --generate-notes
upload_assets:
name: Upload release assets ( ${{ matrix.arch }} )
needs: create_release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
strategy:
matrix:
arch:
- linux_amd64
- windows_amd64
- darwin_amd64
include:
- arch: windows_amd64
extension: .exe
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set release tag
run: echo GITHUB_RELEASE_TAG=${GITHUB_REF#refs/tags/} >> $GITHUB_ENV
- name: Download binary
uses: actions/download-artifact@v4
with:
name: ${{ env.BINARY_NAME }}_${{ matrix.arch }}${{ matrix.extension}}
path: assets_${{ matrix.arch }}
- name: Upload release asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd assets_${{ matrix.arch }}
TAGGED_ASSET_NAME=${{ env.BINARY_NAME }}_${{ env.GITHUB_RELEASE_TAG }}_${{ matrix.arch }}${{ matrix.extension}}
mv ${{ env.BINARY_NAME }}${{ matrix.extension }} ${TAGGED_ASSET_NAME}
gh release upload ${{ env.GITHUB_RELEASE_TAG }} ${TAGGED_ASSET_NAME}