Skip to content

Build & Release

Build & Release #5

Workflow file for this run

name: Build & Release PyElevate
on:
workflow_dispatch:
permissions:
contents: write
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.v.outputs.version }}
steps:
- uses: actions/checkout@v4
- id: v
run: |
V=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "version=$V" >> $GITHUB_OUTPUT
build:
needs: version
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
osname: linux
- os: windows-latest
target: x86_64-pc-windows-msvc
osname: windows
- os: macos-latest
target: aarch64-apple-darwin
osname: macos-arm64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: rustup target add ${{ matrix.target }}
- run: cargo build --release --target ${{ matrix.target }}
- name: Package Binary
shell: bash
run: |
VERSION=${{ needs.version.outputs.version }}
BIN=pyelevate
EXT=""
if [ "${{ runner.os }}" = "Windows" ]; then EXT=".exe"; fi
NAME=pyelevate-v${VERSION}-${{ matrix.osname }}
mkdir -p pkg
cp target/${{ matrix.target }}/release/$BIN$EXT pkg/
if [ "${{ runner.os }}" = "Windows" ]; then
powershell Compress-Archive -Path pkg\$BIN$EXT -DestinationPath $NAME.zip
certutil -hashfile $NAME.zip SHA256 | head -1 > $NAME.sha256
else
tar -cJf $NAME.tar.xz -C pkg $BIN$EXT
shasum -a 256 $NAME.tar.xz > $NAME.sha256
fi
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.osname }}
path: |
*.zip
*.tar.xz
*.sha256
changelog:
needs: version
runs-on: ubuntu-latest
outputs:
notes: ${{ steps.cliff.outputs.notes }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install git-cliff (native, no Docker)
run: |
curl -sL https://github.com/orhun/git-cliff/releases/latest/download/git-cliff-x86_64-unknown-linux-gnu.tar.gz \
| tar -xz
sudo mv git-cliff /usr/local/bin/
- name: Generate changelog
id: cliff
run: |
git-cliff --config cliff.toml --latest --strip header > CHANGELOG_GENERATED.md
echo "notes<<EOF" >> $GITHUB_OUTPUT
cat CHANGELOG_GENERATED.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
release:
needs: [version, build, changelog]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
- uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.version.outputs.version }}
name: PyElevate v${{ needs.version.outputs.version }}
body: ${{ needs.changelog.outputs.notes }}
files: artifacts/**/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}