Skip to content

Release

Release #14

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
bump:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
dry_run:
description: 'Dry run (no publish, no git push, no release)'
required: false
default: false
type: boolean
jobs:
version:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
permissions:
contents: write
outputs:
version: ${{ steps.bump.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get current version
id: current
run: |
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Calculate new version
id: bump
env:
CURRENT_VERSION: ${{ steps.current.outputs.version }}
BUMP_TYPE: ${{ inputs.bump }}
run: |
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
case "$BUMP_TYPE" in
major) major=$((major + 1)); minor=0; patch=0 ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
esac
echo "version=${major}.${minor}.${patch}" >> $GITHUB_OUTPUT
- name: Update Cargo.toml
env:
NEW_VERSION: ${{ steps.bump.outputs.version }}
run: |
sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" Cargo.toml
- name: Update Cargo.lock
run: cargo update --workspace
- name: Show changes (dry run)
if: inputs.dry_run
run: |
echo "=== DRY RUN MODE ==="
echo "Would bump to version: ${{ steps.bump.outputs.version }}"
echo ""
echo "=== Cargo.toml changes ==="
git diff Cargo.toml
echo ""
echo "=== Would create tag: ${{ steps.bump.outputs.version }} ==="
- name: Commit and tag
if: ${{ !inputs.dry_run }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Cargo.toml Cargo.lock
git commit -m "Release ${{ steps.bump.outputs.version }}"
git tag "${{ steps.bump.outputs.version }}"
git push origin HEAD --tags
build:
needs: version
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: k8sql-linux-x86_64
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
name: k8sql-linux-aarch64
- target: x86_64-apple-darwin
os: macos-latest
name: k8sql-macos-x86_64
- target: aarch64-apple-darwin
os: macos-latest
name: k8sql-macos-aarch64
- target: x86_64-pc-windows-msvc
os: windows-latest
name: k8sql-windows-x86_64.exe
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.dry_run && github.ref || needs.version.outputs.version }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Rename binary (Unix)
if: runner.os != 'Windows'
run: mv target/${{ matrix.target }}/release/k8sql ${{ matrix.name }}
- name: Rename binary (Windows)
if: runner.os == 'Windows'
run: mv target/${{ matrix.target }}/release/k8sql.exe ${{ matrix.name }}
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: ${{ matrix.name }}
publish:
needs: version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.dry_run && github.ref || needs.version.outputs.version }}
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Publish to crates.io (dry run)
if: inputs.dry_run
run: cargo publish --dry-run
- name: Publish to crates.io
if: ${{ !inputs.dry_run }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish
release:
needs: [version, build, publish]
if: ${{ !inputs.dry_run }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.version.outputs.version }}
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Generate SHA256 checksums
run: |
cd artifacts
for file in k8sql-*; do
sha256sum "$file" > "$file.sha256"
echo "Generated checksum for $file:"
cat "$file.sha256"
done
cd ..
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.version.outputs.version }}
generate_release_notes: true
files: artifacts/*
dry-run-summary:
needs: [version, build, publish]
if: inputs.dry_run
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Generate SHA256 checksums
run: |
cd artifacts
for file in k8sql-*; do
sha256sum "$file" > "$file.sha256"
done
cd ..
- name: Summary
run: |
echo "=== DRY RUN COMPLETE ==="
echo ""
echo "Version: ${{ needs.version.outputs.version }}"
echo ""
echo "Built artifacts:"
ls -la artifacts/
echo ""
echo "Checksums:"
cat artifacts/*.sha256
echo ""
echo "To perform a real release, run without dry_run checked."