Skip to content

Commit 8ea3461

Browse files
refactor(rust-build): remove publish, add lint and audit steps
1 parent 08eb8a4 commit 8ea3461

File tree

2 files changed

+53
-97
lines changed

2 files changed

+53
-97
lines changed

.github/workflows/rust-build.yml

Lines changed: 34 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build, Test and Publish Rust Package
1+
name: Build and Test Rust Package
22

33
on:
44
workflow_call:
@@ -7,97 +7,66 @@ on:
77
description: 'Rust version to use'
88
default: 'stable'
99
type: string
10-
build-target:
10+
build-profile:
1111
description: 'Cargo profile to use for building (debug, release)'
1212
default: 'release'
1313
type: string
14+
run-audit:
15+
description: 'Run cargo-audit for security vulnerabilities'
16+
default: true
17+
type: boolean
1418
enable-cache:
1519
description: 'Enable caching of dependencies'
1620
default: true
1721
type: boolean
18-
publish-crates-io:
19-
description: 'Publish package to crates.io'
20-
default: false
21-
type: boolean
22-
upload-artifact:
23-
description: 'Upload build artifact'
24-
default: false
25-
type: boolean
26-
artifact-name:
27-
description: 'Name of the artifact to upload'
28-
type: string
29-
required: false
30-
artifact-path:
31-
description: 'Path to the artifact to upload'
32-
type: string
33-
required: false
34-
secrets:
35-
CRATES_IO_TOKEN:
36-
required: false
3722

23+
env:
24+
CARGO_TERM_COLOR: always
25+
3826
jobs:
39-
build:
27+
build-and-test:
28+
name: Build & Test
4029
runs-on: ubuntu-latest
41-
outputs:
42-
build_success: ${{ steps.set-output.outputs.build_success }}
4330
steps:
4431
- name: Checkout repository
4532
uses: actions/checkout@v4
4633

4734
- name: Install Rust toolchain
48-
uses: actions-rs/toolchain@v1
35+
uses: dtolnay/rust-toolchain@stable
4936
with:
50-
profile: minimal
5137
toolchain: ${{ inputs.rust-version }}
52-
override: true
38+
components: clippy
5339

5440
- name: Cache dependencies
5541
if: ${{ inputs.enable-cache }}
5642
uses: actions/cache@v4
5743
with:
5844
path: |
59-
~/.cargo/registry
45+
~/.cargo/bin/
46+
~/.cargo/registry/index/
47+
~/.cargo/registry/cache/
6048
~/.cargo/git
6149
target
62-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
63-
64-
- name: Build
65-
run: cargo build --profile ${{ inputs.build-target }}
66-
67-
- name: Run tests
68-
run: cargo test --profile ${{ inputs.build-target }}
69-
70-
- name: Set build success output
71-
id: set-output
72-
run: echo "build_success=true" >> $GITHUB_OUTPUT
50+
key: ${{ runner.os }}-cargo-${{ inputs.build-profile }}-${{ hashFiles('**/Cargo.lock') }}
51+
restore-keys: |
52+
${{ runner.os }}-cargo-${{ inputs.build-profile }}-
7353
74-
- name: Upload artifact
75-
if: ${{ inputs.upload-artifact }}
76-
uses: actions/upload-artifact@v4
77-
with:
78-
name: ${{ inputs.artifact-name }}
79-
path: ${{ inputs.artifact-path }}
54+
- name: Check formatting
55+
run: cargo fmt --all -- --check
8056

81-
publish:
82-
needs: build
83-
if: ${{ inputs.publish-crates-io && needs.build.outputs.build_success == 'true' }}
84-
runs-on: ubuntu-latest
85-
steps:
86-
- name: Checkout repository
87-
uses: actions/checkout@v4
57+
- name: Run linter (Clippy)
58+
run: cargo clippy --all-targets -- -D warnings
59+
60+
- name: Install cargo-audit
61+
if: ${{ inputs.run-audit }}
62+
run: cargo install cargo-audit
8863

89-
- name: Install Rust toolchain
90-
uses: actions-rs/toolchain@v1
91-
with:
92-
profile: minimal
93-
toolchain: ${{ inputs.rust-version }}
94-
override: true
95-
96-
- name: Login to crates.io
97-
run: cargo login ${{ secrets.CRATES_IO_TOKEN }}
64+
- name: Run security audit
65+
if: ${{ inputs.run-audit }}
66+
run: cargo audit
9867

99-
- name: Package for crates.io
100-
run: cargo package
68+
- name: Build
69+
run: cargo build --profile ${{ inputs.build-profile }}
10170

102-
- name: Publish to crates.io
103-
run: cargo publish
71+
- name: Run tests
72+
run: cargo test --profile ${{ inputs.build-profile }}

rust-build/README.md

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
# Rust Build Workflow
1+
# Rust Build and Test 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 auditing Rust packages.
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
811
- Cache dependencies for faster builds
9-
- Publish packages to crates.io
10-
- Upload build artifacts
1112

1213
## Usage
1314

@@ -21,30 +22,19 @@ jobs:
2122
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
2223
with:
2324
rust-version: 'stable'
24-
build-target: 'release'
25+
build-profile: 'release'
26+
run-audit: true
2527
enable-cache: true
26-
upload-artifact: true
27-
artifact-name: 'my-rust-app'
28-
artifact-path: 'target/release/my-app'
2928
```
3029
3130
## Inputs
3231
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` |
42-
43-
## Secrets
44-
45-
| Name | Description | Required |
46-
|-------------------|-----------------------------------|---------------------------------------|
47-
| `CRATES_IO_TOKEN` | Token for publishing to crates.io | Only if `publish-crates-io` is `true` |
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 |
4838

4939
## Examples
5040

@@ -56,26 +46,23 @@ jobs:
5646
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
5747
```
5848

59-
### Build, Test, and Upload Artifact
49+
### Disable Security Audit
6050

6151
```yaml
6252
jobs:
6353
build-and-test:
6454
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
6555
with:
66-
upload-artifact: true
67-
artifact-name: 'my-rust-app'
68-
artifact-path: 'target/release/my-app'
56+
run-audit: false
6957
```
7058

71-
### Build, Test, and Publish to crates.io
59+
### Use Debug Profile
7260

7361
```yaml
7462
jobs:
75-
build-and-publish:
63+
jobs:
64+
build-and-test:
7665
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
7766
with:
78-
publish-crates-io: true
79-
secrets:
80-
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
67+
build-profile: 'debug'
8168
```

0 commit comments

Comments
 (0)