Skip to content

Commit

Permalink
feat: add action file
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed May 26, 2024
1 parent e40c445 commit 5de5909
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 0 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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 }}
cache-workspaces: ./test-workspace

- 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.1.0

- Initial release.
30 changes: 30 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
74 changes: 74 additions & 0 deletions test-workspace/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions test-workspace/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "crate"
version = "1.0.0"
publish = false
edition = "2018"
rust-version = "1.72"

[dependencies]
detrim = "0.1"
3 changes: 3 additions & 0 deletions test-workspace/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

0 comments on commit 5de5909

Please sign in to comment.