-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (69 loc) · 2.2 KB
/
rust-build.yml
File metadata and controls
80 lines (69 loc) · 2.2 KB
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
name: Build, Test and Publish Rust Package
on:
workflow_call:
inputs:
rust-version:
description: 'Rust version to use'
default: 'stable'
type: string
working-directory:
description: 'The directory to run jobs from'
default: '.'
type: string
enable-cache:
description: 'Enable caching of dependencies'
default: true
type: boolean
publish-crates-io:
description: 'Publish package to crates.io'
default: false
type: boolean
secrets:
CARGO_REGISTRY_TOKEN:
required: false
env:
CARGO_TERM_COLOR: always
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
jobs:
build_and_publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ inputs.rust-version }}
components: clippy, rustfmt
- name: Cache dependencies
if: ${{ inputs.enable-cache }}
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-release-
- name: Check formatting
working-directory: ${{ inputs.working-directory }}
run: cargo fmt --all -- --check
- name: Run linter (Clippy)
working-directory: ${{ inputs.working-directory }}
run: cargo clippy --all-targets -- -D warnings
- name: Build
working-directory: ${{ inputs.working-directory }}
run: cargo build --release
- name: Run tests
working-directory: ${{ inputs.working-directory }}
run: cargo test --release
- name: Validate package
if: ${{ inputs.publish-crates-io }}
working-directory: ${{ inputs.working-directory }}
run: cargo package
- name: Publish to crates.io
if: ${{ inputs.publish-crates-io }}
working-directory: ${{ inputs.working-directory }}
run: cargo publish