name: Run checks
on:
pull_request:
push:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
run-checks:
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- stable
- beta
steps:
- uses: actions/checkout@v4
- run: |
rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
rustc --version --verbose
echo RUST_VERSION="$(rustc --version)" >> $GITHUB_ENV
- uses: actions/cache@v4
with:
key: cargo-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.lock') }}
path: |
~/.cargo/registry/
target/
- name: Format
id: format
continue-on-error: true
run: |
rustup component add rustfmt
cargo fmt --version
echo FORMAT_VERSION="$(cargo fmt --version)" >> $GITHUB_ENV
cargo fmt --all -- --check
- name: Lint
id: lint
continue-on-error: true
run: |
rustup component add clippy
cargo clippy --version
echo LINT_VERSION="$(cargo clippy --version)" >> $GITHUB_ENV
cargo clippy --all-targets --all-features -- -D warnings
- name: Typecheck
id: typecheck
continue-on-error: true
run: cargo check --all-targets --all-features
- name: Test
id: test
if: steps.typecheck.outcome == 'success'
continue-on-error: true
run: cargo test --all-features
- name: Report
if: always()
env:
TOOLCHAIN: ${{ matrix.toolchain }}
FORMAT_OUTCOME: ${{ steps.format.outcome }}
LINT_OUTCOME: ${{ steps.lint.outcome }}
TYPECHECK_OUTCOME: ${{ steps.typecheck.outcome }}
TEST_OUTCOME: ${{ steps.test.outcome }}
uses: actions/github-script@v7
with:
script: |
let emojiMapping = {
"success": "✅",
"failure": "❌",
"cancelled": "🚫",
"skipped": "➖",
};
let formatEmoji = emojiMapping[process.env.FORMAT_OUTCOME];
let lintEmoji = emojiMapping[process.env.LINT_OUTCOME];
let typecheckEmoji = emojiMapping[process.env.TYPECHECK_OUTCOME];
let testEmoji = emojiMapping[process.env.TEST_OUTCOME];
let resultsTable = [
"| Check | Result |",
"| :-------- | :---------------: |",
`| Format | ${formatEmoji} |`,
`| Lint | ${lintEmoji} |`,
`| Typecheck | ${typecheckEmoji} |`,
`| Test | ${testEmoji} |`,
].join("\n");
let versionBlock = [
process.env.RUST_VERSION,
process.env.FORMAT_VERSION,
process.env.LINT_VERSION,
].join("\n");
let versionDetails = [
"<details>",
` <summary><strong>Toolchain:</strong> <code>${process.env.TOOLCHAIN}</code></summary>`,
` <pre><code>${versionBlock}</code></pre>`,
"</details>",
].join("\n");
let mdSummary = [
resultsTable,
versionDetails,
].join("\n\n") + "\n";
core.summary.addRaw(mdSummary).write();
if (process.env.TOOLCHAIN === "stable" && context.issue.number != null) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: mdSummary,
});
}
console.log(`${formatEmoji} Format`);
console.log(`${lintEmoji} Lint`);
console.log(`${typecheckEmoji} Typecheck`);
console.log(`${testEmoji} Test`);
let outcomes = [
process.env.FORMAT_OUTCOME,
process.env.LINT_OUTCOME,
process.env.TYPECHECK_OUTCOME,
process.env.TEST_OUTCOME,
];
if (outcomes.some((it) => it !== "success")) {
core.setFailed(`One or more checks did not succeed.`);
}