name: CI
on:
push:
branches:
- '**'
pull_request:
permissions:
contents: read
issues: write
env:
CARGO_TERM_COLOR: always
jobs:
test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Build
run: cargo build
- name: Run tests
run: cargo test
- name: Open issue on failure
if: failure() && github.event_name == 'push'
uses: actions/github-script@v7
with:
script: |
const run_url = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const sha_short = context.sha.substring(0, 7);
const branch = context.ref.replace('refs/heads/', '');
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `CI failed on ${branch} (${sha_short})`,
body: [
`Tests failed on commit [${sha_short}](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/commit/${context.sha}) on branch \`${branch}\`.`,
``,
`**[View failed run](${run_url})**`,
].join('\n'),
labels: ['bug', 'ci'],
});