name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 1.2.3)'
required: true
env:
PROJECT_NAME: spark-connect
jobs:
get-version:
if: github.ref == 'refs/heads/release'
name: Get Version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract_version.outputs.version }}
steps:
- name: Validate input format
run: |
VERSION="${{ github.event.inputs.version }}"
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ Invalid version format: $VERSION. Expected something like 1.2.3"
exit 1
fi
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Verify tag exists
run: |
VERSION="${{ github.event.inputs.version }}"
if git rev-parse "refs/tags/v$VERSION" >/dev/null 2>&1; then
echo "✅ Tag v$VERSION exists"
else
echo "❌ Tag v$VERSION does not exist in the repo"
exit 1
fi
- name: Extract version from input
id: extract_version
run: |
VERSION="${{ github.event.inputs.version }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
promote-release:
name: Promote Draft Release and Publish Crate
needs: get-version
runs-on: ubuntu-latest
permissions:
contents: write id-token: write
environment: release
steps:
- name: Create draft release
uses: softprops/action-gh-release@v2
with:
name: "${{ env.PROJECT_NAME }} v${{ needs.get-version.outputs.version }}"
tag_name: v${{ needs.get-version.outputs.version }}
draft: false
make_latest: true
- name: Checkout version
uses: actions/checkout@v4
with:
ref: "v${{ needs.get-version.outputs.version }}"
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Install protoc to compile protobuf
run: sudo apt update && sudo apt install -y protobuf-compiler
- name: Publish crate
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish