Release #15
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: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Release version (e.g. 0.2.0)' | |
| required: true | |
| type: string | |
| push: | |
| tags: | |
| - 'v*' | |
| permissions: | |
| contents: write | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| prepare: | |
| name: Prepare release tag | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'workflow_dispatch' | |
| outputs: | |
| tag: v${{ github.event.inputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Create and push tag | |
| run: | | |
| git tag "v${{ github.event.inputs.version }}" | |
| git push origin "v${{ github.event.inputs.version }}" | |
| build: | |
| name: Build (${{ matrix.target }}) | |
| needs: [prepare] | |
| if: always() && (needs.prepare.result == 'success' || needs.prepare.result == 'skipped') | |
| runs-on: ${{ matrix.os }} | |
| outputs: | |
| release_tag: ${{ needs.prepare.outputs.tag || github.ref_name }} | |
| env: | |
| RELEASE_TAG: ${{ needs.prepare.outputs.tag || github.ref_name }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| archive: tar.gz | |
| - target: aarch64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| archive: tar.gz | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| archive: tar.gz | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| archive: tar.gz | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross-compilation tools (aarch64-linux) | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu | |
| echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV | |
| - name: Cache cargo | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: ${{ matrix.target }}-cargo- | |
| - name: Build release binary | |
| run: cargo build --release --target ${{ matrix.target }} -p pipit-cli | |
| - name: Package archive | |
| shell: bash | |
| run: | | |
| TAG="${RELEASE_TAG}" | |
| ARCHIVE_NAME="pipit-${TAG}-${{ matrix.target }}" | |
| mkdir -p "${ARCHIVE_NAME}" | |
| cp "target/${{ matrix.target }}/release/pipit" "${ARCHIVE_NAME}/" | |
| cp LICENSE README.md "${ARCHIVE_NAME}/" | |
| tar czf "${ARCHIVE_NAME}.tar.gz" "${ARCHIVE_NAME}" | |
| echo "ARCHIVE=${ARCHIVE_NAME}.tar.gz" >> $GITHUB_ENV | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pipit-${{ matrix.target }} | |
| path: ${{ env.ARCHIVE }} | |
| release: | |
| name: Create GitHub Release | |
| needs: [prepare, build] | |
| if: always() && needs.build.result == 'success' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Collect archives | |
| run: | | |
| mkdir -p release | |
| find artifacts -name '*.tar.gz' -exec mv {} release/ \; | |
| ls -lh release/ | |
| - name: Generate checksums | |
| working-directory: release | |
| run: sha256sum *.tar.gz > SHA256SUMS | |
| - name: Create release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ needs.prepare.outputs.tag || github.ref_name }} | |
| generate_release_notes: true | |
| files: | | |
| release/*.tar.gz | |
| release/SHA256SUMS |