---
name: Deploy
on:
push:
tags:
- '*'
workflow_dispatch:
permissions:
contents: write
jobs:
test:
uses: ./.github/workflows/test.yml
build:
name: Build and release
runs-on: ${{ matrix.os }}
needs: test
strategy:
matrix:
include:
- build: linux
os: ubuntu-latest
target: x86_64-unknown-linux-musl
rpm_arch: x86_64
- build: linux-arm
os: ubuntu-24.04-arm
target: aarch64-unknown-linux-musl
rpm_arch: aarch64
- build: macos
os: macos-latest
target: x86_64-apple-darwin
- build: macos-arm
os: macos-latest
target: aarch64-apple-darwin
- build: windows
os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Get the release version from the tag
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- run: sudo apt -y install musl-dev musl-tools
if: contains(matrix.target, 'linux')
- name: Install packaging tools (RPM/DEB)
if: contains(matrix.target, 'linux')
run: |
cargo install cargo-generate-rpm
cargo install cargo-deb --force --locked
- name: Build
run: |
cargo build --release --locked --target ${{ matrix.target }}
- name: Generate RPM
if: contains(matrix.target, 'linux')
run: |
ls -alR target/${{ matrix.target }}/release/pwgen2
cp target/${{ matrix.target }}/release/pwgen2 ./target/release/pwgen2
strip -s ./target/release/pwgen2
cargo generate-rpm --arch ${{ matrix.rpm_arch }}
ls -alR target/generate-rpm # Check where the RPM is generated
RPM_PATH=$(find target/generate-rpm/ -name "*.rpm" -print -quit)
echo "RPM_ASSET=$RPM_PATH" >> $GITHUB_ENV
- name: Generate DEB
if: contains(matrix.target, 'linux')
run: |
cargo deb --no-build --target ${{ matrix.target }}
DEB_PATH="$(find target -type f -name '*.deb' -print -quit)"
echo "DEB_ASSET=$DEB_PATH" >> $GITHUB_ENV
echo "DEB: $DEB_PATH"
- name: Build archive
shell: bash
run: |
binary_name="pwgen2"
dirname="$binary_name-${{ env.VERSION }}-${{ matrix.target }}"
mkdir "$dirname"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
mv "target/${{ matrix.target }}/release/$binary_name.exe" "$dirname"
else
mv "target/${{ matrix.target }}/release/$binary_name" "$dirname"
fi
if [ "${{ matrix.os }}" = "windows-latest" ]; then
7z a "$dirname.zip" "$dirname"
echo "ASSET=$dirname.zip" >> $GITHUB_ENV
else
tar -czf "$dirname.tar.gz" "$dirname"
echo "ASSET=$dirname.tar.gz" >> $GITHUB_ENV
fi
- name: Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v3
with:
files: |-
${{ env.ASSET }}
${{ env.RPM_ASSET }}
${{ env.DEB_ASSET }}
publish:
name: Publish
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Checkout sources
uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- run: cargo publish --token ${CRATES_TOKEN}
env:
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}