Skip to content

Commit

Permalink
ci: 🎡 Thanks actions-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
kohbis committed Nov 3, 2023
1 parent 78642f2 commit 4aa8cb7
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 57 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
---
name: PR

'on': pull_request
on:
pull_request:

jobs:
spec:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Run fmt check
run: cargo fmt -- --check
run: >
cargo fmt --
--check
- name: Run tests
run: cargo test --verbose
run: >
cargo test
--verbose
137 changes: 83 additions & 54 deletions .github/workflows/release-and-cargo-publish.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,70 @@
---
name: Release & Cargo publish
name: CD

'on':
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-*'
branches:
- main

jobs:
spec:
runs-on: ubuntu-latest
build-test:
name: Build and test (${{ matrix.os }})

strategy:
matrix:
os: [ubuntu-latest, macos-latest]

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

steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v3
- uses: swatinem/rust-cache@v2
- name: Build
run: >
cargo build
--locked
--verbose
- name: Run fmt check
run: cargo fmt -- --check
run: >
cargo fmt --
--check
- name: Run tests
run: cargo test --verbose
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 },
{ "type": "chore", "section": "Miscellaneous", "hidden": false },
{ "type": "docs", "section": "Documentation", "hidden": false }
]
outputs:
created: ${{ steps.release.outputs.release_created }}

github_release:
name: Publishing for ${{ matrix.os }}
needs: spec
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]
Expand All @@ -30,45 +73,33 @@ jobs:
- os: macos-latest
artifact_prefix: macos
target: x86_64-apple-darwin
binary_postfix: ""
- os: ubuntu-latest
artifact_prefix: linux
target: x86_64-unknown-linux-gnu
binary_postfix: ""

steps:
- uses: actions/checkout@v4
- name: Installing Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
- name: Installing needed macOS dependencies
if: matrix.os == 'macos-latest'
run: brew install [email protected]
- name: Installing needed Ubuntu dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
- uses: actions/cache@v3
with:
path: |
target
key: ${{ runner.os }}-cargo-publish-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.lock') }}
- name: Running cargo build
uses: actions-rs/cargo@v1

- name: Set toolchain
uses: dtolnay/rust-toolchain@stable
with:
command: build
toolchain: ${{ matrix.rust }}
args: --release --target ${{ matrix.target }}
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${{ matrix.binary_postfix }}
tar czvf rslack-${{ matrix.artifact_prefix }}.tar.gz rslack${{ matrix.binary_postfix }}
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
Expand All @@ -79,20 +110,18 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-cargo:
name: Publishing to Cargo
needs: [spec, github_release]
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
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- run: |
sudo apt-get update
sudo apt-get install -y -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
- uses: actions-rs/cargo@v1
with:
command: publish
args: --token ${{ secrets.CARGO_API_KEY }} --allow-dirty

- name: Publish
run: >
cargo publish
--verbose
--locked
--token ${{ secrets.CARGO_API_KEY }}

0 comments on commit 4aa8cb7

Please sign in to comment.