name: Release on: push: tags: - 'v*' workflow_dispatch: permissions: contents: write jobs: build: name: Build ${{ matrix.target }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: include: - os: ubuntu-latest target: x86_64-unknown-linux-gnu use_cross: false - os: ubuntu-latest target: x86_64-unknown-linux-musl use_cross: false - os: ubuntu-latest target: aarch64-unknown-linux-gnu use_cross: true - os: macos-latest target: x86_64-apple-darwin use_cross: false - os: macos-latest target: aarch64-apple-darwin use_cross: false - os: windows-latest target: x86_64-pc-windows-msvc use_cross: false steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.target }} - name: Install musl tools if: matrix.target == 'x86_64-unknown-linux-musl' run: sudo apt-get update && sudo apt-get install -y musl-tools - name: Install cross if: matrix.use_cross run: cargo install cross --git https://github.com/cross-rs/cross - uses: Swatinem/rust-cache@v2 with: key: ${{ matrix.target }} - name: Build run: | if [ "${{ matrix.use_cross }}" == "true" ]; then cross build --release --locked --target ${{ matrix.target }} else cargo build --release --locked --target ${{ matrix.target }} fi shell: bash - name: Get binary name id: binary run: | name=$(grep '^name = ' Cargo.toml | head -1 | cut -d'"' -f2) if [ "${{ runner.os }}" == "Windows" ]; then echo "name=${name}.exe" >> $GITHUB_OUTPUT else echo "name=${name}" >> $GITHUB_OUTPUT fi shell: bash - name: Strip binary if: runner.os != 'Windows' run: strip target/${{ matrix.target }}/release/${{ steps.binary.outputs.name }} - name: Package id: package run: | name=$(grep '^name = ' Cargo.toml | head -1 | cut -d'"' -f2) target="${{ matrix.target }}" binary="${{ steps.binary.outputs.name }}" cd target/${target}/release if [ "${{ runner.os }}" == "Windows" ]; then archive="${name}-${target}.zip" 7z a ../../../${archive} ${binary} echo "archive=${archive}" >> $GITHUB_OUTPUT else archive="${name}-${target}.tar.gz" tar czf ../../../${archive} ${binary} echo "archive=${archive}" >> $GITHUB_OUTPUT fi shell: bash - uses: actions/upload-artifact@v4 with: name: ${{ matrix.target }} path: ${{ steps.package.outputs.archive }} release: name: Release needs: build runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: actions/download-artifact@v4 with: path: artifacts - name: Generate changelog run: | if [ -n "$(git tag --sort=-creatordate | head -n 2 | tail -n 1)" ]; then prev_tag=$(git tag --sort=-creatordate | head -n 2 | tail -n 1) git log ${prev_tag}..HEAD --pretty=format:"- %s" > CHANGELOG.md else echo "Initial release" > CHANGELOG.md fi - uses: softprops/action-gh-release@v2 with: body_path: CHANGELOG.md files: artifacts/**/* env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}