|
| 1 | +# Rust Build Workflow |
| 2 | + |
| 3 | +A reusable GitHub Actions workflow for building, testing, and publishing Rust packages. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Build and test Rust packages |
| 8 | +- Cache dependencies for faster builds |
| 9 | +- Publish packages to crates.io |
| 10 | +- Upload build artifacts |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +```yaml |
| 15 | +name: Rust CI |
| 16 | + |
| 17 | +on: |
| 18 | + push: |
| 19 | + branches: [ main ] |
| 20 | + pull_request: |
| 21 | + branches: [ main ] |
| 22 | + |
| 23 | +jobs: |
| 24 | + build-and-test: |
| 25 | + uses: your-org/github-actions-workflows/.github/workflows/rust-build.yml@main |
| 26 | + with: |
| 27 | + rust-version: 'stable' |
| 28 | + build-target: 'release' |
| 29 | + enable-cache: true |
| 30 | + upload-artifact: true |
| 31 | + artifact-name: 'my-rust-app' |
| 32 | + artifact-path: 'target/release/my-app' |
| 33 | + secrets: |
| 34 | + CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} |
| 35 | +``` |
| 36 | +
|
| 37 | +## Inputs |
| 38 | +
|
| 39 | +| Name | Description | Default | Required | |
| 40 | +|---------------------|----------------------------------------------------|-----------|-------------------------------------| |
| 41 | +| `rust-version` | Rust version to use | `stable` | No | |
| 42 | +| `build-target` | Cargo profile to use for building (debug, release) | `release` | No | |
| 43 | +| `enable-cache` | Enable caching of dependencies | `true` | No | |
| 44 | +| `publish-crates-io` | Publish package to crates.io | `false` | No | |
| 45 | +| `upload-artifact` | Upload build artifact | `false` | No | |
| 46 | +| `artifact-name` | Name of the artifact to upload | - | Only if `upload-artifact` is `true` | |
| 47 | +| `artifact-path` | Path to the artifact to upload | - | Only if `upload-artifact` is `true` | |
| 48 | + |
| 49 | +## Secrets |
| 50 | + |
| 51 | +| Name | Description | Required | |
| 52 | +|-------------------|-----------------------------------|---------------------------------------| |
| 53 | +| `CRATES_IO_TOKEN` | Token for publishing to crates.io | Only if `publish-crates-io` is `true` | |
| 54 | + |
| 55 | +## Examples |
| 56 | + |
| 57 | +### Basic Build and Test |
| 58 | + |
| 59 | +```yaml |
| 60 | +jobs: |
| 61 | + build-and-test: |
| 62 | + uses: your-org/github-actions-workflows/.github/workflows/rust-build.yml@main |
| 63 | +``` |
| 64 | + |
| 65 | +### Build, Test, and Upload Artifact |
| 66 | + |
| 67 | +```yaml |
| 68 | +jobs: |
| 69 | + build-and-test: |
| 70 | + uses: your-org/github-actions-workflows/.github/workflows/rust-build.yml@main |
| 71 | + with: |
| 72 | + upload-artifact: true |
| 73 | + artifact-name: 'my-rust-app' |
| 74 | + artifact-path: 'target/release/my-app' |
| 75 | +``` |
| 76 | + |
| 77 | +### Build, Test, and Publish to crates.io |
| 78 | + |
| 79 | +```yaml |
| 80 | +jobs: |
| 81 | + build-and-publish: |
| 82 | + uses: your-org/github-actions-workflows/.github/workflows/rust-build.yml@main |
| 83 | + with: |
| 84 | + publish-crates-io: true |
| 85 | + secrets: |
| 86 | + CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} |
| 87 | +``` |
0 commit comments