Repository navigation
96 lines (83 loc) · 3.08 KB
/
Copy pathrust-build.yml
File metadata and controls
96 lines (83 loc) · 3.08 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@02cb101ec7c40f2c49e1d9714d64511d8e1b74de # @master 2026-09-12 (action has no version tags)
with:
toolchain: ${{ inputs.rust-version }}
components: clippy, rustfmt
- name: Enable Socket Firewall
uses: SocketDev/action@be1f253a41351d59095f8d7f1425985097dd1054 # unreleased: post-v1.3.2, includes sfw shims
with:
mode: firewall-free
shims: true
# https://github.com/actions/cache/blob/main/examples.md#rust---cargo
- name: Cache dependencies
if: ${{ inputs.enable-cache }}
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- 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 --locked --all-targets -- -D warnings
- name: Build
working-directory: ${{ inputs.working-directory }}
run: cargo build --locked --release
- name: Run tests
working-directory: ${{ inputs.working-directory }}
run: cargo test --locked --release
- name: Check documentation
working-directory: ${{ inputs.working-directory }}
env:
RUSTDOCFLAGS: "-D warnings"
run: cargo doc --locked --no-deps --document-private-items
- name: Validate package
if: ${{ inputs.publish-crates-io }}
working-directory: ${{ inputs.working-directory }}
run: cargo package --locked
- name: Publish to crates.io
if: ${{ inputs.publish-crates-io }}
working-directory: ${{ inputs.working-directory }}
run: cargo publish --locked # zizmor: ignore[use-trusted-publishing] TODO fix this if you need to publish on crates.io