name: CI
on:
push:
branches: [main, master]
tags: ["v*"]
pull_request:
branches: [main, master]
env:
CARGO_TERM_COLOR: always
jobs:
check:
name: check (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v5
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: cargo fmt --check
run: cargo fmt --all -- --check
- name: cargo clippy
run: cargo clippy --all-targets -- -D warnings
- name: cargo test
run: cargo test --all-targets
build:
name: build (${{ matrix.target }})
needs: check
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact: streamtop-linux-x86_64
- os: macos-latest
target: aarch64-apple-darwin
artifact: streamtop-macos-aarch64
- os: macos-latest
target: x86_64-apple-darwin
artifact: streamtop-macos-x86_64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact: streamtop-windows-x86_64
steps:
- uses: actions/checkout@v5
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build release
run: cargo build --release --target ${{ matrix.target }}
- name: Package (Unix)
if: runner.os != 'Windows'
run: |
mkdir -p dist
cp "target/${{ matrix.target }}/release/streamtop" "dist/streamtop"
cp README.md LICENSE CHANGELOG.md dist/
cd dist
zip -r "../${{ matrix.artifact }}.zip" streamtop README.md LICENSE CHANGELOG.md
- name: Package (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path dist | Out-Null
Copy-Item "target/${{ matrix.target }}/release/streamtop.exe" dist/
Copy-Item README.md,LICENSE,CHANGELOG.md dist/
Compress-Archive -Path dist\* -DestinationPath "${{ matrix.artifact }}.zip" -Force
- name: Upload artifact
uses: actions/upload-artifact@v5
with:
name: ${{ matrix.artifact }}
path: ${{ matrix.artifact }}.zip
if-no-files-found: error
release:
name: github-release
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- name: Download artifacts
uses: actions/download-artifact@v5
with:
path: artifacts
- name: Prepare release assets
env:
TAG: ${{ github.ref_name }}
run: |
mkdir -p release
ver="${TAG#v}"
for zip in artifacts/*/*.zip; do
base=$(basename "$zip" .zip)
cp "$zip" "release/${base}-${ver}.zip"
done
ls -la release/
- name: Publish GitHub Release
uses: softprops/action-gh-release@v2
with:
draft: false
prerelease: false
generate_release_notes: true
files: release/*.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}