Merge pull request #257 from kohbis/thanks-actions-rs #6
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: Release & Cargo publish | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-test: | |
name: Build and test (${{ matrix.os }}) | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: swatinem/rust-cache@v2 | |
- name: Build | |
run: > | |
cargo build | |
--locked | |
--verbose | |
- name: Run fmt check | |
run: > | |
cargo fmt -- | |
--check | |
- name: Run tests | |
run: > | |
cargo test | |
--verbose | |
release-please: | |
name: Execute release chores | |
permissions: | |
contents: write | |
pull-requests: write | |
runs-on: ubuntu-latest | |
needs: build-test | |
steps: | |
- uses: google-github-actions/release-please-action@v3 | |
id: release | |
with: | |
release-type: rust | |
bump-minor-pre-major: true | |
bump-patch-for-minor-pre-major: true | |
changelog-types: > | |
[ | |
{ "type": "feat", "section": "Features", "hidden": false }, | |
{ "type": "fix", "section": "Bug Fixes", "hidden": false } | |
] | |
outputs: | |
created: ${{ steps.release.outputs.release_created }} | |
github-release: | |
name: GitHub release (${{ matrix.os }}) | |
runs-on: ${{ matrix.os }} | |
needs: release-please | |
if: needs.release-please.outputs.created | |
strategy: | |
matrix: | |
os: [macos-latest, ubuntu-latest] | |
rust: [stable] | |
include: | |
- os: macos-latest | |
artifact_prefix: macos | |
target: x86_64-apple-darwin | |
- os: ubuntu-latest | |
artifact_prefix: linux | |
target: x86_64-unknown-linux-gnu | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
toolchain: ${{ matrix.rust }} | |
target: ${{ matrix.target }} | |
- uses: Swatinem/rust-cache@v2 | |
- name: Cargo build | |
run: > | |
cargo build | |
--release | |
--target ${{ matrix.target }} | |
- name: Packaging final binary | |
shell: bash | |
run: | | |
cd target/${{ matrix.target }}/release | |
strip rslack | |
tar czvf rslack-${{ matrix.artifact_prefix }}.tar.gz rslack | |
shasum -a 256 rslack-${{ matrix.artifact_prefix }}.tar.gz > rslack-${{ matrix.artifact_prefix }}.sha256 | |
- name: Releasing assets | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: | | |
target/${{ matrix.target }}/release/rslack-${{ matrix.artifact_prefix }}.tar.gz | |
target/${{ matrix.target }}/release/rslack-${{ matrix.artifact_prefix }}.sha256 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
publish: | |
name: Publish to crates.io | |
runs-on: ubuntu-latest | |
needs: release-please | |
if: needs.release-please.outputs.created | |
environment: crates.io | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Publish | |
run: > | |
cargo publish | |
--verbose | |
--locked | |
--token ${{ secrets.CARGO_API_KEY }} |