name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
ci:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.95.0
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
- run: cargo fmt -- --check
- run: cargo clippy --all-targets -- -D warnings
- run: cargo test
build:
needs: ci
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-latest
target: x86_64-apple-darwin
artifact: ezpn-x86_64-apple-darwin.tar.gz
- os: macos-latest
target: aarch64-apple-darwin
artifact: ezpn-aarch64-apple-darwin.tar.gz
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact: ezpn-x86_64-unknown-linux-gnu.tar.gz
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.95.0
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- run: cargo build --release --target ${{ matrix.target }}
- name: Package
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../${{ matrix.artifact }} ezpn ezpn-ctl
cd ../../..
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: ${{ matrix.artifact }}
publish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Create or update GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if gh release view "${{ github.ref_name }}" >/dev/null 2>&1; then
gh release upload "${{ github.ref_name }}" artifacts/*.tar.gz --clobber
else
gh release create "${{ github.ref_name }}" \
--title "${{ github.ref_name }}" \
--generate-notes \
artifacts/*.tar.gz
fi
- uses: dtolnay/rust-toolchain@1.95.0
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
set +e
out=$(cargo publish --allow-dirty 2>&1)
rc=$?
echo "$out"
if [ $rc -eq 0 ]; then
exit 0
fi
if echo "$out" | grep -q "already exists on crates.io"; then
echo "::notice::version already published — skipping"
exit 0
fi
exit $rc