Skip to content

Release

Release #24

Workflow file for this run

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, windows-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
- target: x86_64-pc-windows-msvc
runner: windows-latest
- target: aarch64-pc-windows-msvc
runner: windows-11-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
shell: bash
run: |
EXT=""
if [[ "${{ matrix.target }}" == *windows* ]]; then EXT=".exe"; fi
cp "target/${{ matrix.target }}/release/cship${EXT}" "cship-${{ matrix.target }}${EXT}"
- name: Validate binary
shell: bash
run: |
EXT=""
if [[ "${{ matrix.target }}" == *windows* ]]; then EXT=".exe"; fi
if [[ "${{ matrix.target }}" != *windows* ]]; then file "cship-${{ matrix.target }}"; fi
test -s "cship-${{ matrix.target }}${EXT}" || { 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/checkout@v4
with:
ref: ${{ github.event.inputs.version || github.ref_name }}
- uses: actions/download-artifact@v4
- name: Extract changelog for this release
shell: bash
env:
TAG: ${{ github.event.inputs.version || github.ref_name }}
run: |
VERSION="${TAG#v}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
echo "ERROR: Invalid version format: $TAG" >&2; exit 1
fi
awk -v ver="[$VERSION]" '
p && /^## \[/ { exit }
/^## / && index($0, ver) { p=1; next }
p { print }
' CHANGELOG.md > /tmp/release-notes.md
if [ ! -s /tmp/release-notes.md ]; then
echo "See commit history for changes in this release." > /tmp/release-notes.md
fi
- uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event.inputs.version || github.ref_name }}
files: cship-*/cship-*
body_path: /tmp/release-notes.md
generate_release_notes: true
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