name: Release
on:
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
jobs:
create-release:
name: Create Release
runs-on: ubuntu-latest
outputs:
release_id: ${{ steps.create_release.outputs.id }}
steps:
- uses: actions/checkout@v4
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
with:
draft: false
prerelease: false
generate_release_notes: true
build-release:
name: Build Release
needs: create-release
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [linux, macos, macos-arm, windows]
include:
- build: linux
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-gnu
archive: tar.gz
- build: macos
os: macos-latest
rust: stable
target: x86_64-apple-darwin
archive: tar.gz
- build: macos-arm
os: macos-latest
rust: stable
target: aarch64-apple-darwin
archive: tar.gz
- build: windows
os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
archive: zip
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Build archive
shell: bash
run: |
staging="cc2report-${{ matrix.target }}"
mkdir -p "$staging"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
cp "target/${{ matrix.target }}/release/cc2report.exe" "$staging/"
else
cp "target/${{ matrix.target }}/release/cc2report" "$staging/"
fi
cp README.md LICENSE CHANGELOG.md "$staging/"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
7z a "$staging.zip" "$staging"
echo "ASSET=$staging.zip" >> $GITHUB_ENV
else
tar czf "$staging.tar.gz" "$staging"
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
fi
- name: Upload Release Asset
uses: softprops/action-gh-release@v2
with:
files: ${{ env.ASSET }}
publish-crate:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: [create-release, build-release]
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}