11# Rust Build Workflow
22
3- A reusable GitHub Actions workflow for building, testing, and publishing Rust packages.
3+ A reusable GitHub Actions workflow for building, linting, testing, and publishing Rust packages, with optional dependency caching and working directory support .
44
55## Features
66
77- Build and test Rust packages
8+ - Lint code using ` clippy `
9+ - Check formatting with ` cargo fmt `
810- Cache dependencies for faster builds
9- - Publish packages to crates.io
10- - Upload build artifacts
11+ - Set a working directory (for monorepos or nested crates)
12+ - Publish to crates.io
1113
1214## Usage
1315
@@ -21,30 +23,29 @@ jobs:
2123 uses : iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
2224 with :
2325 rust-version : ' stable'
24- build-target : ' release '
26+ working-directory : ' ./my-crate '
2527 enable-cache : true
26- upload-artifact : true
27- artifact-name : ' my-rust-app '
28- artifact-path : ' target/release/my-app '
28+ publish-crates-io : false
29+ secrets :
30+ CARGO_REGISTRY_TOKEN : ${{ secrets.CARGO_REGISTRY_TOKEN }}
2931` ` `
3032
3133## Inputs
3234
33- | Name | Description | Default | Required |
34- |---------------------|----------------------------------------------------|-----------|-------------------------------------|
35- | ` rust-version` | Rust version to use | `stable` | No |
36- | `build-target` | Cargo profile to use for building (debug, release) | `release` | No |
37- | `enable-cache` | Enable caching of dependencies | `true` | No |
38- | `publish-crates-io` | Publish package to crates.io | `false` | No |
39- | `upload-artifact` | Upload build artifact | `false` | No |
40- | `artifact-name` | Name of the artifact to upload | - | Only if `upload-artifact` is `true` |
41- | `artifact-path` | Path to the artifact to upload | - | Only if `upload-artifact` is `true` |
35+ | Name | Description | Default | Required |
36+ | ------------------- | --------------------------------------------------------- | -------- | -------- |
37+ | ` rust-version` | Rust version to use | `stable` | No |
38+ | `working-directory` | The directory to run jobs from | `.` | No |
39+ | `enable-cache` | Enable caching of dependencies | `true` | No |
40+ | `publish-crates-io` | Publish the package to crates.io (only if build succeeds) | `false` | No |
41+
42+ Note : All builds use the release profile by default. There is no build-target input anymore
4243
4344# # Secrets
4445
45- | Name | Description | Required |
46- |-------------------| -----------------------------------| ---------------------------------------|
47- | `CRATES_IO_TOKEN ` | Token for publishing to crates.io | Only if `publish-crates-io` is `true` |
46+ | Name | Description | Required |
47+ | ---------------------- | --------------------------------------- | ------------------------------------- |
48+ | `CARGO_REGISTRY_TOKEN ` | crates.io API token for `cargo publish` | Only if `publish-crates-io` is `true` |
4849
4950# # Examples
5051
@@ -56,19 +57,17 @@ jobs:
5657 uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
5758` ` `
5859
59- # ## Build, Test, and Upload Artifact
60+ # ## Specify a Working Directory
6061
6162` ` ` yaml
6263jobs:
6364 build-and-test:
6465 uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
6566 with:
66- upload-artifact: true
67- artifact-name: 'my-rust-app'
68- artifact-path: 'target/release/my-app'
67+ working-directory: './my-crate'
6968` ` `
7069
71- # ## Build, Test, and Publish to crates.io
70+ # ## Publish to crates.io (requires CARGO_REGISTRY_TOKEN)
7271
7372` ` ` yaml
7473jobs:
7776 with:
7877 publish-crates-io: true
7978 secrets:
80- CRATES_IO_TOKEN : ${{ secrets.CRATES_IO_TOKEN }}
79+ CARGO_REGISTRY_TOKEN : ${{ secrets.CARGO_REGISTRY_TOKEN }}
8180` ` `
0 commit comments