buster/.github/workflows/cli-release.yml

341 lines
14 KiB
YAML

name: CLI Release
on:
workflow_run:
workflows: ["Manage Versions"] # Name of the manage-versions.yml workflow
types:
- completed
# Add permissions for creating releases
permissions:
contents: write
pull-requests: write # May not be needed if PRs don't trigger this directly
jobs:
build:
if: github.event.workflow_run.conclusion == 'success'
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: buster-cli-linux-x86_64.tar.gz
use_tar: true
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: buster-cli-darwin-x86_64.tar.gz
use_tar: true
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: buster-cli-darwin-arm64.tar.gz
use_tar: true
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: buster-cli-windows-x86_64.zip
use_tar: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }} # Checkout the commit from the completed manage-versions run
fetch-depth: 0 # Important for release notes generation
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
profile: minimal
override: true
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
- name: Configure Cargo for optimized build
run: |
mkdir -p .cargo
echo '[profile.release]' > .cargo/config.toml
echo 'lto = true' >> .cargo/config.toml
echo 'codegen-units = 1' >> .cargo/config.toml
echo 'panic = "abort"' >> .cargo/config.toml
echo 'opt-level = 3' >> .cargo/config.toml
echo 'strip = true' >> .cargo/config.toml
- name: Build optimized release
working-directory: ./cli # Assuming this is the workspace root for the cli crate
# If your CLI project is in cli/cli, adjust working-directory to ./cli/cli
run: cargo build --release --target ${{ matrix.target }} --manifest-path ./cli/Cargo.toml
- name: Determine Binary Name and Path
id: binary_info
shell: bash
run: |
CRATE_NAME=$(basename $(find cli/target/${{ matrix.target }}/release -maxdepth 1 -type f -executable ! -name '*.dSYM' ! -name '*.pdb'))
echo "CRATE_NAME=$CRATE_NAME"
echo "Binary name: $CRATE_NAME"
echo "binary_name=$CRATE_NAME" >> $GITHUB_OUTPUT
echo "binary_path=cli/target/${{ matrix.target }}/release/$CRATE_NAME"
echo "binary_path_val=cli/target/${{ matrix.target }}/release/$CRATE_NAME" >> $GITHUB_OUTPUT
- name: Compress binary (Unix)
if: matrix.use_tar
shell: bash
run: |
cd cli/target/${{ matrix.target }}/release
tar czf ${{ matrix.artifact_name }} ${{ steps.binary_info.outputs.binary_name }}
if [[ "${{ runner.os }}" == "macOS" ]]; then
shasum -a 256 ${{ matrix.artifact_name }} > ${{ matrix.artifact_name }}.sha256
else
sha256sum ${{ matrix.artifact_name }} > ${{ matrix.artifact_name }}.sha256
fi
- name: Compress binary (Windows)
if: matrix.use_tar == false
shell: pwsh
run: |
cd cli/target/${{ matrix.target }}/release
Compress-Archive -Path ${{ steps.binary_info.outputs.binary_name }}.exe -DestinationPath ${{ matrix.artifact_name }}
Get-FileHash -Algorithm SHA256 ${{ matrix.artifact_name }} | Select-Object -ExpandProperty Hash > ${{ matrix.artifact_name }}.sha256
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: buster-cli-${{ matrix.target }}
path: |
cli/target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
cli/target/${{ matrix.target }}/release/${{ matrix.artifact_name }}.sha256
retention-days: 1
release:
needs: build
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
outputs:
release_tag: ${{ steps.get_tag_info.outputs.cli_tag_name }}
release_version: ${{ steps.get_tag_info.outputs.cli_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
fetch-depth: 0
- name: Download Tag Information Artifact from Manage Versions workflow
uses: actions/download-artifact@v4
with:
name: version-tag-info
github-token: ${{ secrets.GITHUB_TOKEN }} # Token to download artifact from another workflow run
run-id: ${{ github.event.workflow_run.id }}
- name: Extract CLI Tag and Version from Artifact
id: get_tag_info
shell: bash
run: |
if [ ! -f tag_info.json ]; then
echo "tag_info.json not found. This might happen if no tags were created by the Manage Versions workflow."
# Decide if this is a critical failure or if the workflow should exit gracefully
# For now, we'll set outputs to empty and let downstream steps handle it (e.g. Create Release might skip)
echo "cli_tag_name=" >> $GITHUB_OUTPUT
echo "cli_version=" >> $GITHUB_OUTPUT
exit 0 # Exit gracefully to allow other jobs or steps to evaluate
fi
CLI_TAG_NAME=$(jq -r '.cli_tag // empty' tag_info.json)
if [ -z "$CLI_TAG_NAME" ] || [ "$CLI_TAG_NAME" == "null" ]; then
echo "CLI tag not found in tag_info.json or is null."
# As above, decide on failure or graceful exit
echo "cli_tag_name=" >> $GITHUB_OUTPUT
echo "cli_version=" >> $GITHUB_OUTPUT
exit 0 # Exit gracefully
fi
# Extract version from the tag name (e.g., cli/v1.2.3 -> 1.2.3)
CLI_VERSION=$(echo "$CLI_TAG_NAME" | sed 's#^cli/v##')
echo "cli_tag_name=$CLI_TAG_NAME" >> $GITHUB_OUTPUT
echo "cli_version=$CLI_VERSION" >> $GITHUB_OUTPUT
echo "Extracted CLI Tag: $CLI_TAG_NAME, CLI Version: $CLI_VERSION"
- name: Download build artifacts
uses: actions/download-artifact@v4
# No specific path needed, it downloads all to a directory named after the artifact
- name: Create Release
if: steps.get_tag_info.outputs.cli_tag_name != '' # Only run if a CLI tag was found
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_tag_info.outputs.cli_tag_name }}
name: CLI Release v${{ steps.get_tag_info.outputs.cli_version }}
files: |
**/buster-cli-linux-x86_64.tar.gz
**/buster-cli-linux-x86_64.tar.gz.sha256
**/buster-cli-darwin-x86_64.tar.gz
**/buster-cli-darwin-x86_64.tar.gz.sha256
**/buster-cli-darwin-arm64.tar.gz
**/buster-cli-darwin-arm64.tar.gz.sha256
**/buster-cli-windows-x86_64.zip
**/buster-cli-windows-x86_64.zip.sha256
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-homebrew-tap:
name: Update Homebrew Tap
needs: release
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success' && needs.release.outputs.release_tag != '' # Run only if Manage Versions succeeded and a CLI tag was processed
steps:
- name: Get release version and tag from previous job
id: release_info
run: |
echo "RELEASE_VERSION=${{ needs.release.outputs.release_version }}" >> $GITHUB_ENV
echo "RELEASE_TAG=${{ needs.release.outputs.release_tag }}" >> $GITHUB_ENV
echo "Using version: ${{ needs.release.outputs.release_version }} from tag: ${{ needs.release.outputs.release_tag }}"
- name: Set up GitHub CLI
uses: actions/setup-node@v4 # gh is often bundled, but this ensures it's available or can be installed
with:
node-version: '20' # Or any version that ensures gh is available
- name: Download SHA256 sums from GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Use GITHUB_TOKEN to interact with the current repo's release
GH_REPO: ${{ github.repository }}
run: |
gh release download ${{ env.RELEASE_TAG }} --pattern '*.sha256' -R $GH_REPO
echo "Downloaded SHA256 files:"
ls -la *.sha256
SHA_ARM64=$(cat buster-cli-darwin-arm64.tar.gz.sha256 | awk '{print $1}')
SHA_INTEL=$(cat buster-cli-darwin-x86_64.tar.gz.sha256 | awk '{print $1}')
SHA_LINUX=$(cat buster-cli-linux-x86_64.tar.gz.sha256 | awk '{print $1}')
echo "SHA_ARM64=$SHA_ARM64" >> $GITHUB_ENV
echo "SHA_INTEL=$SHA_INTEL" >> $GITHUB_ENV
echo "SHA_LINUX=$SHA_LINUX" >> $GITHUB_ENV
echo "ARM64 SHA: $SHA_ARM64"
echo "Intel SHA: $SHA_INTEL"
echo "Linux SHA: $SHA_LINUX"
- name: Checkout Homebrew tap repository
uses: actions/checkout@v4
with:
repository: buster-so/buster-homebrew
token: ${{ secrets.HOMEBREW_TAP_TOKEN }} # PAT with repo scope for buster-so/buster-homebrew
path: buster-homebrew # Checkout to a specific path
- name: Configure Git
working-directory: ./buster-homebrew
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Update Homebrew Formula
working-directory: ./buster-homebrew
env:
VERSION: ${{ env.RELEASE_VERSION }}
TAG: ${{ env.RELEASE_TAG }}
SHA_ARM64: ${{ env.SHA_ARM64 }}
SHA_INTEL: ${{ env.SHA_INTEL }}
SHA_LINUX: ${{ env.SHA_LINUX }}
run: |
FORMULA_FILE="Formula/buster.rb"
TEMP_FORMULA_FILE="Formula/buster.rb.tmp"
# URLs for artifacts
URL_BASE="https://github.com/${{ github.repository_owner }}/buster/releases/download/$TAG"
URL_ARM64="$URL_BASE/buster-cli-darwin-arm64.tar.gz"
URL_INTEL="$URL_BASE/buster-cli-darwin-x86_64.tar.gz"
URL_LINUX="$URL_BASE/buster-cli-linux-x86_64.tar.gz"
echo "Updating $FORMULA_FILE with Version: $VERSION"
echo "ARM64 URL: $URL_ARM64, SHA: $SHA_ARM64"
echo "Intel URL: $URL_INTEL, SHA: $SHA_INTEL"
echo "Linux URL: $URL_LINUX, SHA: $SHA_LINUX"
# Update version
sed "s/^ version .*/ version \\"$VERSION\\"/" "$FORMULA_FILE" > "$TEMP_FORMULA_FILE" && mv "$TEMP_FORMULA_FILE" "$FORMULA_FILE"
# Update top-level (defaults to ARM usually, as per your formula)
sed -E "s#^ url .*# url \\"$URL_ARM64\\"#" "$FORMULA_FILE" > "$TEMP_FORMULA_FILE" && mv "$TEMP_FORMULA_FILE" "$FORMULA_FILE"
sed "s/^ sha256 .*/ sha256 \\"$SHA_ARM64\\"/" "$FORMULA_FILE" > "$TEMP_FORMULA_FILE" && mv "$TEMP_FORMULA_FILE" "$FORMULA_FILE"
# Update on_macos -> on_arm
# Use a block to target sed within the on_arm block. Delimit with unique markers.
awk '
BEGIN { printing = 1; in_arm_block = 0; }
/on_macos do/,/end/ {
if (/on_arm do/) { in_arm_block = 1; }
if (in_arm_block && /url /) {
print " url \\"\\"" ENVIRON["URL_ARM64"] "\\"\\""
next
}
if (in_arm_block && /sha256 /) {
print " sha256 \\"\\"" ENVIRON["SHA_ARM64"] "\\"\\""
next
}
if (in_arm_block && /end/) { in_arm_block = 0; }
}
{ print }
' "$FORMULA_FILE" > "$TEMP_FORMULA_FILE" && mv "$TEMP_FORMULA_FILE" "$FORMULA_FILE"
# Update on_macos -> on_intel
awk '
BEGIN { printing = 1; in_intel_block = 0; }
/on_macos do/,/end/ {
if (/on_intel do/) { in_intel_block = 1; }
if (in_intel_block && /url /) {
print " url \\"\\"" ENVIRON["URL_INTEL"] "\\"\\""
next
}
if (in_intel_block && /sha256 /) {
print " sha256 \\"\\"" ENVIRON["SHA_INTEL"] "\\"\\""
next
}
if (in_intel_block && /end/) { in_intel_block = 0; }
}
{ print }
' "$FORMULA_FILE" > "$TEMP_FORMULA_FILE" && mv "$TEMP_FORMULA_FILE" "$FORMULA_FILE"
# Update on_linux
awk '
BEGIN { printing = 1; in_linux_block = 0; }
/on_linux do/,/end/ {
if (/url / && !in_linux_block) { next } # Skip top-level url if not already processed
if (/on_linux do/) { in_linux_block = 1; }
if (in_linux_block && /url /) {
print " url \\"\\"" ENVIRON["URL_LINUX"] "\\"\\""
next
}
if (in_linux_block && /sha256 /) {
print " sha256 \\"\\"" ENVIRON["SHA_LINUX"] "\\"\\""
next
}
if (in_linux_block && /end/) { in_linux_block = 0; }
}
{ print }
' "$FORMULA_FILE" > "$TEMP_FORMULA_FILE" && mv "$TEMP_FORMULA_FILE" "$FORMULA_FILE"
echo "--- Formula file after updates ---"
cat "$FORMULA_FILE"
echo "--- End of formula file ---"
- name: Commit and push changes to Homebrew tap
working-directory: ./buster-homebrew
run: |
git add Formula/buster.rb
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No changes to commit to Homebrew tap."
else
git commit -m "Update buster formula to version ${{ env.RELEASE_VERSION }}
[skip ci]"
git push
echo "Pushed updated formula to buster-so/buster-homebrew."
fi