Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- **rust/build-library** - Build Rust libraries with flexible profile and feature control
- **rust/lint** - Run cargo fmt and cargo clippy for code quality checks
- **rust/verify-toolchain** - Reusable action to verify Rust toolchain and components are installed
- Verify cargo, rustfmt, clippy, or llvm-tools-preview
- Outputs version information for all verified tools
- Clear, actionable error messages with setup instructions
- Used internally by other Rust actions (lint, build-binary, build-library, generate-sbom)
- **rust/lint** features:
- Configurable fmt and clippy checks (can enable/disable individually)
- Custom clippy arguments and lint levels
- Feature support (all-features, specific features, no-default-features)
Expand All @@ -28,8 +34,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Complete workspace workflow examples in documentation

### Changed
- **rust/setup-rust-build** now includes `rustfmt` and `clippy` components by default
- Ensures all Rust tooling is available for linting and code quality checks
- Added new `components` input parameter for customization (default: `rustfmt, clippy`)
- Users can customize components or set to empty string for minimal installation
- No breaking changes - existing workflows continue to work
- **rust/generate-sbom** now supports Cargo workspaces with `--workspace` and `--package` flags
- **rust/lint**, **rust/build-binary**, **rust/build-library**, and **rust/generate-sbom** now use **rust/verify-toolchain** action
- Provides consistent toolchain verification across all Rust actions
- Reduces code duplication
- Clearer error messages with actionable guidance
- Updated generate-sbom README with workspace examples and best practices
- Updated all Rust action documentation to prioritize `rust/setup-rust-build` over external setup actions

## [1.0.0] - 2025-12-18

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ jobs:

### Rust Ecosystem

