1- # Rust Build and Test Workflow
1+ # Rust Build Workflow
22
3- A reusable GitHub Actions workflow for building, linting, testing, and auditing Rust packages.
3+ A reusable GitHub Actions workflow for building, linting, testing, and auditing Rust packages, with optional artifact upload and crates.io publishing .
44
55## Features
66
77- Build and test Rust packages
8- - Lint code using clippy
9- - Check formatting with cargo fmt
10- - Run security audits with cargo audit
8+ - Lint code using ` clippy `
9+ - Check formatting with ` cargo fmt `
10+ - Run security audits with ` cargo audit `
1111- Cache dependencies for faster builds
12+ - Upload build artifacts
13+ - Publish to crates.io
1214
1315## Usage
1416
@@ -25,16 +27,31 @@ jobs:
2527 build-profile : ' release'
2628 run-audit : true
2729 enable-cache : true
30+ upload-artifact : true
31+ artifact-name : my-crate
32+ artifact-path : target/release/my-crate
33+ secrets :
34+ CRATES_IO_TOKEN : ${{ secrets.CRATES_IO_TOKEN }}
2835` ` `
2936
3037## Inputs
3138
32- | Name | Description | Default | Required |
33- | --------------- | ---------------------------------------------- | --------- | -------- |
34- | ` rust-version` | Rust version to use | `stable` | No |
35- | `build-profile` | Cargo profile to use (debug, release) | `release` | No |
36- | `run-audit` | Run `cargo audit` for security vulnerabilities | `true` | No |
37- | `enable-cache` | Enable caching of dependencies | `true` | No |
39+ | Name | Description | Default | Required |
40+ | ------------------- | ------------------------------------------------------------ | --------- | -------- |
41+ | ` rust-version` | Rust version to use | `stable` | No |
42+ | `build-profile` | Cargo profile to use for building (`debug`, `release`, etc.) | `release` | No |
43+ | `run-audit` | Run `cargo audit` for security vulnerabilities | `true` | No |
44+ | `enable-cache` | Enable caching of dependencies | `true` | No |
45+ | `upload-artifact` | Upload a build artifact after building | `false` | No |
46+ | `artifact-name` | Name of the artifact to upload | – | No |
47+ | `artifact-path` | Path to the artifact to upload | – | No |
48+ | `publish-crates-io` | Publish the package to crates.io (only if build succeeds) | `false` | No |
49+
50+ # # Secrets
51+
52+ | Name | Description | Required |
53+ | ----------------- | --------------------------------------- | ------------------------------------- |
54+ | `CRATES_IO_TOKEN` | crates.io API token for `cargo publish` | Only if `publish-crates-io` is `true` |
3855
3956# # Examples
4057
6077
6178` ` ` yaml
6279jobs:
63- jobs:
6480 build-and-test:
6581 uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
6682 with:
6783 build-profile: 'debug'
84+ ` ` `
85+
86+ # ## Upload Artifact After Build
87+
88+ ` ` ` yaml
89+ jobs:
90+ build-and-test:
91+ uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
92+ with:
93+ upload-artifact: true
94+ artifact-name: my-crate
95+ artifact-path: target/release/my-crate
96+ ` ` `
97+
98+ # ## Publish to crates.io (requires CRATES_IO_TOKEN)
99+
100+ ` ` ` yaml
101+ jobs:
102+ build-and-test:
103+ uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
104+ with:
105+ publish-crates-io: true
106+ secrets:
107+ CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
68108` ` `
0 commit comments