15 Commits

Author SHA1 Message Date
137d2d5a3a Set environment variables before running rust-cache 2022-07-29 23:22:43 +02:00
8282e10527 Show rustfmt action in example workflow
Show how the related rustfmt action can be used.
2022-07-27 20:42:53 +02:00
2f56cd1b8a Merge pull request #2 from actions-rust-lang/support-toolchain-file
Add support for toolchain files
2022-07-21 23:33:26 +02:00
08934cd939 Add test for toolchain file support 2022-07-21 21:31:15 +00:00
379d2bfd83 Add support for toolchain files
A toolchain file in the repository root will always take priority.

Closes #1
2022-07-21 21:16:38 +00:00
c17331ebbf Update changelog for v1.1.0 2022-07-19 19:03:54 +00:00
49e54cc50a Update to newer version of caching action 2022-07-19 19:01:40 +00:00
29a2385140 Better and more verbose version printing and cachekey version. 2022-07-19 19:00:36 +00:00
8ba04cb6f2 Install rustup if not available, Linux only
The original code stems from this PR:
https://github.com/dtolnay/rust-toolchain/pull/8
2022-07-19 18:48:19 +00:00
5c0654516c Create dependabot configuration for GitHub Actions 2022-07-19 20:16:04 +02:00
d39b183d8d Enable backtraces for test failures 2022-05-02 20:41:08 +00:00
4018312e96 Enable colored cargo output 2022-05-02 20:32:16 +00:00
9015641f5c Update changelog 2022-04-20 20:27:13 +00:00
014f31d759 Shrinkt action description to make it marketplace compliant 2022-04-20 20:25:35 +00:00
85cc8bd3df Add changelog 2022-04-20 20:15:26 +00:00
5 changed files with 148 additions and 25 deletions

11
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"

View File

@ -13,9 +13,28 @@ jobs:
strategy:
fail-fast: false
matrix:
rust: [nightly, beta, stable]
rust: [
# Test with toolchain file override
"1.50",
"nightly",
"beta",
"stable",
]
steps:
- uses: actions/checkout@v3
# Test toolchain file support
- name: Write rust-toolchain.toml
run: |
cat <<EOF >>rust-toolchain.toml
[toolchain]
channel = "nightly-2020-07-10"
components = [ "rustfmt", "rustc-dev" ]
targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]
profile = "minimal"
EOF
shell: bash
if: matrix.rust == '1.50'
- uses: ./
name: Run actions-rust-lang/setup-rust-toolchain ${{matrix.rust}}
id: toolchain

52
CHANGELOG.md Normal file
View File

@ -0,0 +1,52 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [1.2.1] - 2022-07-29
### Fixed
* Set environment variables before invoking the cache action.
This ensures restoring and saving are using the same cache key.
## [1.2.0] - 2022-07-21
### Added
* Prefer toolchain definitions in `rust-toolchain` or `rust-toolchain.toml` files ([Toolchain File](https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file)).
Other input values are ignored if either file is found.
## [1.1.0] - 2022-07-19
### Added
* Install rustup if not available in the CI environment. (Linux only)
The code is taken from this issue: <https://github.com/dtolnay/rust-toolchain/pull/8>
* Add rustc version output suitable as a cache key.
This is based on <https://github.com/dtolnay/rust-toolchain/pull/20> and <https://github.com/dtolnay/rust-toolchain/pull/17>.
### Changed
* Update to `Swatinem/rust-cache@v2`.
## [1.0.2] - 2022-05-02
### Changed
* Enable colored cargo output.
* Print short backtraces during test failure.
## [1.0.1] - 2022-04-20
### Added
* Release action on marketplace
## [1.0.0] - 2022-04-20
Initial Version

View File

