Adapted from the rust docs to add single CI runs on pull requests and pushes, and publish step
https://doc.rust-lang.org/cargo/guide/continuous-integration.html
name: CI
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
release:
types: [published]
env:
CARGO_TERM_COLOR: always
jobs:
build_and_test:
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- stable
- beta
- nightly
steps:
- uses: actions/checkout@v4
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: cargo build --verbose
- run: cargo test --verbose
- name: Publish
if: github.ref_type == 'tag' && matrix.item =='stable'
run: cargo publish --verbose
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
...
jobs:
build_and_test:
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- stable
- beta
- nightly
steps:
...
- name: Publish (Preferred Option 1 that works, without ${{ }})
if: github.ref_type == 'tag' && matrix.item =='stable'
run: cargo publish --verbose
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Publish (Option 2 that works, with ${{ }})
if: ${{ (github.ref_type == 'tag') && (matrix.item =='stable') }}
run: cargo publish --verbose
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}