ci: new release workflow config #45
Workflow file for this run
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: Build & Release | |
permissions: | |
contents: write | |
on: | |
push: | |
tags: | |
- "v*" | |
jobs: | |
format: | |
name: fmt | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install toolchain | |
uses: dtolnay/rust-toolchain@1.73.0 | |
with: | |
components: rustfmt | |
- name: Check formatting | |
run: | | |
cargo fmt --all -- --check | |
clippy: | |
name: clippy | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install toolchain | |
uses: dtolnay/rust-toolchain@1.73.0 | |
with: | |
components: clippy | |
- name: Check the lints | |
run: | | |
cargo clippy -- -D warnings | |
test: | |
name: test | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install toolchain | |
uses: dtolnay/rust-toolchain@1.73.0 | |
- name: Unit Test | |
run: | | |
cargo test --workspace | |
env: | |
RUST_BACKTRACE: 1 | |
build: | |
name: Build | |
needs: [format, clippy, test] | |
runs-on: ${{ matrix.os }}-latest | |
strategy: | |
matrix: | |
target: | |
[ | |
x86_64-apple-darwin, | |
aarch64-unknown-linux-gnu, | |
x86_64-unknown-linux-gnu, | |
aarch64-apple-darwin, | |
] | |
include: | |
- target: x86_64-apple-darwin | |
os: macos | |
binary_name: cl_${{ github.ref_name }}_darwin_amd64 | |
- target: x86_64-unknown-linux-gnu | |
os: ubuntu | |
binary_name: cl_${{ github.ref_name }}_linux_amd64 | |
- target: aarch64-unknown-linux-gnu | |
os: ubuntu | |
binary_name: cl_${{ github.ref_name }}_linux_arm64 | |
- target: aarch64-apple-darwin | |
os: macos | |
binary_name: cl_${{ github.ref_name }}_darwin_arm64 | |
steps: | |
- name: Install toolchain for ${{ matrix.target }} | |
uses: dtolnay/rust-toolchain@1.73.0 | |
with: | |
targets: ${{ matrix.target }} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install Cross | |
if: ${{ matrix.os == 'ubuntu' }} | |
run: cargo install cross | |
- name: Build with Cross | |
if: ${{ matrix.os == 'ubuntu' }} | |
run: | | |
cross build --release --bins --target ${{ matrix.target }} | |
- name: Build | |
if: ${{ matrix.os != 'ubuntu' }} | |
run: | | |
cargo build --release --bins --target ${{ matrix.target }} | |
- name: rename binary | |
run: | | |
mv target/${{ matrix.target }}/release/cl target/${{ matrix.target }}/release/cl-${{ matrix.binary_name }} | |
- name: Create tar.gz file | |
run: | | |
tar -czvf target/${{ matrix.target }}/release/cl-${{ matrix.binary_name }}.tar.gz -C target/${{ matrix.target }}/release/ cl-${{ matrix.binary_name }} | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: cl-${{ matrix.target }} | |
path: target/${{ matrix.target }}/release/cl-${{ matrix.binary_name }}.tar.gz | |
if-no-files-found: error | |
release: | |
name: Release | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: target/artifacts/ | |
- name: check artifacts | |
run: ls -latr target/artifacts/ | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: | | |
target/artifacts/* | |
token: ${{ secrets.GH_TOKEN }} | |
- name: Update Homebrew formula | |
uses: dawidd6/action-homebrew-bump-formula@v3 | |
with: | |
token: ${{ secrets.GH_TOKEN }} | |
tap: rvigo/homebrew-cl | |
formula: cl | |