Release #17
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: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version tag to create and release (e.g. v1.2.3)' | |
| required: true | |
| type: string | |
| concurrency: | |
| group: release | |
| cancel-in-progress: false | |
| jobs: | |
| tag: | |
| name: Create and Push Tag | |
| if: github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Validate version format | |
| env: | |
| VERSION: ${{ github.event.inputs.version }} | |
| run: | | |
| if ! echo "$VERSION" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then | |
| echo "ERROR: Version must match vX.Y.Z format (e.g. v1.2.3)" | |
| exit 1 | |
| fi | |
| - name: Verify tag does not already exist | |
| env: | |
| VERSION: ${{ github.event.inputs.version }} | |
| run: | | |
| if git ls-remote --tags origin "refs/tags/$VERSION" | grep -qF "$VERSION"; then | |
| echo "ERROR: Tag $VERSION already exists on remote. Aborting." | |
| exit 1 | |
| fi | |
| - name: Create and push tag | |
| env: | |
| VERSION: ${{ github.event.inputs.version }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag "$VERSION" | |
| git push origin "$VERSION" | |
| test: | |
| name: Test (${{ matrix.os }}) | |
| needs: [tag] | |
| if: "!cancelled() && (needs.tag.result == 'success' || needs.tag.result == 'skipped')" | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust stable | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: rustfmt, clippy | |
| - uses: Swatinem/rust-cache@v2 | |
| - name: Check formatting | |
| run: cargo fmt --check | |
| - name: Clippy | |
| run: cargo clippy -- -D warnings | |
| - name: Test | |
| run: cargo test | |
| build: | |
| name: Build (${{ matrix.target }}) | |
| needs: test | |
| runs-on: ${{ matrix.runner }} | |
| strategy: | |
| matrix: | |
| include: | |
| - target: aarch64-apple-darwin | |
| runner: macos-latest | |
| - target: x86_64-apple-darwin | |
| runner: macos-latest | |
| - target: x86_64-unknown-linux-musl | |
| runner: ubuntu-latest | |
| - target: aarch64-unknown-linux-musl | |
| runner: ubuntu-24.04-arm | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust stable | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install musl tools (Linux) | |
| if: contains(matrix.target, 'linux-musl') | |
| run: sudo apt-get install -y musl-tools | |
| - uses: Swatinem/rust-cache@v2 | |
| - name: Build release binary | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Rename binary | |
| run: cp target/${{ matrix.target }}/release/cship cship-${{ matrix.target }} | |
| - name: Validate binary | |
| run: | | |
| file cship-${{ matrix.target }} | |
| test -s cship-${{ matrix.target }} || { echo "ERROR: binary is empty"; exit 1; } | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: cship-${{ matrix.target }} | |
| path: cship-${{ matrix.target }} | |
| release: | |
| name: Publish GitHub Release | |
| needs: build | |
| if: "!cancelled() && needs.build.result == 'success'" | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| - uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.event.inputs.version || github.ref_name }} | |
| files: cship-*/cship-* | |
| publish: | |
| name: Publish to crates.io | |
| needs: release | |
| if: "!cancelled() && needs.release.result == 'success'" | |
| runs-on: ubuntu-latest | |
| permissions: {} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.inputs.version || github.ref_name }} | |
| - name: Install Rust stable | |
| uses: dtolnay/rust-toolchain@stable | |
| - uses: Swatinem/rust-cache@v2 | |
| - name: Publish to crates.io | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| run: cargo publish |