Skip to content

Commit 1050416

Browse files
Revert "refactor: simplify rust workflow and update README"
This reverts commit 85ee789.
1 parent 320df78 commit 1050416

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

.github/workflows/rust-build.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
description: 'The directory to run jobs from'
88
default: '.'
99
type: string
10+
run-audit:
11+
description: 'Run cargo-audit for security vulnerabilities'
12+
default: true
13+
type: boolean
1014
enable-cache:
1115
description: 'Enable caching of dependencies'
1216
default: true
@@ -15,6 +19,18 @@ on:
1519
description: 'Publish package to crates.io'
1620
default: false
1721
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
1834
secrets:
1935
CARGO_REGISTRY_TOKEN:
2036
required: false
@@ -53,6 +69,15 @@ jobs:
5369
- name: Run linter (Clippy)
5470
working-directory: ${{ inputs.working-directory }}
5571
run: cargo clippy --all-targets -- -D warnings
72+
73+
- name: Install cargo-audit
74+
if: ${{ inputs.run-audit }}
75+
run: cargo install cargo-audit
76+
77+
- name: Run security audit
78+
if: ${{ inputs.run-audit }}
79+
working-directory: ${{ inputs.working-directory }}
80+
run: cargo audit
5681

5782
- name: Build
5883
working-directory: ${{ inputs.working-directory }}
@@ -62,6 +87,13 @@ jobs:
6287
working-directory: ${{ inputs.working-directory }}
6388
run: cargo test --release
6489

90+
- name: Upload artifact
91+
if: ${{ inputs.upload-artifact }}
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: ${{ inputs.artifact-name }}
95+
path: ${{ inputs.artifact-path }}
96+
6597
- name: Validate package
6698
if: ${{ inputs.publish-crates-io }}
6799
working-directory: ${{ inputs.working-directory }}

rust-build/README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
# Rust Build Workflow
22

3-
A reusable GitHub Actions workflow for building, linting, testing, and publishing Rust packages, with optional dependency caching and working directory support.
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
88
- Lint code using `clippy`
99
- Check formatting with `cargo fmt`
10+
- Run security audits with `cargo audit`
1011
- Cache dependencies for faster builds
11-
- Set a working directory (for monorepos or nested crates)
12+
- Set a working directory for monorepos
13+
- Upload build artifacts
1214
- Publish to crates.io
15+
- All operations are performed in a single job (no redundant toolchain installs)
1316

1417
## Usage
1518

@@ -23,8 +26,11 @@ jobs:
2326
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
2427
with:
2528
working-directory: './my-crate'
29+
run-audit: true
2630
enable-cache: true
27-
publish-crates-io: false
31+
upload-artifact: true
32+
artifact-name: my-crate
33+
artifact-path: target/release/my-crate
2834
secrets:
2935
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
3036
```
@@ -34,7 +40,11 @@ jobs:
3440
| Name | Description | Default | Required |
3541
| ------------------- | --------------------------------------------------------- | -------- | -------- |
3642
| `working-directory` | The directory to run jobs from | `.` | No |
43+
| `run-audit` | Run `cargo audit` for security vulnerabilities | `true` | No |
3744
| `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 |
3848
| `publish-crates-io` | Publish the package to crates.io (only if build succeeds) | `false` | No |
3949

4050
Note: All builds use the release profile by default. There is no build-target input anymore
@@ -65,6 +75,28 @@ jobs:
6575
working-directory: './my-crate'
6676
```
6777

78+
### Disable Security Audit
79+
80+
```yaml
81+
jobs:
82+
build-and-test:
83+
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
84+
with:
85+
run-audit: false
86+
```
87+
88+
### Upload Artifact After Build
89+
90+
```yaml
91+
jobs:
92+
build-and-upload:
93+
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
94+
with:
95+
upload-artifact: true
96+
artifact-name: my-crate
97+
artifact-path: target/release/my-crate
98+
```
99+
68100
### Publish to crates.io (requires CARGO_REGISTRY_TOKEN)
69101

70102
```yaml

0 commit comments

Comments
 (0)