chore(main): release 0.4.5 #166
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Main | |
on: | |
push: | |
pull_request: | |
branches: | |
- main | |
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-coverage: | |
name: Build and test with coverage | |
runs-on: ubuntu-latest | |
# Currently broken... linking with `cc`/`ld` fails, no idea... | |
if: false | |
steps: | |
- uses: actions/checkout@v4 | |
- 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) | |
# `--all-targets` does not include `--doc` | |
run: > | |
cargo tarpaulin | |
--out xml | |
--engine llvm | |
--all-targets | |
--doc | |
- name: Upload coverage reports to Codecov | |
uses: codecov/codecov-action@v3 | |
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@v3 | |
id: release | |
with: | |
# Token needs: `contents: write`, `pull-requests: write` | |
token: ${{ steps.app-token.outputs.token }} | |
release-type: rust | |
- uses: actions/checkout@v4 | |
- name: Mark release as draft | |
# To prevent race conditions where release is created, but no binaries are | |
# attached yet. | |
if: steps.release.outputs.release_created | |
env: | |
# `secrets.GITHUB_TOKEN` would work here (with appropriate `permissions`), | |
# but just reuse what we already have. | |
GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
run: > | |
gh release edit | |
${{ steps.release.outputs.tag_name }} | |
--draft=true | |
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 }}-${{ needs.release-please.outputs.tag_name }}.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 | |
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 }}" ]] |