Skip to content

ci: Tarpaulin flakiness #267

ci: Tarpaulin flakiness

ci: Tarpaulin flakiness #267

Workflow file for this run

name: Main
on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev
env:
CARGO_TERM_COLOR: always
jobs:
build-test:
name: Build and test (${{ matrix.os }})
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- name: Build
run: >
cargo build
--locked
--verbose
- name: Run tests (without coverage)
run: >
cargo test
--verbose
build-test-feature-powerset:
name: Build and test feature powerset
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- uses: taiki-e/install-action@v2
with:
tool: cargo-hack
- name: Run tests
run: >
cargo hack
--feature-powerset
test
build-test-coverage:
name: Build and test with coverage
runs-on: ubuntu-latest
strategy:
matrix:
include:
- cli-option: "--lib"
codecov-flag: "unit"
# https://github.com/rust-lang/cargo/issues/8396#issuecomment-713126649
- cli-option: "--test '*'"
codecov-flag: "integration"
- cli-option: "--doc"
codecov-flag: "doc"
- cli-option: "--all-targets"
codecov-flag: "all-targets"
# The others might miss benches, examples, ..., so ensure we have a total as
# well. `--all-targets` does not include `--doc`, so put that extra.
- cli-option: "--all-targets --doc"
codecov-flag: "total"
steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- name: Install cargo-tarpaulin (for coverage)
# As recommened by `cargo-binstall` team:
# https://github.com/cargo-bins/cargo-binstall/tree/d5549ce99ebc82b1ceee93a41375137b7dbd1a1f#faq
uses: taiki-e/install-action@v2
with:
tool: cargo-tarpaulin
- name: Install (minimal) nightly toolchain
run: rustup toolchain install --profile minimal nightly
- name: Run tests (with coverage)
# Tarpaulin is very flaky, and coverage is just 'nice to have', so do not fail
# entire pipeline because of it.
continue-on-error: true
id: tarpaulin
# Will read from `tarpaulin.toml`. Extra flags given here complement the config.
run: >
cargo tarpaulin
--verbose
${{ matrix.cli-option }}
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
# `steps.$STEP.conclusion` is "after" `continue-on-error` was applied,
# `steps.$STEP.outcome` is "before".
# That's why the `success()` expression doesn't work here.
if: ${{ steps.tarpaulin.outcome == 'success' }}
with:
fail_ci_if_error: true
verbose: true
flags: ${{ matrix.codecov-flag }}
token: ${{ secrets.CODECOV_UPLOAD_TOKEN }}
release-please:
name: Execute release chores
runs-on: ubuntu-latest
outputs:
created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
tag_name_without_v: ${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }}
steps:
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/making-authenticated-api-requests-with-a-github-app-in-a-github-actions-workflow
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: google-github-actions/release-please-action@v4
id: release
with:
# Token needs: `contents: write`, `pull-requests: write`
token: ${{ steps.app-token.outputs.token }}
build-upload:
name: Build and upload binaries
needs: release-please
# Assumption: if release created, tests ran in corresponding PR, so it's safe to not
# `needs` tests here.
if: needs.release-please.outputs.created
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
crate: srgn
binary: srgn
extension: ""
- os: macos-latest
target: x86_64-apple-darwin
crate: srgn
binary: srgn
extension: ""
- os: macos-latest
target: aarch64-apple-darwin
crate: srgn
binary: srgn
extension: ""
- os: windows-latest
target: x86_64-pc-windows-msvc
crate: srgn
binary: srgn
extension: ".exe"
runs-on: ${{ matrix.os }}
env:
ASSET_FILE: "${{ matrix.crate }}-${{ matrix.target }}.tgz"
permissions:
contents: write # For `gh` to upload asset to release
steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- name: Add rustup target
# Idempotent, so just succeeds if already added.
run: rustup target add ${{ matrix.target }}
- name: Build
shell: bash
run: >
cargo build
--release
--locked
--verbose
--target ${{ matrix.target }}
--bin ${{ matrix.binary }}
- name: Package binary (for cargo-binstall)
shell: bash
env:
DIR: ${{ matrix.crate }}
run: >
mkdir "$DIR"
&& mv
"target/${{ matrix.target }}/release/${{ matrix.binary }}${{ matrix.extension }}"
"$DIR"
&& tar
--create
--verbose
--gzip
--file "$ASSET_FILE"
"$DIR"
- name: Attach binary to release
shell: bash
env:
# `gh` blows up without token, cf.
# https://josh-ops.com/posts/gh-auth-login-in-actions/#example-2---env-variable
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >
gh release upload
${{ needs.release-please.outputs.tag_name }}
"$ASSET_FILE"
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs:
- release-please
# Assumption: if release created, tests ran in corresponding PR, so it's safe to not
# `needs` tests here.
if: needs.release-please.outputs.created
environment:
name: crates.io
url: https://crates.io/crates/srgn/${{ needs.release-please.outputs.tag_name_without_v }}
steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- name: Publish
# https://doc.rust-lang.org/cargo/reference/config.html?highlight=CARGO_REGISTRY_TOKEN#credentials
run: >
cargo publish
--verbose
--locked
--no-verify
--token ${{ secrets.CARGO_REGISTRY_TOKEN }}
release-draft:
name: Turn release draft into full release
runs-on: ubuntu-latest
needs:
- release-please
- build-upload
if: needs.release-please.outputs.created
permissions:
contents: write # For `gh` to edit release
steps:
- uses: actions/checkout@v4
- name: Remove draft status from release
# Now that everything is done, fully release.
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >
gh release edit
${{ needs.release-please.outputs.tag_name }}
--draft=false
test-binstall-installation:
name: Test installation and running via cargo-binstall
strategy:
matrix:
include:
- os: ubuntu-latest
- os: macos-latest
- os: windows-latest
needs:
- release-please
- release-draft
- publish
runs-on: ${{ matrix.os }}
steps:
- uses: cargo-bins/cargo-binstall@main
- name: Install binary
# Get the current version that was just released, and fail if no binaries are
# directly available (don't allow fallback to compilation from source).
run: >
cargo binstall
--version ${{ needs.release-please.outputs.tag_name_without_v }}
--strategies crate-meta-data
--no-confirm
srgn
- name: Print version
run: srgn --version
- name: Print help
run: srgn --help
- name: Test version matches release
shell: bash
run: >
[[ $(srgn --version) == "srgn ${{ needs.release-please.outputs.tag_name_without_v }}" ]]