Skip to content

Commit

Permalink
ci
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsleyh committed Dec 5, 2024
1 parent a030348 commit 30f5770
Showing 1 changed file with 33 additions and 45 deletions.
78 changes: 33 additions & 45 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,64 @@ name: Publish release to Crates.io

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

on:
push:
tags:
- '*'
- 'v*' # Only match version tags

env:
CARGO_TERM_COLOR: always

jobs:
build-test:
name: Build and test (${{ matrix.os }})

strategy:
matrix:
os: [ubuntu-latest]

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

steps:
- uses: actions/checkout@v3
- uses: swatinem/rust-cache@v2
- name: Build
run: >
cargo build
--locked
--verbose
- name: Run tests (without coverage)
if: matrix.os != 'ubuntu-latest'
run: >
cargo test
--verbose
release-please:
name: Execute release chores

permissions:
contents: write
pull-requests: write
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
shared-key: "build-cache"

runs-on: ubuntu-latest
needs: build-test
- name: Build
run: cargo build --locked --verbose

outputs:
created: ${{ steps.release.outputs.release_created }}

steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: rust
- name: Run tests
run: cargo test --verbose

publish:
name: Publish to crates.io

needs: build-test
runs-on: ubuntu-latest
needs: release-please
if: needs.release-please.outputs.created

environment: crates.io

steps:
- uses: actions/checkout@v3
- uses: swatinem/rust-cache@v2
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
shared-key: "publish-cache"

- name: Extract version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: Release ${{ steps.get_version.outputs.VERSION }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish
# https://doc.rust-lang.org/cargo/reference/config.html?highlight=CARGO_REGISTRY_TOKEN#credentials
run: >
cargo publish
--verbose
--locked
--token ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Publish to crates.io
run: cargo publish --locked --verbose --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

0 comments on commit 30f5770

Please sign in to comment.