Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ci.yml #12

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: CI

on:
merge_group:
pull_request:
workflow_dispatch:

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:
maybe-expedite:
outputs:
value: ${{ steps.expedite.outputs.value }}

runs-on: ubuntu-latest

steps:
- name: Log github refs
run: |
echo '```' >> "$GITHUB_STEP_SUMMARY"
echo 'github.ref: ${{ github.ref }}' >> "$GITHUB_STEP_SUMMARY"
echo 'github.sha: ${{ github.sha }}' >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"

- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check if merging an up-to-date branch
if: ${{ github.event_name == 'merge_group' }}
id: expedite
run: |
N="$(expr "${{ github.ref }}" : '.*-\([0-9]\+\)-[^-]*$')"
BASE_SHA="$(gh api /repos/${{ github.repository }}/pulls/"$N" | jq -r '.base.sha')"
if git diff --quiet ${{ github.event.merge_group.base_sha }} "$BASE_SHA"; then
echo "value=1" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ github.token }}

test:
needs: [maybe-expedite]

if: ${{ ! needs.maybe-expedite.outputs.value }}

strategy:
fail-fast: ${{ github.event_name == 'merge_group' }}
matrix:
environment: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.environment }}

steps:
- uses: actions/checkout@v4

- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Install tools
run: |
rustup install nightly
rustup +nightly component add clippy
cargo install cargo-dylint dylint-link || true
cargo install cargo-hack || true
cargo install cargo-udeps --locked || true
cargo install group-runner || true

- name: Build
run: cargo test --no-run

- name: Test
run: cargo test --config "target.'cfg(all())'.runner = 'group-runner'"

all-checks:
needs: [test]

if: ${{ always() }}

runs-on: ubuntu-latest

steps:
- name: Check results
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ sha2 = "0.10"
tempfile = "3.13"

[dev-dependencies]
ctor = "0.2"
regex = "1.11"

[lints.rust.unexpected_cfgs]
Expand Down
7 changes: 6 additions & 1 deletion tests/ci.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use assert_cmd::assert::OutputAssertExt;
use regex::Regex;
use std::{fs::read_to_string, path::Path, process::Command};
use std::{env::remove_var, fs::read_to_string, path::Path, process::Command};
use tempfile::tempdir;

#[ctor::ctor]
fn initialize() {
remove_var("CARGO_TERM_COLOR");
}

#[test]
fn clippy() {
Command::new("cargo")
Expand Down