> **Note**: All Rust actions require the Rust toolchain to be installed. Use [`rust/setup-rust-build`](rust/setup-rust-build/README.md) or [actions-rust-lang/setup-rust-toolchain](https://github.com/actions-rust-lang/setup-rust-toolchain) before using these actions.

| Action | Description | Documentation |
|--------|-------------|---------------|
| [`rust/cache-cargo`](rust/cache-cargo/README.md) | Cache Cargo registry, index, and build artifacts | [📖 Docs](rust/cache-cargo/README.md) |
| [`rust/setup-rust-build`](rust/setup-rust-build/README.md) | Set up Rust toolchain with cross-compilation support | [📖 Docs](rust/setup-rust-build/README.md) |
| [`rust/verify-toolchain`](rust/verify-toolchain/README.md) | Verify Rust toolchain and required components are installed | [📖 Docs](rust/verify-toolchain/README.md) |
| [`rust/build-binary`](rust/build-binary/README.md) | Build Rust binaries for x86_64 and ARM64 | [📖 Docs](rust/build-binary/README.md) |
| [`rust/build-library`](rust/build-library/README.md) | Build Rust libraries with flexible profile and feature control | [📖 Docs](rust/build-library/README.md) |
| [`rust/lint`](rust/lint/README.md) | Run cargo fmt and cargo clippy for code quality | [📖 Docs](rust/lint/README.md) |
Expand Down Expand Up @@ -299,7 +302,7 @@ These actions are built with the following principles:

| Language | Actions Available | Count |
|----------|-------------------|-------|
| **Rust** | cache-cargo, setup-rust-build, build-binary, build-library, lint, security-scan, generate-sbom | 7 |
| **Rust** | cache-cargo, setup-rust-build, verify-toolchain, build-binary, build-library, lint, security-scan, generate-sbom | 8 |
| **Go** | trivy-scan, cosign-sign, verify-signed-commits, license-check, setup-docker, extract-version | 6 |
| **Python** | trivy-scan, cosign-sign, verify-signed-commits, license-check, setup-docker, extract-version | 6 |
| **Node.js** | trivy-scan, cosign-sign, verify-signed-commits, license-check, setup-docker, extract-version | 6 |
Expand Down
5 changes: 5 additions & 0 deletions rust/build-binary/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ inputs:
runs:
using: composite
steps:
- name: Verify Rust toolchain
uses: firestoned/github-actions/rust/verify-toolchain@main
with:
require-cargo: true

- name: Build (release) - x86_64
if: inputs.target == 'x86_64-unknown-linux-gnu'
shell: bash
Expand Down
5 changes: 5 additions & 0 deletions rust/build-library/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ outputs:
runs:
using: composite
steps:
- name: Verify Rust toolchain
uses: firestoned/github-actions/rust/verify-toolchain@main
with:
require-cargo: true

- name: Determine build command
id: config
shell: bash
Expand Down
5 changes: 5 additions & 0 deletions rust/generate-sbom/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ inputs:
runs:
using: 'composite'
steps:
- name: Verify Rust toolchain
uses: firestoned/github-actions/rust/verify-toolchain@main
with:
require-cargo: true

- name: Cache cargo-cyclonedx
id: cache-cyclonedx
uses: actions/cache@v4
Expand Down
49 changes: 48 additions & 1 deletion rust/lint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

A composite GitHub Action that runs `cargo fmt` and `cargo clippy` to check code formatting and quality for Rust projects.

## Prerequisites

This action requires the Rust toolchain with `rustfmt` and `clippy` components to be installed. Set up Rust before using this action:

```yaml
- uses: firestoned/github-actions/rust/setup-rust-build@v1
```

Alternatively, you can use the community action:

```yaml
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt, clippy
```

## Features

- **Automated Formatting Checks** - Verify code follows Rust style guidelines with `cargo fmt`
Expand All @@ -17,6 +33,9 @@ A composite GitHub Action that runs `cargo fmt` and `cargo clippy` to check code
### Basic Example

```yaml
- name: Setup Rust
uses: firestoned/github-actions/rust/setup-rust-build@v1

- name: Lint Rust code
uses: firestoned/github-actions/rust/lint@v1
```
Expand Down Expand Up @@ -165,6 +184,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Rust
uses: firestoned/github-actions/rust/setup-rust-build@v1

- name: Cache dependencies
uses: firestoned/github-actions/rust/cache-cargo@v1

Expand Down Expand Up @@ -352,13 +374,38 @@ avoid-breaking-exported-api = true

## Troubleshooting

### Rust Toolchain Not Found

**Problem**: Error "Rust toolchain not found"

**Solution**: Add Rust setup before the lint action:
```yaml
- uses: firestoned/github-actions/rust/setup-rust-build@v1

- uses: firestoned/github-actions/rust/lint@v1
```

### rustfmt or clippy Component Missing

**Problem**: Error "rustfmt component not found" or "clippy component not found"

**Solution**: Ensure components are installed. Our setup action includes them by default:
```yaml
- uses: firestoned/github-actions/rust/setup-rust-build@v1
```

Or manually:
```bash
rustup component add rustfmt clippy
```

### Formatting Check Fails

**Problem**: `cargo fmt --check` fails in CI but passes locally

**Solution**: Ensure same Rust version and rustfmt.toml:
```yaml
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: firestoned/github-actions/rust/setup-rust-build@v1
with:
toolchain: stable
components: rustfmt, clippy
Expand Down
7 changes: 7 additions & 0 deletions rust/lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ outputs:
runs:
using: 'composite'
steps:
- name: Verify Rust toolchain
uses: firestoned/github-actions/rust/verify-toolchain@main
with:
require-cargo: true
require-rustfmt: true
require-clippy: true

- name: Check formatting
id: fmt
if: inputs.check-fmt == 'true'
Expand Down
24 changes: 22 additions & 2 deletions rust/setup-rust-build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ A composite GitHub Action that sets up a complete Rust build environment with in
cache-key: my-feature-branch
```

### Custom Components

```yaml
# Minimal setup without linting tools
- name: Setup Rust (build only)
uses: your-org/github-actions/rust/setup-rust-build@v1
with:
target: x86_64-unknown-linux-gnu
components: ''

# Add additional components
- name: Setup Rust with extra tools
uses: your-org/github-actions/rust/setup-rust-build@v1
with:
target: x86_64-unknown-linux-gnu
components: 'rustfmt, clippy, llvm-tools-preview'
```

### Multi-Target Matrix Build

```yaml
Expand Down Expand Up @@ -71,15 +89,17 @@ jobs:
| `target` | Rust target triple (e.g., `x86_64-unknown-linux-gnu`, `aarch64-unknown-linux-gnu`) | Yes | N/A |
| `cache-key` | Additional cache key component for isolating caches by branch or feature | No | `''` |
| `cross-version` | Version of `cross` to install for ARM64 builds (e.g., `v0.2.5`) | No | `v0.2.5` |
| `components` | Comma-separated list of Rust components to install (e.g., `rustfmt, clippy`) | No | `rustfmt, clippy` |

## How It Works

### Standard Builds (x86_64)

1. Installs Rust toolchain using `dtolnay/rust-toolchain@stable`
2. Adds the specified target to the toolchain
3. Caches Rust dependencies using `Swatinem/rust-cache@v2`
4. Uses target and cache-key for cache isolation
3. Installs components (default: `rustfmt, clippy`)
4. Caches Rust dependencies using `Swatinem/rust-cache@v2`
5. Uses target and cache-key for cache isolation

### ARM64 Builds (aarch64)

Expand Down
5 changes: 5 additions & 0 deletions rust/setup-rust-build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ inputs:
description: 'Version of cross to install for ARM64 builds'
required: false
default: 'v0.2.5'
components:
description: 'Comma-separated list of components to install (e.g., rustfmt, clippy)'
required: false
default: 'rustfmt, clippy'

runs:
using: composite
Expand All @@ -29,6 +33,7 @@ runs:
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ inputs.target }}
components: ${{ inputs.components }}

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
Expand Down
Loading
Loading