- rewrite README for operator-first onboarding with clear goal/approach intro - expand scope section with concrete supported resources and workflows - add docs/operator-guide.md for runtime usage, navigation, logs, secrets, and troubleshooting - add docs/contributor-guide.md for engineering standards, validation, and release responsibilities - simplify CONTRIBUTING.md into a concise entrypoint that links to the detailed contributor guide - remove docs/status.md and drop update-status job from release workflow
418 lines
12 KiB
YAML
418 lines
12 KiB
YAML
name: Krust / Release
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: "Optional explicit version (e.g. 0.2.0 or v0.2.0)"
|
|
required: false
|
|
type: string
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
concurrency:
|
|
group: release-main
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
preflight:
|
|
name: Preflight release eligibility
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
release_enabled: ${{ steps.eval.outputs.release_enabled }}
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Evaluate docs-only change set
|
|
id: eval
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
|
echo "release_enabled=true" >> "${GITHUB_OUTPUT}"
|
|
exit 0
|
|
fi
|
|
|
|
BEFORE="${{ github.event.before }}"
|
|
AFTER="${{ github.sha }}"
|
|
if [[ -z "${BEFORE}" || "${BEFORE}" == "0000000000000000000000000000000000000000" ]]; then
|
|
BEFORE="$(git rev-parse "${AFTER}^" 2>/dev/null || true)"
|
|
fi
|
|
|
|
CHANGED="$(git diff --name-only "${BEFORE}" "${AFTER}" || true)"
|
|
echo "Changed files:"
|
|
echo "${CHANGED}"
|
|
|
|
NON_DOC="$(echo "${CHANGED}" | grep -Ev '^(docs/|.*\.md$)' || true)"
|
|
if [[ -z "${NON_DOC}" ]]; then
|
|
echo "Docs-only change set detected; release disabled."
|
|
echo "release_enabled=false" >> "${GITHUB_OUTPUT}"
|
|
else
|
|
echo "Non-doc changes detected; release enabled."
|
|
echo "release_enabled=true" >> "${GITHUB_OUTPUT}"
|
|
fi
|
|
|
|
prepare:
|
|
name: Validate + compute version
|
|
needs: preflight
|
|
if: ${{ needs.preflight.outputs.release_enabled == 'true' && (github.event_name != 'push' || (!contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'github-actions[bot]')) }}
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
tag: ${{ steps.version.outputs.tag }}
|
|
version: ${{ steps.version.outputs.version }}
|
|
release_sha: ${{ steps.tag.outputs.release_sha }}
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Install Rust
|
|
uses: dtolnay/rust-toolchain@stable
|
|
|
|
- name: Cache Rust artifacts
|
|
uses: Swatinem/rust-cache@v2
|
|
|
|
- name: Validate (fmt/check/test/build)
|
|
run: |
|
|
set -euo pipefail
|
|
cargo fmt --all -- --check
|
|
cargo check --locked
|
|
cargo test --locked
|
|
cargo build --release --locked
|
|
|
|
- name: Resolve next semver
|
|
id: version
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
normalize_tag() {
|
|
local raw="$1"
|
|
raw="${raw#refs/tags/}"
|
|
if [[ "${raw}" != v* ]]; then
|
|
raw="v${raw}"
|
|
fi
|
|
echo "${raw}"
|
|
}
|
|
|
|
explicit="${{ github.event.inputs.version }}"
|
|
if [[ -n "${explicit}" ]]; then
|
|
TAG="$(normalize_tag "${explicit}")"
|
|
if ! [[ "${TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then
|
|
echo "Invalid version: ${TAG}" >&2
|
|
exit 1
|
|
fi
|
|
VERSION="${TAG#v}"
|
|
BUMP_KIND="manual"
|
|
else
|
|
LAST_TAG="$(git tag --list 'v*.*.*' --sort=-version:refname | head -n1 || true)"
|
|
if [[ -z "${LAST_TAG}" ]]; then
|
|
BASE="0.0.0"
|
|
RANGE="HEAD"
|
|
else
|
|
BASE="${LAST_TAG#v}"
|
|
RANGE="${LAST_TAG}..HEAD"
|
|
fi
|
|
|
|
SUBJECTS="$(git log --format='%s' ${RANGE})"
|
|
FULL_LOG="$(git log --format='%s%n%b' ${RANGE})"
|
|
|
|
BUMP_KIND="patch"
|
|
if grep -Eq '(^|[[:space:]])BREAKING CHANGE:' <<<"${FULL_LOG}" || grep -Eq '^.+!:' <<<"${SUBJECTS}"; then
|
|
BUMP_KIND="major"
|
|
elif grep -Eq '^feat(\(.+\))?:' <<<"${SUBJECTS}"; then
|
|
BUMP_KIND="minor"
|
|
fi
|
|
|
|
IFS='.' read -r MAJOR MINOR PATCH <<<"${BASE}"
|
|
case "${BUMP_KIND}" in
|
|
major)
|
|
MAJOR=$((MAJOR + 1))
|
|
MINOR=0
|
|
PATCH=0
|
|
;;
|
|
minor)
|
|
MINOR=$((MINOR + 1))
|
|
PATCH=0
|
|
;;
|
|
patch)
|
|
PATCH=$((PATCH + 1))
|
|
;;
|
|
esac
|
|
|
|
VERSION="${MAJOR}.${MINOR}.${PATCH}"
|
|
TAG="v${VERSION}"
|
|
fi
|
|
|
|
echo "Resolved ${TAG} (${BUMP_KIND})"
|
|
echo "tag=${TAG}" >> "${GITHUB_OUTPUT}"
|
|
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
|
|
|
|
- name: Update Cargo version on main
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
VERSION="${{ steps.version.outputs.version }}"
|
|
|
|
current_version="$(sed -n '/^\[package\]/,/^\[/p' Cargo.toml | awk -F'"' '/^version = /{print $2; exit}')"
|
|
if [[ "${current_version}" == "${VERSION}" ]]; then
|
|
echo "Cargo.toml already at ${VERSION}"
|
|
exit 0
|
|
fi
|
|
|
|
awk -v v="${VERSION}" '
|
|
BEGIN { in_package = 0; updated = 0 }
|
|
/^\[package\]$/ { in_package = 1; print; next }
|
|
/^\[/ && $0 != "[package]" { in_package = 0 }
|
|
{
|
|
if (in_package && !updated && $1 == "version" && $2 == "=") {
|
|
print "version = \"" v "\""
|
|
updated = 1
|
|
next
|
|
}
|
|
print
|
|
}
|
|
' Cargo.toml > Cargo.toml.tmp
|
|
mv Cargo.toml.tmp Cargo.toml
|
|
|
|
# Keep Cargo.lock in sync with the bumped package version so downstream
|
|
# --locked builds do not fail.
|
|
cargo generate-lockfile --offline || cargo generate-lockfile
|
|
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
git add Cargo.toml Cargo.lock
|
|
if git diff --cached --quiet; then
|
|
echo "No Cargo manifest/lock changes to commit"
|
|
exit 0
|
|
fi
|
|
git commit -m "chore(release): v${VERSION} [skip ci]"
|
|
git push origin HEAD:main
|
|
|
|
- name: Create/push release tag
|
|
id: tag
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
TAG="${{ steps.version.outputs.tag }}"
|
|
git fetch --tags origin
|
|
|
|
RELEASE_SHA="$(git rev-parse HEAD)"
|
|
if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
|
|
EXISTING_SHA="$(git rev-list -n1 "${TAG}")"
|
|
if [[ "${EXISTING_SHA}" != "${RELEASE_SHA}" ]]; then
|
|
echo "Tag ${TAG} already exists on ${EXISTING_SHA}, expected ${RELEASE_SHA}" >&2
|
|
exit 1
|
|
fi
|
|
else
|
|
git tag "${TAG}" "${RELEASE_SHA}"
|
|
git push origin "refs/tags/${TAG}"
|
|
fi
|
|
|
|
echo "release_sha=${RELEASE_SHA}" >> "${GITHUB_OUTPUT}"
|
|
|
|
build:
|
|
name: Build ${{ matrix.target }}
|
|
needs: prepare
|
|
runs-on: ${{ matrix.os }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- os: ubuntu-latest
|
|
target: x86_64-unknown-linux-gnu
|
|
- os: macos-latest
|
|
target: x86_64-apple-darwin
|
|
- os: macos-latest
|
|
target: aarch64-apple-darwin
|
|
|
|
steps:
|
|
- name: Checkout release tag
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: refs/tags/${{ needs.prepare.outputs.tag }}
|
|
|
|
- name: Install Rust
|
|
uses: dtolnay/rust-toolchain@stable
|
|
|
|
- name: Add target
|
|
run: rustup target add ${{ matrix.target }}
|
|
|
|
- name: Cache Rust artifacts
|
|
uses: Swatinem/rust-cache@v2
|
|
|
|
- name: Build release binary
|
|
run: cargo build --release --locked --target ${{ matrix.target }}
|
|
|
|
- name: Package artifact
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
TARGET='${{ matrix.target }}'
|
|
PKG="krust-${TARGET}"
|
|
mkdir -p "dist/${PKG}"
|
|
cp "target/${TARGET}/release/krust" "dist/${PKG}/krust"
|
|
cp README.md LICENSE "dist/${PKG}/"
|
|
tar -C dist -czf "dist/${PKG}.tar.gz" "${PKG}"
|
|
|
|
- name: Upload build artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: package-${{ matrix.target }}
|
|
path: dist/krust-${{ matrix.target }}.tar.gz
|
|
if-no-files-found: error
|
|
|
|
publish:
|
|
name: Publish GitHub Release
|
|
needs: [prepare, build]
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout release tag
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: refs/tags/${{ needs.prepare.outputs.tag }}
|
|
|
|
- name: Download packaged artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
pattern: package-*
|
|
path: dist
|
|
merge-multiple: true
|
|
|
|
- name: Generate SHA256SUMS
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
cd dist
|
|
sha256sum *.tar.gz > SHA256SUMS
|
|
|
|
- name: Generate Homebrew formula
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
scripts/release/generate_homebrew_formula.sh \
|
|
--version "${{ needs.prepare.outputs.version }}" \
|
|
--checksums dist/SHA256SUMS \
|
|
--output dist/krust.rb
|
|
|
|
- name: Publish release assets
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
tag_name: ${{ needs.prepare.outputs.tag }}
|
|
name: ${{ needs.prepare.outputs.tag }}
|
|
target_commitish: ${{ needs.prepare.outputs.release_sha }}
|
|
generate_release_notes: true
|
|
overwrite_files: true
|
|
files: |
|
|
dist/*.tar.gz
|
|
dist/SHA256SUMS
|
|
dist/krust.rb
|
|
|
|
verify-release-assets:
|
|
name: Verify release assets
|
|
needs: [prepare, publish]
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Verify required assets exist on release
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
TAG: ${{ needs.prepare.outputs.tag }}
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
ASSETS="$(gh release view "${TAG}" --repo "${GITHUB_REPOSITORY}" --json assets --jq '.assets[].name')"
|
|
echo "Release assets:"
|
|
echo "${ASSETS}"
|
|
|
|
required=(
|
|
"krust-x86_64-unknown-linux-gnu.tar.gz"
|
|
"krust-x86_64-apple-darwin.tar.gz"
|
|
"krust-aarch64-apple-darwin.tar.gz"
|
|
"SHA256SUMS"
|
|
"krust.rb"
|
|
)
|
|
|
|
for item in "${required[@]}"; do
|
|
if ! grep -Fxq "${item}" <<<"${ASSETS}"; then
|
|
echo "Missing release asset: ${item}" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
sync-homebrew-tap:
|
|
name: Sync Homebrew tap
|
|
needs: [prepare, publish, verify-release-assets]
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout release tag
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: refs/tags/${{ needs.prepare.outputs.tag }}
|
|
|
|
- name: Download SHA256SUMS from release
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
TAG: ${{ needs.prepare.outputs.tag }}
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
mkdir -p dist
|
|
gh release download "${TAG}" \
|
|
--repo "${GITHUB_REPOSITORY}" \
|
|
--pattern "SHA256SUMS" \
|
|
--dir dist
|
|
|
|
- name: Generate formula
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
scripts/release/generate_homebrew_formula.sh \
|
|
--version "${{ needs.prepare.outputs.version }}" \
|
|
--checksums dist/SHA256SUMS \
|
|
--output dist/krust.rb
|
|
|
|
- name: Push formula to tap
|
|
env:
|
|
TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
|
|
TAP_REPO: ErfanY/homebrew-krust
|
|
VERSION: ${{ needs.prepare.outputs.version }}
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
if [[ -z "${TAP_TOKEN}" ]]; then
|
|
echo "Missing HOMEBREW_TAP_GITHUB_TOKEN secret" >&2
|
|
exit 1
|
|
fi
|
|
|
|
git clone "https://x-access-token:${TAP_TOKEN}@github.com/${TAP_REPO}.git" tap
|
|
mkdir -p tap/Formula
|
|
cp dist/krust.rb tap/Formula/krust.rb
|
|
|
|
cd tap
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
|
|
if git diff --quiet -- Formula/krust.rb; then
|
|
echo "No tap update required"
|
|
exit 0
|
|
fi
|
|
|
|
git add Formula/krust.rb
|
|
git commit -m "krust ${VERSION}"
|
|
git push
|