Release #8
Workflow file for this run
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: Release | |
| on: | |
| push: | |
| paths: | |
| - 'Cargo.toml' | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| force: | |
| description: Force release regardless of version change | |
| type: boolean | |
| default: false | |
| jobs: | |
| check-version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version_changed: ${{ steps.check.outputs.changed }} | |
| version: ${{ steps.extract.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Check if version changed | |
| id: check | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.force }}" = "true" ]; then | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| elif git rev-parse HEAD^ >/dev/null 2>&1 && git diff HEAD^ HEAD -- Cargo.toml | grep -q '^[+-]version = '; then | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Extract version | |
| id: extract | |
| if: steps.check.outputs.changed == 'true' | |
| run: | | |
| VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| build: | |
| needs: check-version | |
| if: needs.check-version.outputs.version_changed == 'true' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-musl | |
| artifact_name: pik | |
| asset_name: pik-linux-x86_64 | |
| - os: macos-latest | |
| target: x86_64-apple-darwin | |
| artifact_name: pik | |
| asset_name: pik-macos-x86_64 | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| artifact_name: pik | |
| asset_name: pik-macos-aarch64 | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| artifact_name: pik.exe | |
| asset_name: pik-windows-x86_64.exe | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - uses: Swatinem/rust-cache@v2 | |
| - name: Install musl-tools | |
| if: matrix.os == 'ubuntu-latest' | |
| run: sudo apt-get install -y musl-tools | |
| - name: Build | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Strip binary | |
| if: matrix.os != 'windows-latest' | |
| run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }} | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.asset_name }} | |
| path: target/${{ matrix.target }}/release/${{ matrix.artifact_name }} | |
| release: | |
| needs: [check-version, build] | |
| if: needs.check-version.outputs.version_changed == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Create release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -e | |
| VERSION="${{ needs.check-version.outputs.version }}" | |
| if [ -z "$VERSION" ]; then | |
| echo "No version resolved — aborting" | |
| exit 1 | |
| fi | |
| if gh release view "v$VERSION" &>/dev/null; then | |
| echo "Release v$VERSION already exists — skipping" | |
| exit 0 | |
| fi | |
| gh release create "v$VERSION" --title "v$VERSION" --generate-notes | |
| shopt -s nullglob | |
| ASSETS=(artifacts/*/*) | |
| echo "Found ${#ASSETS[@]} artifacts:" | |
| for f in "${ASSETS[@]}"; do | |
| echo " - $f" | |
| done | |
| if [ "${#ASSETS[@]}" -eq 0 ]; then | |
| echo "No artifacts found to upload — failing" | |
| exit 1 | |
| fi | |
| FAILED=0 | |
| for f in "${ASSETS[@]}"; do | |
| dir=$(basename "$(dirname "$f")") | |
| echo "Uploading $f as $dir..." | |
| if ! gh release upload "v$VERSION" "$f#$dir" --clobber; then | |
| echo "Failed to upload $f" | |
| FAILED=1 | |
| fi | |
| done | |
| if [ "$FAILED" -eq 1 ]; then | |
| echo "One or more uploads failed" | |
| exit 1 | |
| fi | |