-
Notifications
You must be signed in to change notification settings - Fork 9
244 lines (208 loc) · 6.94 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
name: Polkadot Staking Miner CI
on:
push:
branches:
- main
tags:
- v*
pull_request:
branches:
- main
env:
IMAGE: paritytech/ci-unified:bullseye-1.81.0-2024-09-11
IMAGE_NAME: paritytech/polkadot-staking-miner
RUST_INFO: rustup show && cargo --version && rustup +nightly show && cargo +nightly --version
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
set-image:
# GitHub Actions does not allow using 'env' in a container context.
# This workaround sets the container image for each job using 'set-image' job output.
runs-on: ubuntu-latest
outputs:
IMAGE: ${{ steps.set_image.outputs.IMAGE }}
steps:
- id: set_image
run: echo "IMAGE=${{ env.IMAGE }}" >> $GITHUB_OUTPUT
check-fmt:
name: Check formatting
runs-on: ubuntu-latest
needs: [set-image]
container: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check formatting
run: |
${{ env.RUST_INFO }}
cargo +nightly fmt --all -- --check
check-clippy:
name: Clippy
runs-on: ubuntu-latest
needs: [set-image]
container: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache Rust dependencies
uses: swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
- name: Run Clippy
run: |
${{ env.RUST_INFO }}
cargo clippy --all-targets
check-docs:
name: Check documentation
runs-on: ubuntu-latest
needs: [set-image]
container: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache Rust dependencies
uses: swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
- name: Check documentation
run: |
${{ env.RUST_INFO }}
RUSTDOCFLAGS="--cfg docsrs --deny rustdoc::broken_intra_doc_links" cargo doc --verbose --workspace --no-deps --document-private-items --all-features
check-cargo-hack:
name: Check code using cargo-hack
runs-on: ubuntu-latest
needs: [set-image]
container: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache Rust dependencies
uses: swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
- name: Check code using cargo-hack
run: |
${{ env.RUST_INFO }}
cargo hack check --workspace --each-feature --all-targets
test:
name: Run tests
runs-on: ubuntu-latest
needs: [set-image]
container: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get Polkadot and Staking Miner Playground binaries
uses: ./.github/workflows/actions/prepare-binaries
- name: Cache Rust dependencies
uses: swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
- name: Run tests on Ubuntu
run: |
${{ env.RUST_INFO }}
RUST_LOG=info cargo +stable test --workspace -- --nocapture
build:
name: Build polkadot-staking-miner binary
runs-on: ubuntu-latest
needs: [set-image]
container: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache Rust dependencies
uses: swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
- name: Build staking-miner
run: |
${{ env.RUST_INFO }}
cargo build --release --locked
- name: Move polkadot-staking-miner binary
run: mv ./target/release/polkadot-staking-miner .
- name: Collect artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifacts
path: |
./polkadot-staking-miner
./Dockerfile
build-docker-image:
name: Test Docker image build
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
needs: [check-fmt,
check-clippy,
check-docs,
check-cargo-hack,
test,
build]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: build-artifacts
path: ./artifacts
- name: Set permissions
run: chmod +x ./artifacts/polkadot-staking-miner
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
uses: docker/build-push-action@v6
with:
push: false
context: ./artifacts
file: ./artifacts/Dockerfile
build-args: |
VCS_REF="${{ github.sha }}"
BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
tags: |
${{ env.IMAGE_NAME }}:test
publish-docker-image:
name: Build and publish Docker image
if: ${{ github.ref == 'refs/heads/main' || github.ref_type == 'tag' }}
runs-on: ubuntu-latest
environment: main_and_tags
needs: [check-fmt,
check-clippy,
check-docs,
check-cargo-hack,
test,
build]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: build-artifacts
path: ./artifacts
- name: Prepare Docker environment
run: |
echo IMAGE_TAG=$(if [ "$GITHUB_REF" == "refs/heads/main" ]; then echo "main-${GITHUB_SHA::7}"; else echo "$GITHUB_REF_NAME"; fi) >> $GITHUB_ENV
echo PUSH_IMAGE=true >> $GITHUB_ENV
echo "Docker image will be published with the tag: ${{ env.IMAGE_TAG }}!"
chmod +x ./artifacts/polkadot-staking-miner
- name: Log in to Docker Hub
if: ${{ github.ref == 'refs/heads/main' || github.ref_type == 'tag' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
push: true
context: ./artifacts
file: ./artifacts/Dockerfile
build-args: |
VCS_REF="${{ github.sha }}"
BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
tags: |
${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
${{ env.IMAGE_NAME }}:latest