From 00c748f96a6424d500a21c4d01806ebd0c9bb08a Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 26 May 2024 01:01:47 +0100 Subject: [PATCH] feat: add action file --- .github/workflows/ci.yml | 90 ++++++++++++++++++++++++++++++++++++++ CHANGELOG.md | 5 +++ action.yml | 30 +++++++++++++ test-workspace/Cargo.lock | 74 +++++++++++++++++++++++++++++++ test-workspace/Cargo.toml | 9 ++++ test-workspace/src/main.rs | 3 ++ 6 files changed, 211 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 CHANGELOG.md create mode 100644 action.yml create mode 100644 test-workspace/Cargo.lock create mode 100644 test-workspace/Cargo.toml create mode 100644 test-workspace/src/main.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9c083e9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,90 @@ +name: CI + +on: + push: + branches: [main] + merge_group: + types: [checks_requested] + pull_request: + branches: [main] + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + msrv: + name: MSRV + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + + - name: Determine MSRV + id: msrv + uses: ./ + with: + manifest-path: ./test-workspace/Cargo.toml + + outputs: + msrv: "${{ steps.msrv.outputs.msrv }}" + + build: + needs: msrv + + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + toolchain: + - { name: msrv, version: "${{ needs.msrv.outputs.msrv }}" } + - { name: stable, version: stable } + + name: Test / ${{ matrix.toolchain.name }} + + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: ${{ matrix.toolchain.version }} + + - name: Test + run: cargo run --manifest-path=./test-workspace/Cargo.toml + + combined: + runs-on: ubuntu-latest + + name: Test Combined + + steps: + - uses: actions/checkout@v4 + + - name: Install Rust (stable) + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + cache: false + + - name: Determine MSRV + id: msrv + uses: ./ + with: + manifest-path: ./test-workspace/Cargo.toml + + - name: Install Rust (MSRV) + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: ${{ steps.msrv.outputs.msrv }} + cache-workspaces: ./test-workspace + + - name: Test + run: cargo run --manifest-path=./test-workspace/Cargo.toml diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..621a0db --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## 0.1.0 + +- Initial release. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..d4050f2 --- /dev/null +++ b/action.yml @@ -0,0 +1,30 @@ +name: Determine minimum supported Rust version (MSRV) for workspace + +description: | + Determine minimum supported Rust version (MSRV) for workspace for use in a job matrix. + +inputs: + manifest-path: + description: Path to Cargo.toml manifest for workspace + required: false + +runs: + using: composite + + steps: + - name: Read MSRV from workspace manifest + id: read_msrv + shell: bash + run: | + cargo metadata --format-version=1 --manifest-path=${{ inputs.manifest-path || 'Cargo.toml' }} \ + | jq -r 'first(.packages[] | select(.source == null and .rust_version)) | .rust_version' \ + | sed -E 's/^1\.([0-9]{2})$/1\.\1\.0/' \ + | xargs -0 printf "msrv=%s" \ + | tee /dev/stderr \ + >> "$GITHUB_OUTPUT" + +outputs: + msrv: + description: |- + Minimum supported Rust version. E.g.: 1.72.1" + value: ${{ steps.read_msrv.outputs.msrv }} diff --git a/test-workspace/Cargo.lock b/test-workspace/Cargo.lock new file mode 100644 index 0000000..0dad367 --- /dev/null +++ b/test-workspace/Cargo.lock @@ -0,0 +1,74 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "crate" +version = "1.0.0" +dependencies = [ + "detrim", +] + +[[package]] +name = "detrim" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a398843bbb5c8aa78639440d0ab4d6d14e9a24337046394053a95299ec4418da" +dependencies = [ + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/test-workspace/Cargo.toml b/test-workspace/Cargo.toml new file mode 100644 index 0000000..41d02d0 --- /dev/null +++ b/test-workspace/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "crate" +version = "1.0.0" +publish = false +edition = "2018" +rust-version = "1.72" + +[dependencies] +detrim = "0.1" diff --git a/test-workspace/src/main.rs b/test-workspace/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/test-workspace/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}