Skip to content

Commit 1704cef

Browse files
refactor: unify Rust build and publish into single job
1 parent 32ddee3 commit 1704cef

File tree

2 files changed

+22
-47
lines changed

2 files changed

+22
-47
lines changed

.github/workflows/rust-build.yml

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ on:
77
description: 'Rust version to use'
88
default: 'stable'
99
type: string
10-
build-target:
11-
description: 'Cargo profile to use for building (debug, release)'
12-
default: 'release'
13-
type: string
1410
working-directory:
1511
description: 'The directory to run jobs from'
1612
default: '.'
@@ -48,7 +44,7 @@ env:
4844
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
4945

5046
jobs:
51-
build:
47+
build_and_publish:
5248
runs-on: ubuntu-latest
5349
steps:
5450
- name: Checkout repository
@@ -58,7 +54,7 @@ jobs:
5854
uses: dtolnay/rust-toolchain@stable
5955
with:
6056
toolchain: ${{ inputs.rust-version }}
61-
components: clippy, rustfmt
57+
components: clippy, rustfmt, cargo
6258

6359
- name: Cache dependencies
6460
if: ${{ inputs.enable-cache }}
@@ -69,9 +65,9 @@ jobs:
6965
~/.cargo/registry
7066
~/.cargo/git
7167
target
72-
key: ${{ runner.os }}-cargo-${{ inputs.build-target }}-${{ hashFiles('**/Cargo.lock') }}
68+
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
7369
restore-keys: |
74-
${{ runner.os }}-cargo-${{ inputs.build-target }}-
70+
${{ runner.os }}-cargo-release-
7571
7672
- name: Check formatting
7773
working-directory: ${{ inputs.working-directory }}
@@ -92,11 +88,11 @@ jobs:
9288

9389
- name: Build
9490
working-directory: ${{ inputs.working-directory }}
95-
run: cargo build --profile ${{ inputs.build-target }}
91+
run: cargo build --release
9692

9793
- name: Run tests
9894
working-directory: ${{ inputs.working-directory }}
99-
run: cargo test --profile ${{ inputs.build-target }}
95+
run: cargo test --release
10096

10197
- name: Upload artifact
10298
if: ${{ inputs.upload-artifact }}
@@ -105,24 +101,12 @@ jobs:
105101
name: ${{ inputs.artifact-name }}
106102
path: ${{ inputs.artifact-path }}
107103

108-
publish:
109-
needs: build
110-
if: ${{ inputs.publish-crates-io && needs.build.result == 'success' }}
111-
runs-on: ubuntu-latest
112-
steps:
113-
- name: Checkout repository
114-
uses: actions/checkout@v4
115-
116-
- name: Install Rust toolchain
117-
uses: dtolnay/rust-toolchain@stable
118-
with:
119-
toolchain: ${{ inputs.rust-version }}
120-
components: cargo
121-
122104
- name: Validate package
105+
if: ${{ inputs.publish-crates-io }}
123106
working-directory: ${{ inputs.working-directory }}
124107
run: cargo package
125108

126109
- name: Publish to crates.io
110+
if: ${{ inputs.publish-crates-io }}
127111
working-directory: ${{ inputs.working-directory }}
128112
run: cargo publish

rust-build/README.md

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ A reusable GitHub Actions workflow for building, linting, testing, and auditing
1212
- Set a working directory for monorepos
1313
- Upload build artifacts
1414
- Publish to crates.io
15+
- All operations are performed in a single job (no redundant toolchain installs)
1516

1617
## Usage
1718

@@ -25,7 +26,6 @@ jobs:
2526
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
2627
with:
2728
rust-version: 'stable'
28-
build-target: 'release'
2929
working-directory: './my-crate'
3030
run-audit: true
3131
enable-cache: true
@@ -38,22 +38,23 @@ jobs:
3838
3939
## Inputs
4040
41-
| Name | Description | Default | Required |
42-
| ------------------- | ------------------------------------------------------------ | --------- | -------- |
43-
| `rust-version` | Rust version to use | `stable` | No |
44-
| `build-target` | Cargo profile to use for building (`debug`, `release`, etc.) | `release` | No |
45-
| `working-directory` | The directory to run jobs from | `.` | No |
46-
| `run-audit` | Run `cargo audit` for security vulnerabilities | `true` | No |
47-
| `enable-cache` | Enable caching of dependencies | `true` | No |
48-
| `upload-artifact` | Upload a build artifact after building | `false` | No |
49-
| `artifact-name` | Name of the artifact to upload | – | No |
50-
| `artifact-path` | Path to the artifact to upload | – | No |
51-
| `publish-crates-io` | Publish the package to crates.io (only if build succeeds) | `false` | No |
41+
| Name | Description | Default | Required |
42+
| ------------------- | --------------------------------------------------------- | -------- | -------- |
43+
| `rust-version` | Rust version to use | `stable` | No |
44+
| `working-directory` | The directory to run jobs from | `.` | No |
45+
| `run-audit` | Run `cargo audit` for security vulnerabilities | `true` | No |
46+
| `enable-cache` | Enable caching of dependencies | `true` | No |
47+
| `upload-artifact` | Upload a build artifact after building | `false` | No |
48+
| `artifact-name` | Name of the artifact to upload | – | No |
49+
| `artifact-path` | Path to the artifact to upload | – | No |
50+
| `publish-crates-io` | Publish the package to crates.io (only if build succeeds) | `false` | No |
51+
52+
Note: All builds use the release profile by default. There is no build-target input anymore
5253

5354
## Secrets
5455

5556
| Name | Description | Required |
56-
| -----------------------| --------------------------------------- | ------------------------------------- |
57+
| ---------------------- | --------------------------------------- | ------------------------------------- |
5758
| `CARGO_REGISTRY_TOKEN` | crates.io API token for `cargo publish` | Only if `publish-crates-io` is `true` |
5859

5960
## Examples
@@ -86,16 +87,6 @@ jobs:
8687
run-audit: false
8788
```
8889

89-
### Use Debug Target
90-
91-
```yaml
92-
jobs:
93-
build-and-test:
94-
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/rust-build.yml@main
95-
with:
96-
build-target: 'debug'
97-
```
98-
9990
### Upload Artifact After Build
10091

10192
```yaml

0 commit comments

Comments
 (0)