@ -24,11 +24,26 @@ jobs:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo test --all-features
# Check formatting with rustfmt
formatting:
name: cargo fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Ensure rustfmt is installed and setup problem matcher
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt
- name: Rustfmt Check
uses: actions-rust-lang/rustfmt@v1
```
## Inputs
All inputs are optional.
If a [toolchain file](https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file) (i.e., `rust-toolchain` or `rust-toolchain.toml`) is found in the root of the repository, it takes precedence.
All input values are ignored if a toolchain file exists.
| Name | Description | Default |
| ------------ | --------------------------------------------------------------------------------- | ------- |

View File

@ -1,8 +1,7 @@
name: Setup Rust Toolchain for GitHub CI
description: |
Setup specific Rust versions and integrate nicely into the ecosystem.
The action enabled caching of Rust tools and build artifacts and sets environment variables for faster and more efficient caching.
It also sets up problem matchers showing compilation and formatting issues.
Setup specific Rust versions with caching pre-configured.
It provides problem matchers for cargo and rustfmt issues.
branding:
icon: "play"
@ -34,6 +33,9 @@ outputs:
rustup-version:
description: "Version as reported by `rustup --version`"
value: ${{steps.versions.outputs.rustup-version}}
cachekey:
description: A short hash of the rustc version, appropriate for use as a cache key. "20220627a831"
value: ${{steps.versions.outputs.cachekey}}
runs:
using: composite
@ -48,30 +50,54 @@ runs:
targets: ${{inputs.target}}
components: ${{inputs.components}}
shell: bash
- name: rustup toolchain install ${{inputs.toolchain}}
run: |
rustup toolchain install ${{inputs.toolchain}}${{steps.flags.outputs.targets}}${{steps.flags.outputs.components}} --profile minimal${{steps.flags.outputs.downgrade}} --no-self-update
rustup default ${{inputs.toolchain}}
shell: bash
- name: Print installed versions
id: versions
run: |
echo "::set-output name=rustc-version::$(rustc --version)"
rustc --version
echo "::set-output name=cargo-version::$(cargo --version)"
cargo --version
echo "::set-output name=rustup-version::$(rustup --version)"
rustup --version
shell: bash
- name: "Setup Rust Caching"
uses: Swatinem/rust-cache@v1
- name: "Install Rust Problem Matcher"
run: echo "::add-matcher::${{ github.action_path }}/rust.json"
shell: bash
# The environment variables always need to be set before the caching action
- name: "Setting Environment Variables"
run: |
echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV
echo "CARGO_PROFILE_DEV_DEBUG=0" >> $GITHUB_ENV
echo "CARGO_TERM_COLOR=always" >> $GITHUB_ENV
echo "RUST_BACKTRACE=short" >> $GITHUB_ENV
echo "RUSTFLAGS=-D warnings" >> $GITHUB_ENV
shell: bash
- name: "Install Rust Problem Matcher"
run: echo "::add-matcher::${{ github.action_path }}/rust.json"
shell: bash
- name: Install rustup, if needed
run: |
if ! command -v rustup &> /dev/null ; then
curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --default-toolchain none -y
echo "${CARGO_HOME:-~/.cargo}/bin" >> $GITHUB_PATH
fi
if: runner.os != 'Windows'
shell: bash
- name: rustup toolchain install ${{inputs.toolchain}}
run: |
if [[ -f "rust-toolchain" || -f "rust-toolchain.toml" ]]
then
# Install the toolchain as specified in the file
# Might break at some point: https://github.com/rust-lang/rustup/issues/1397
rustup show
else
rustup toolchain install ${{inputs.toolchain}}${{steps.flags.outputs.targets}}${{steps.flags.outputs.components}} --profile minimal${{steps.flags.outputs.downgrade}} --no-self-update
rustup default ${{inputs.toolchain}}
fi
shell: bash
- name: Print installed versions
id: versions
run: |
echo "::set-output name=rustc-version::$(rustc --version)"
rustc --version --verbose
echo "::set-output name=cargo-version::$(cargo --version)"
cargo --version --verbose
echo "::set-output name=rustup-version::$(rustup --version)"
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 "::set-output name=cachekey::$(echo $DATE$HASH | head -c12)"
shell: bash
- name: "Setup Rust Caching"
uses: Swatinem/rust-cache@v2