name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Release version (e.g. v0.1.0)"
required: true
type: string
env:
CARGO_TERM_COLOR: always
BINARY_NAME: ploit-malper
permissions:
contents: write
jobs:
build:
name: Build ${{ matrix.target }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
archive: tar.gz
ext: ""
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
archive: tar.gz
ext: ""
- target: aarch64-apple-darwin
os: macos-latest
archive: tar.gz
ext: ""
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: zip
ext: ".exe"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: ${{ matrix.target }}
- name: Install cross
if: runner.os == 'Linux'
run: cargo install cross --locked
- name: Build
shell: bash
run: |
set -euo pipefail
if [[ "${{ runner.os }}" == "Linux" ]]; then
cross build --release --target ${{ matrix.target }}
else
cargo build --release --target ${{ matrix.target }}
fi
- name: Package
shell: bash
run: |
set -euo pipefail
BIN="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}${{ matrix.ext }}"
NAME="${{ env.BINARY_NAME }}-${{ inputs.version }}-${{ matrix.target }}"
if [ ! -f "$BIN" ]; then
echo "Binary not found!"
ls -R target
exit 1
fi
mkdir -p package
cp "$BIN" package/
if [ "${{ matrix.archive }}" = "zip" ]; then
cd package
7z a "../${NAME}.zip" *
cd ..
echo "ARCHIVE=${NAME}.zip" >> "$GITHUB_ENV"
else
tar -czf "${NAME}.tar.gz" -C package .
echo "ARCHIVE=${NAME}.tar.gz" >> "$GITHUB_ENV"
fi
- uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCHIVE }}
path: ${{ env.ARCHIVE }}
checksums:
name: SHA256 Checksums
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Generate checksums
shell: bash
run: |
set -euo pipefail
find artifacts -type f -exec sha256sum {} \; | sed 's|artifacts/||' > SHA256SUMS.txt
cat SHA256SUMS.txt
- uses: actions/upload-artifact@v4
with:
name: SHA256SUMS
path: SHA256SUMS.txt
release:
name: Publish GitHub Release
needs:
- build
- checksums
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Prepare release files
shell: bash
run: |
set -euo pipefail
mkdir -p dist
find artifacts -type f -exec cp {} dist/ \;
ls -lah dist
- name: Publish Release
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
gh release create "${{ inputs.version }}" \
--title "${{ inputs.version }}" \
--generate-notes \
dist/*