Build & Release #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Release App | |
| on: | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: release-${{ github.ref }} | |
| cancel-in-progress: true | |
| 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 | |
| changelog: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install git-cliff | |
| run: | | |
| VERSION=$(gh release view --repo orhun/git-cliff --json tagName -q .tagName) | |
| curl -sL "https://github.com/orhun/git-cliff/releases/download/${VERSION}/git-cliff-${VERSION}-x86_64-unknown-linux-gnu.tar.gz" | tar -xz | |
| sudo mv git-cliff /usr/local/bin/ | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Generate changelog | |
| run: git-cliff -o CHANGELOG.md | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: changelog | |
| path: CHANGELOG.md | |
| build: | |
| needs: version | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| bin: pyelevate | |
| osname: linux | |
| ext: "" | |
| pack: tar | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| bin: pyelevate.exe | |
| osname: windows | |
| ext: ".exe" | |
| pack: zip | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| bin: pyelevate | |
| osname: macos-arm64 | |
| ext: "" | |
| pack: tar | |
| 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: Ensure zip exists | |
| if: matrix.os == 'windows-latest' | |
| run: choco install zip -y | |
| - name: Package | |
| shell: bash | |
| run: | | |
| NAME=pyelevate-v${{ needs.version.outputs.version }}-${{ matrix.osname }} | |
| mkdir pkg | |
| cp target/${{ matrix.target }}/release/${{ matrix.bin }} pkg/pyelevate${{ matrix.ext }} | |
| if [ "${{ matrix.pack }}" = "zip" ]; then | |
| cd pkg && zip -9 ../$NAME.zip * | |
| else | |
| tar -C pkg -cJf $NAME.tar.xz . | |
| fi | |
| sha256sum $NAME.* > $NAME.sha256 | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.osname }} | |
| path: | | |
| *.zip | |
| *.tar.xz | |
| *.sha256 | |
| 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_path: artifacts/changelog/CHANGELOG.md | |
| files: artifacts/**/* | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |