-
-
Notifications
You must be signed in to change notification settings - Fork 0
chore(ci): reuse cargo commands via composite actions #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
RAprogramm
merged 1 commit into
main
from
eye-of-ra/create-composite-actions-for-ci-commands
Sep 30, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| name: "Cargo audit" | ||
| description: "Ensure cargo-audit is installed and run it with consistent flags" | ||
| inputs: | ||
| version: | ||
| description: "cargo-audit crate version to install (leave empty for latest)" | ||
| required: false | ||
| default: "" | ||
| deny-warnings: | ||
| description: "Whether to pass --deny warnings" | ||
| required: false | ||
| default: "true" | ||
| extra-args: | ||
| description: "Additional arguments passed to cargo audit" | ||
| required: false | ||
| default: "" | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Ensure cargo-audit | ||
| shell: bash | ||
| env: | ||
| VERSION: ${{ inputs.version }} | ||
| run: | | ||
| set -euo pipefail | ||
| desired_version="${VERSION}" | ||
| if command -v cargo-audit >/dev/null 2>&1; then | ||
| if [ -n "${desired_version}" ]; then | ||
| current_version="$(cargo-audit --version | awk '{print $2}')" | ||
| if [ "${current_version}" = "${desired_version}" ]; then | ||
| exit 0 | ||
| fi | ||
| else | ||
| exit 0 | ||
| fi | ||
| fi | ||
| if [ -n "${desired_version}" ]; then | ||
| cargo install cargo-audit --locked --force --version "${desired_version}" | ||
| else | ||
| cargo install cargo-audit --locked --force | ||
| fi | ||
| - name: Run cargo audit | ||
| shell: bash | ||
| env: | ||
| DENY_WARNINGS: ${{ inputs.deny-warnings }} | ||
| EXTRA_ARGS: ${{ inputs.extra-args }} | ||
| run: | | ||
| set -euo pipefail | ||
| args=() | ||
| if [ "${DENY_WARNINGS}" = "true" ]; then | ||
| args+=("--deny" "warnings") | ||
| fi | ||
| if [ -n "${EXTRA_ARGS}" ]; then | ||
| # shellcheck disable=SC2206 | ||
| extra_parts=(${EXTRA_ARGS}) | ||
| args+=("${extra_parts[@]}") | ||
| fi | ||
| cargo audit "${args[@]}" | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: "Cargo clippy" | ||
| description: "Run cargo clippy with workspace defaults and optional all-features" | ||
| inputs: | ||
| toolchain: | ||
| description: "Rust toolchain identifier to use (without the leading +)" | ||
| required: true | ||
| all-features: | ||
| description: "Whether to enable --all-features" | ||
| required: false | ||
| default: "false" | ||
| extra-args: | ||
| description: "Additional arguments passed to cargo clippy" | ||
| required: false | ||
| default: "" | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Run cargo clippy | ||
| shell: bash | ||
| env: | ||
| TOOLCHAIN: ${{ inputs.toolchain }} | ||
| ALL_FEATURES: ${{ inputs.all-features }} | ||
| EXTRA_ARGS: ${{ inputs.extra-args }} | ||
| run: | | ||
| set -euo pipefail | ||
| if [ "${ALL_FEATURES}" = "true" ]; then | ||
| cargo +"${TOOLCHAIN}" clippy --workspace --all-targets --all-features ${EXTRA_ARGS} -- -D warnings | ||
| else | ||
| cargo +"${TOOLCHAIN}" clippy --workspace --all-targets ${EXTRA_ARGS} -- -D warnings | ||
| fi | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| name: "Cargo fmt check" | ||
| description: "Run cargo fmt in check mode using the provided toolchain" | ||
| inputs: | ||
| toolchain: | ||
| description: "Rust toolchain identifier to use (without the leading +)" | ||
| required: false | ||
| default: "nightly" | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Run cargo fmt | ||
| shell: bash | ||
| env: | ||
| TOOLCHAIN: ${{ inputs.toolchain }} | ||
| run: | | ||
| set -euo pipefail | ||
| cargo +"${TOOLCHAIN}" fmt --all -- --check | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: "Cargo test" | ||
| description: "Run cargo test for the workspace with consistent flags" | ||
| inputs: | ||
| toolchain: | ||
| description: "Rust toolchain identifier to use (without the leading +)" | ||
| required: true | ||
| all-features: | ||
| description: "Whether to enable --all-features" | ||
| required: false | ||
| default: "false" | ||
| no-fail-fast: | ||
| description: "Whether to include --no-fail-fast" | ||
| required: false | ||
| default: "true" | ||
| extra-args: | ||
| description: "Additional arguments passed to cargo test" | ||
| required: false | ||
| default: "" | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Run cargo test | ||
| shell: bash | ||
| env: | ||
| TOOLCHAIN: ${{ inputs.toolchain }} | ||
| ALL_FEATURES: ${{ inputs.all-features }} | ||
| NO_FAIL_FAST: ${{ inputs.no-fail-fast }} | ||
| EXTRA_ARGS: ${{ inputs.extra-args }} | ||
| run: | | ||
| set -euo pipefail | ||
| args=("--workspace") | ||
| if [ "${ALL_FEATURES}" = "true" ]; then | ||
| args+=("--all-features") | ||
| fi | ||
| if [ "${NO_FAIL_FAST}" = "true" ]; then | ||
| args+=("--no-fail-fast") | ||
| fi | ||
| if [ -n "${EXTRA_ARGS}" ]; then | ||
| # shellcheck disable=SC2206 | ||
| extra_parts=(${EXTRA_ARGS}) | ||
| args+=("${extra_parts[@]}") | ||
| fi | ||
| cargo +"${TOOLCHAIN}" test "${args[@]}" | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Continuous integration recipes | ||
|
|
||
| The workspace exposes reusable GitHub composite actions so multiple workflows can | ||
| share the same cargo setup without copying command bodies. Each composite lives | ||
| under [`.github/actions`](../../.github/actions) and assumes the caller already | ||
| prepared the toolchain, caches, and workspace checkout. | ||
|
|
||
| ## Available composites | ||
|
|
||
| | Action | Purpose | Required inputs | | ||
| | ------ | ------- | ---------------- | | ||
| | `./.github/actions/cargo-fmt` | Runs `cargo fmt -- --check` with the requested toolchain. | `toolchain` (defaults to `nightly`). | | ||
| | `./.github/actions/cargo-clippy` | Executes `cargo clippy --workspace --all-targets`, optionally enabling `--all-features`. | `toolchain` (MSRV or other installed toolchain). | | ||
| | `./.github/actions/cargo-test` | Executes `cargo test --workspace` with optional `--all-features` and `--no-fail-fast`. | `toolchain` (MSRV or other installed toolchain). | | ||
| | `./.github/actions/cargo-audit` | Installs (if required) and runs `cargo audit` with `--deny warnings` by default. | None. | | ||
|
|
||
| ## Usage example | ||
|
|
||
| After the shared setup steps (checkout, Rust toolchain install, cache restore), | ||
| call the composites in sequence: | ||
|
|
||
| ```yaml | ||
| jobs: | ||
| lint-and-test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| toolchain: 1.70.0 | ||
| - name: Cargo cache | ||
| uses: Swatinem/rust-cache@v2 | ||
| - name: Run fmt | ||
| uses: ./.github/actions/cargo-fmt | ||
| with: | ||
| toolchain: nightly | ||
| - name: Run clippy | ||
| uses: ./.github/actions/cargo-clippy | ||
| with: | ||
| toolchain: 1.70.0 | ||
| all-features: true | ||
| - name: Run tests | ||
| uses: ./.github/actions/cargo-test | ||
| with: | ||
| toolchain: 1.70.0 | ||
| - name: Security audit | ||
| uses: ./.github/actions/cargo-audit | ||
| ``` | ||
|
|
||
| Each composite forwards optional inputs like `extra-args` so teams can tailor | ||
| command flags without duplicating the shell logic. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P0] Fix indentation on Auto-commit README step
The new workflow block after the composite actions has
- name: Auto-commit README changes (any branch)followed byif:andrun:at the same indentation level. In YAML the keys that belong to the step must be indented deeper than the dash; as written,ifandrunare parsed outside of the step and the workflow fails to load (unexpected key while parsing steps). The pre-existing version used correct indentation. Re‑indentif:andrun:(and their bodies) so they are children of the list item.Useful? React with 👍 / 👎.