diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 92c44a8..a3f176c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,3 +9,5 @@ updates: directory: "/" schedule: interval: "weekly" + cooldown: + default-days: 7 diff --git a/.github/workflows/autotag-releases.yml b/.github/workflows/autotag-releases.yml index 4ca4ad5..fe6fc2a 100644 --- a/.github/workflows/autotag-releases.yml +++ b/.github/workflows/autotag-releases.yml @@ -15,7 +15,7 @@ jobs: permissions: contents: write steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7.0.1 - name: Get version from tag id: tag_name run: | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a2d5ed9..edd2415 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: - "beta" - "stable" steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7.0.1 # Test toolchain file support - name: Write rust-toolchain.toml @@ -93,7 +93,7 @@ jobs: name: Cache runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7.0.1 - name: Install Rust uses: ./ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d922da4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +test-workspace/target/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ba2a6f4..2ddb195 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v6.0.0 hooks: - id: check-case-conflict - id: check-executables-have-shebangs @@ -11,8 +11,9 @@ repos: - id: trailing-whitespace args: [--markdown-linebreak-ext=md] - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.29.2 + rev: 0.38.0 hooks: - id: check-dependabot - id: check-github-actions - - id: check-github-workflows + # Does not like the `null` value in the "rust" matrix in ci.yml + # - id: check-github-workflows diff --git a/CHANGELOG.md b/CHANGELOG.md index b302a9c..5e56fab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,56 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.0.0] - 2026-09-07 + +* Use `CARGO_BUILD_WARNINGS` for enforcing warning free compilations (#98) + This is a new variable supported by cargo 1.97+ [and sets the `build.warnings` config](https://blog.rust-lang.org/2026/07/09/Rust-1.97.0/#cargo-support-for-denying-warnings). + It allows removing the `RUSTFLAGS="-D warnings"` default, which will improve compatibility with `target.*.rustflags` and `.cargo/config.toml` files. + + This adds a new `build-warnings` input to configure the value for the `build.warnings` config. +* Add error matcher for Rust panics + This will highlight the location of the panic location during tests. +* Reuse output of `rustc --version --verbose` calls (#103 by @ChihweiLHBird) + +## [1.17.0] - 2026-06-25 + +* Add new parameter `cache-targets` that is propagated to `Swatinem/rust-cache` as `cache-targets` (#84). + This allows disabling caching of the workspace `target` directory, e.g. when using `sccache`, while keeping the rest of the cache enabled. + +## [1.16.1] - 2026-05-08 + +* Renamed internally used variable to avoid clashes with globally existing variables. + This fixes the interference of the TOOLCHAIN variable as reported in #91. + +## [1.16.0] - 2026-04-13 + +* Add new parameter `cache-save-if` that is propagated to `Swatinem/rust-cache` as `save-if` (#90 by @ChanTsune) + +## [1.15.4] - 2026-03-15 + +* Bump Swatinem/rust-cache from 2.8.2 to 2.9.1 (#87 by @hyperfinitism) + This gets rid of the warnings about Node.js 20. + +## [1.15.3] - 2026-03-01 + +* Bump Swatinem/rust-cache from 2.8.1 to 2.8.2 + +## [1.15.2] - 2025-10-04 + +* Fix: Run the version detection steps in the selected `rust-src-dir` directory. + This should enable the version selection even without a default toolchain installed. + Fixes #74. + +## [1.15.1] - 2025-09-23 + +* Update `Swatinem/rust-cache` to v2.8.1 + +## [1.15.0] - 2025-09-14 + +* Add support for non-root source directory. + Accept source code and `rust-toolchain.toml` file in subdirectories of the repository. + Adds a new parameter `rust-src-dir` that controls the lookup for toolchain files and sets a default value for the `cache-workspace` input. (#69 by @Kubaryt) + ## [1.14.1] - 2025-08-28 * Pin `Swatinem/rust-cache` action to a full commit SHA (#68 by @JohnTitor) diff --git a/README.md b/README.md index 6c7ca03..9a93749 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ jobs: name: cargo test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions-rust-lang/setup-rust-toolchain@v1 + - uses: actions/checkout@v6 + - uses: actions-rust-lang/setup-rust-toolchain@v2 - run: cargo test --all-features # Check formatting with rustfmt @@ -30,9 +30,9 @@ jobs: name: cargo fmt runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 # Ensure rustfmt is installed and setup problem matcher - - uses: actions-rust-lang/setup-rust-toolchain@v1 + - uses: actions-rust-lang/setup-rust-toolchain@v2 with: components: rustfmt - name: Rustfmt Check @@ -48,42 +48,31 @@ If no `toolchain` value or toolchain file is present, it will default to `stable First, all items specified in the toolchain file are installed. Afterward, the `components` and `target` specified via inputs are installed in addition to the items from the toolchain file. -| Name | Description | Default | -| ------------------------ | ----------------------------------------------------------------------------------------------------------------------- | ------------- | -| `toolchain` | Comma-separated list of Rustup toolchain specifier e.g. `stable`, `nightly`, `1.42.0`. The last version is the default. | stable | -| `target` | Additional target support to install e.g. `wasm32-unknown-unknown` | | -| `components` | Comma-separated string of additional components to install e.g. `clippy, rustfmt` | | -| `cache` | Automatically configure Rust cache (using [`Swatinem/rust-cache`]) | true | -| `cache-directories` | Propagates the value to [`Swatinem/rust-cache`] | | -| `cache-workspaces` | Propagates the value to [`Swatinem/rust-cache`] | | -| `cache-on-failure` | Propagates the value to [`Swatinem/rust-cache`] | true | -| `cache-key` | Propagates the value to [`Swatinem/rust-cache`] as `key` | | -| `cache-shared-key` | Propagates the value to [`Swatinem/rust-cache`] as `shared-key` | | -| `cache-bin` | Propagates the value to [`Swatinem/rust-cache`] as `cache-bin` | true | -| `cache-provider` | Propagates the value to [`Swatinem/rust-cache`] as `cache-provider` | 'github' | -| `cache-all-crates` | Propagates the value to [`Swatinem/rust-cache`] as `cache-all-crates` | false | -| `cache-workspace-crates` | Propagates the value to [`Swatinem/rust-cache`] as `cache-workspace-crates` | false | -| `matcher` | Enable problem matcher to surface build messages and formatting issues | true | -| `rustflags` | Set the value of `RUSTFLAGS` (set to empty string to avoid overwriting existing flags) | "-D warnings" | -| `override` | Setup the last installed toolchain as the default via `rustup override` | true | +| Name | Description | Default | +| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | +| `toolchain` | Comma-separated list of Rustup toolchain specifier e.g. `stable`, `nightly`, `1.42.0`. The last version is the default. | stable | +| `target` | Additional target support to install e.g. `wasm32-unknown-unknown` | | +| `build-warnings` | Sets the `build.warnings` config via the `CARGO_BUILD_WARNINGS` variable. (set to empty string to avoid overwriting existing flags) | deny | +| `components` | Comma-separated string of additional components to install e.g. `clippy, rustfmt` | | +| `cache` | Automatically configure Rust cache (using [`Swatinem/rust-cache`]) | true | +| `cache-directories` | Propagates the value to [`Swatinem/rust-cache`] | | +| `cache-workspaces` | Propagates the value to [`Swatinem/rust-cache`]. Influenced by the value of `rust-src-dir`. | | +| `cache-on-failure` | Propagates the value to [`Swatinem/rust-cache`] | true | +| `cache-key` | Propagates the value to [`Swatinem/rust-cache`] as `key` | | +| `cache-shared-key` | Propagates the value to [`Swatinem/rust-cache`] as `shared-key` | | +| `cache-bin` | Propagates the value to [`Swatinem/rust-cache`] as `cache-bin` | true | +| `cache-provider` | Propagates the value to [`Swatinem/rust-cache`] as `cache-provider` | 'github' | +| `cache-all-crates` | Propagates the value to [`Swatinem/rust-cache`] as `cache-all-crates` | false | +| `cache-workspace-crates` | Propagates the value to [`Swatinem/rust-cache`] as `cache-workspace-crates` | false | +| `cache-save-if` | Propagates the value to [`Swatinem/rust-cache`] as `save-if` | true | +| `cache-targets` | Propagates the value to [`Swatinem/rust-cache`] as `cache-targets` | true | +| `matcher` | Enable problem matcher to surface build messages and formatting issues | true | +| `rustflags` | Set the value of `RUSTFLAGS` (set to empty string to avoid overwriting existing flags) | "" | +| `override` | Setup the last installed toolchain as the default via `rustup override` | true | +| `rust-src-dir` | Path from root directory to directory with the Rust source directory (if its not in the root of the repository). Sets a default value for `cache-workspaces` that enables caching. | | [`Swatinem/rust-cache`]: https://github.com/Swatinem/rust-cache -### RUSTFLAGS - -By default, this action sets the `RUSTFLAGS` environment variable to `-D warnings`. -However, rustflags sources are mutually exclusive, so setting this environment variable omits any configuration through `target.*.rustflags` or `build.rustflags`. - -- If `RUSTFLAGS` is already set, no modifications of the variable are made and the original value remains. -- If `RUSTFLAGS` is unset and the `rustflags` input is empty (i.e., the empty string), then it will remain unset. - Use this, if you want to prevent the value from being set because you make use of `target.*.rustflags` or `build.rustflags`. -- Otherwise, the environment variable `RUSTFLAGS` is set to the content of `rustflags`. - -To prevent this from happening, set the `rustflags` input to an empty string, which will -prevent the action from setting `RUSTFLAGS` at all, keeping any existing preferences. - -You can read more rustflags, and their load order, in the [Cargo reference]. - ## Outputs | Name | Description | diff --git a/action.yml b/action.yml index f3b877b..d8d755a 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,10 @@ inputs: target: description: "Target triple to install for this toolchain" required: false + build-warnings: + description: "Sets the build.warnings config via the CARGO_BUILD_WARNINGS variable." + required: false + default: "deny" components: description: "Comma-separated list of components to be additionally installed" required: false @@ -57,6 +61,14 @@ inputs: description: "Determines which crates are cached. If `true` all crates will be cached, otherwise only dependent crates will be cached." required: false default: "false" + cache-save-if: + description: "Determines whether the cache should be saved. If `false`, the cache is only restored." + required: false + default: "true" + cache-targets: + description: "Determines whether workspace targets are cached. If `false`, only the cargo registry will be cached." + required: false + default: "true" matcher: description: "Enable the Rust problem matcher" required: false @@ -64,11 +76,14 @@ inputs: rustflags: description: "set RUSTFLAGS environment variable, set to empty string to avoid overwriting build.rustflags" required: false - default: "-D warnings" + default: "" override: description: "Setup the last installed toolchain as the default via `rustup override`" required: false default: "true" + rust-src-dir: + description: "Specify path from root directory to the Rust source directory. By default root directory will be used." + required: false outputs: rustc-version: @@ -84,6 +99,10 @@ outputs: description: A short hash of the rustc version, appropriate for use as a cache key. "20220627a831" value: ${{steps.versions.outputs.cachekey}} +# All local variables are using the `_srt_` prefix (for setup-rust-toolchain) +# this is to avoid conflicts with globally existing variables, as some names are quite generic (e.g., toolchain) +# This has caused issues in the past. +# https://github.com/actions-rust-lang/setup-rust-toolchain/issues/91 runs: using: composite steps: @@ -96,19 +115,20 @@ runs: - id: flags env: - targets: ${{inputs.target}} - components: ${{inputs.components}} + _srt_targets: ${{inputs.target}} + _srt_components: ${{inputs.components}} shell: bash run: | : construct rustup command line - echo "targets=$(for t in ${targets//,/ }; do echo -n ' --target' $t; done)" >> $GITHUB_OUTPUT - echo "components=$(for c in ${components//,/ }; do echo -n ' --component' $c; done)" >> $GITHUB_OUTPUT + echo "targets=$(for t in ${_srt_targets//,/ }; do echo -n ' --target' $t; done)" >> $GITHUB_OUTPUT + echo "components=$(for c in ${_srt_components//,/ }; do echo -n ' --component' $c; done)" >> $GITHUB_OUTPUT echo "downgrade=${{contains(inputs.toolchain, 'nightly') && inputs.components && ' --allow-downgrade' || ''}}" >> $GITHUB_OUTPUT # The environment variables always need to be set before the caching action - name: Setting Environment Variables env: - NEW_RUSTFLAGS: ${{inputs.rustflags}} + _srt_NEW_RUSTFLAGS: ${{inputs.rustflags}} + _srt_CARGO_BUILD_WARNINGS: ${{inputs.build-warnings}} shell: bash run: | if [[ ! -v CARGO_INCREMENTAL ]]; then @@ -123,8 +143,11 @@ runs: if [[ ! -v RUST_BACKTRACE ]]; then echo "RUST_BACKTRACE=short" >> $GITHUB_ENV fi - if [[ ( ! -v RUSTFLAGS ) && $NEW_RUSTFLAGS != "" ]]; then - echo "RUSTFLAGS=$NEW_RUSTFLAGS" >> $GITHUB_ENV + if [[ ( ! -v RUSTFLAGS ) && $_srt_NEW_RUSTFLAGS != "" ]]; then + echo "RUSTFLAGS=$_srt_NEW_RUSTFLAGS" >> $GITHUB_ENV + fi + if [[ ( ! -v CARGO_BUILD_WARNINGS ) && $_srt_CARGO_BUILD_WARNINGS != "" ]]; then + echo "CARGO_BUILD_WARNINGS=$_srt_CARGO_BUILD_WARNINGS" >> $GITHUB_ENV fi # Enable faster sparse index on nightly # The value is ignored on stable and causes no problems @@ -159,52 +182,69 @@ runs: - name: rustup toolchain install ${{inputs.toolchain || 'stable'}} env: - toolchain: ${{inputs.toolchain}} - targets: ${{inputs.target}} - components: ${{inputs.components}} - override: ${{inputs.override}} + _srt_toolchain: ${{inputs.toolchain}} + _srt_targets: ${{inputs.target}} + _srt_components: ${{inputs.components}} + _srt_override: ${{inputs.override}} + _srt_rust_src_dir: ${{inputs.rust-src-dir}} shell: bash run: | - if [[ -z "$toolchain" && ( -f "rust-toolchain" || -f "rust-toolchain.toml" ) ]] + # Check if value is set + if [[ -n "$_srt_rust_src_dir" ]] + then + # If value is set the directory must exist + if [[ -d "$_srt_rust_src_dir" ]] + then + cd "$_srt_rust_src_dir" + else + echo "'rust-src-dir' does not point to an existing directory" >&2 + echo "The value of 'rust-src-dir' is: ${_srt_rust_src_dir}" >&2 + exit 1 + fi + fi + if [[ -z "$_srt_toolchain" && ( -f "rust-toolchain" || -f "rust-toolchain.toml") ]] then # Install the toolchain as specified in the file # rustup show is the old way that implicitly installed a toolchain # rustup toolchain install is the new explicit way # https://github.com/rust-lang/rustup/issues/3635#issuecomment-2343511297 rustup show active-toolchain || rustup toolchain install - if [[ -n $components ]]; then - rustup component add ${components//,/ } + if [[ -n $_srt_components ]]; then + rustup component add ${_srt_components//,/ } fi - if [[ -n $targets ]]; then - rustup target add ${targets//,/ } + if [[ -n $_srt_targets ]]; then + rustup target add ${_srt_targets//,/ } fi else - if [[ -z "$toolchain" ]] + if [[ -z "$_srt_toolchain" ]] then - toolchain=stable + _srt_toolchain=stable fi - rustup toolchain install ${toolchain//,/ } ${{steps.flags.outputs.targets}}${{steps.flags.outputs.components}} --profile minimal${{steps.flags.outputs.downgrade}} --no-self-update + rustup toolchain install ${_srt_toolchain//,/ } ${{steps.flags.outputs.targets}}${{steps.flags.outputs.components}} --profile minimal${{steps.flags.outputs.downgrade}} --no-self-update # Take the last element from the list - if [[ "$override" == "true" ]] + if [[ "$_srt_override" == "true" ]] then - rustup override set ${toolchain//*,/ } + rustup override set ${_srt_toolchain//*,/ } fi fi - id: versions name: Print installed versions shell: bash + # Switch to the Rust sub-directory + working-directory: ${{inputs.rust-src-dir || '.'}} run: | echo "rustc-version=$(rustc --version)" >> $GITHUB_OUTPUT - rustc --version --verbose + _srt_VERBOSE=$(rustc --version --verbose) + echo "$_srt_VERBOSE" echo "cargo-version=$(cargo --version)" >> $GITHUB_OUTPUT cargo --version --verbose echo "rustup-version=$(rustup --version)" >> $GITHUB_OUTPUT rustup --version - DATE=$(rustc --version --verbose | sed -ne 's/^commit-date: \(20[0-9][0-9]\)-\([01][0-9]\)-\([0-3][0-9]\)$/\1\2\3/p') - HASH=$(rustc --version --verbose | sed -ne 's/^commit-hash: //p') - echo "cachekey=$(echo $DATE$HASH | head -c12)" >> $GITHUB_OUTPUT + _srt_DATE=$(echo "$_srt_VERBOSE" | sed -ne 's/^commit-date: \(20[0-9][0-9]\)-\([01][0-9]\)-\([0-3][0-9]\)$/\1\2\3/p') + _srt_HASH=$(echo "$_srt_VERBOSE" | sed -ne 's/^commit-hash: //p') + echo "cachekey=$(echo $_srt_DATE$_srt_HASH | head -c12)" >> $GITHUB_OUTPUT - name: Downgrade registry access protocol when needed shell: bash @@ -220,14 +260,16 @@ runs: - name: Setup Rust Caching if: inputs.cache == 'true' - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0 + uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 with: - workspaces: ${{inputs.cache-workspaces}} + workspaces: ${{ inputs.cache-workspaces || inputs.rust-src-dir }} cache-directories: ${{inputs.cache-directories}} cache-on-failure: ${{inputs.cache-on-failure}} cache-bin: ${{inputs.cache-bin}} cache-provider: ${{inputs.cache-provider}} cache-all-crates: ${{inputs.cache-all-crates}} cache-workspace-crates: ${{inputs.cache-workspace-crates}} + cache-targets: ${{inputs.cache-targets}} + save-if: ${{inputs.cache-save-if}} key: ${{inputs.cache-key}} shared-key: ${{inputs.cache-shared-key}} diff --git a/rust.json b/rust.json index c407391..8ba59a5 100644 --- a/rust.json +++ b/rust.json @@ -28,6 +28,18 @@ "column": 3 } ] + }, + { + "owner": "rust-panic", + "pattern": [ + { + "regexp": "^.*panicked\\s+at\\s+'(.*)',\\s+(.*):(\\d+):(\\d+)$", + "message": 1, + "file": 2, + "line": 3, + "column": 4 + } + ] } ] }