ok tag triggers

This commit is contained in:
dal 2025-05-06 18:23:43 -06:00
parent d3dc471327
commit 5ab8c65da4
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
6 changed files with 122 additions and 107 deletions

View File

@ -1,29 +1,18 @@
name: CLI Release
on:
workflow_run:
workflows: ["Manage Versions"]
types:
- completed
workflow_dispatch:
inputs:
manage_versions_run_id:
description: 'Run ID of the completed "Manage Versions" workflow (that produced version-tag-info artifact)'
required: true
type: string
checkout_sha:
description: 'Commit SHA to checkout (ideally the head_sha from the Manage Versions run)'
required: true
type: string
push:
tags:
- 'cli/v*' # Trigger on tags like cli/v1.2.3
# Add permissions for creating releases
permissions:
contents: write
pull-requests: write
# pull-requests: write # Not typically needed for a tag-triggered release workflow
jobs:
build:
if: (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || github.event_name == 'workflow_dispatch'
# No specific if condition needed here based on event, tag push is the trigger
strategy:
matrix:
include:
@ -45,11 +34,11 @@ jobs:
use_tar: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
- name: Checkout code at the specific tag
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.checkout_sha || github.event.workflow_run.head_sha }}
fetch-depth: 0
ref: ${{ github.ref }} # Checks out the specific tag that triggered the workflow
fetch-depth: 0 # Useful for some build processes or if release notes need history
- name: Install Rust
uses: actions-rs/toolchain@v1
@ -81,12 +70,34 @@ jobs:
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
# Ensure cli/target directory exists before find, in case of clean builds or different structures
mkdir -p cli/target/${{ matrix.target }}/release
CRATE_NAME_OUTPUT=$(basename $(find cli/target/${{ matrix.target }}/release -maxdepth 1 -type f -executable ! -name '*.dSYM' ! -name '*.pdb' 2>/dev/null || echo "buster")) # Default to buster if not found
# If find returns nothing (e.g. build failed or path is wrong), CRATE_NAME_OUTPUT could be empty or an error message.
# Fallback to a known name or fail if necessary. For now, using "buster" as a placeholder.
if [ -z "$CRATE_NAME_OUTPUT" ] || ! [ -f "cli/target/${{ matrix.target }}/release/$CRATE_NAME_OUTPUT" ]; then
echo "Warning: Could not automatically determine binary name. Assuming 'buster'."
# Attempt to find 'buster' or 'buster.exe' directly if primary find fails
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
CRATE_NAME_CANDIDATE="buster.exe"
else
CRATE_NAME_CANDIDATE="buster"
fi
if [ -f "cli/target/${{ matrix.target }}/release/$CRATE_NAME_CANDIDATE" ]; then
CRATE_NAME_OUTPUT=$CRATE_NAME_CANDIDATE
else
# If even the fallback isn't found, this will cause issues later.
# Consider failing the step: echo "Error: Binary not found."; exit 1
# For now, proceeding with a default name and letting later steps handle missing file
echo "Fallback binary '$CRATE_NAME_CANDIDATE' also not found. Proceeding with this name."
CRATE_NAME_OUTPUT=${CRATE_NAME_CANDIDATE%.exe} # Store without .exe for consistency if needed elsewhere
fi
fi
echo "CRATE_NAME=$CRATE_NAME_OUTPUT"
echo "Binary name: $CRATE_NAME_OUTPUT"
echo "binary_name=$CRATE_NAME_OUTPUT" >> $GITHUB_OUTPUT
echo "binary_path=cli/target/${{ matrix.target }}/release/$CRATE_NAME_OUTPUT"
echo "binary_path_val=cli/target/${{ matrix.target }}/release/$CRATE_NAME_OUTPUT" >> $GITHUB_OUTPUT
- name: Compress binary (Unix)
if: matrix.use_tar
@ -120,63 +131,44 @@ jobs:
release:
needs: build
runs-on: ubuntu-latest
if: (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || github.event_name == 'workflow_dispatch'
# No specific if condition needed here based on event, tag push is the trigger
outputs:
release_tag: ${{ steps.get_tag_info.outputs.cli_tag_name }}
release_version: ${{ steps.get_tag_info.outputs.cli_version }}
steps:
- name: Checkout code
- name: Checkout code at the specific tag
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.checkout_sha || github.event.workflow_run.head_sha }}
ref: ${{ github.ref }} # Checks out the specific tag that triggered the workflow
fetch-depth: 0
- name: Download Tag Information Artifact
uses: actions/download-artifact@v4
with:
name: version-tag-info
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.manage_versions_run_id || github.event.workflow_run.id }}
- name: Extract CLI Tag and Version from Artifact
- name: Extract CLI Tag and Version from Git Ref
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
CLI_TAG_NAME="${{ github.ref_name }}"
# Validate tag format if necessary (e.g., ensure it starts with cli/v)
if [[ ! "$CLI_TAG_NAME" =~ ^cli/v[0-9]+\.[0-9]+\.[0-9]+(.*)$ ]]; then
echo "Error: Tag $CLI_TAG_NAME does not match the expected format 'cli/vX.Y.Z'"
# exit 1 # Optionally fail the job
# For now, we'll proceed and let release creation fail if tag is not suitable
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"
echo "Extracted from Git Ref - 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
# if: steps.get_tag_info.outputs.cli_tag_name != '' # This check is implicitly handled by the tag trigger pattern
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_tag_info.outputs.cli_tag_name }}
tag_name: ${{ steps.get_tag_info.outputs.cli_tag_name }} # Should be same as github.ref_name
name: CLI Release v${{ steps.get_tag_info.outputs.cli_version }}
files: |
**/buster-cli-linux-x86_64.tar.gz
@ -197,7 +189,7 @@ jobs:
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
if: needs.release.outputs.release_tag != '' # Run only if a CLI tag was processed and release was attempted
steps:
- name: Get release version and tag from previous job
id: release_info

View File

@ -18,8 +18,10 @@ jobs:
if: startsWith(github.ref, 'refs/tags/api/v') # Trigger only for API tags
runs-on: blacksmith-32vcpu-ubuntu-2204 # Updated runner
steps:
- name: Checkout code
- name: Checkout code at the specific tag
uses: actions/checkout@v4
with:
ref: ${{ github.ref }} # Checks out the specific API tag
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
@ -28,16 +30,16 @@ jobs:
uses: docker/setup-buildx-action@v3
- name: Extract API version from Git tag
id: api_version
id: api_version_extractor # Renamed for clarity
run: |
# github.ref_name will be like "api/v1.2.3"
VERSION=$(echo "${{ github.ref_name }}" | sed 's#^api/v##')
if [ -z "$VERSION" ]; then
if [ -z "$VERSION" ]; then # Should not happen due to startsWith condition
echo "Could not extract version from tag: ${{ github.ref_name }}"
VERSION="unknown" # Fallback or fail: exit 1
VERSION="unknown"
fi
echo "API_VERSION=$VERSION" >> $GITHUB_ENV
echo "api_version=$VERSION" >> $GITHUB_OUTPUT
echo "API_VERSION_ENV=$VERSION" >> $GITHUB_ENV # Set for current job
echo "api_version_output=$VERSION" >> $GITHUB_OUTPUT # Output for other steps if needed
echo "Extracted API version: $VERSION"
shell: bash
@ -55,8 +57,8 @@ jobs:
file: ./api/Dockerfile # Assuming this Dockerfile is for api/server
push: true
tags: |
${{ env.DOCKER_REGISTRY_OWNER }}/${{ env.API_IMAGE_NAME }}:${{ steps.api_version.outputs.api_version }}
${{ env.DOCKER_REGISTRY_OWNER }}/${{ env.API_IMAGE_NAME }}:${{ github.sha }} # Consider if SHA tag is still needed or if component-specific SHA makes sense
${{ env.DOCKER_REGISTRY_OWNER }}/${{ env.API_IMAGE_NAME }}:${{ env.API_VERSION_ENV }}
${{ env.DOCKER_REGISTRY_OWNER }}/${{ env.API_IMAGE_NAME }}:${{ github.sha }} # SHA of the tag commit
${{ env.DOCKER_REGISTRY_OWNER }}/${{ env.API_IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
@ -66,8 +68,10 @@ jobs:
if: startsWith(github.ref, 'refs/tags/web/v') # Trigger only for Web tags
runs-on: blacksmith-32vcpu-ubuntu-2204 # Updated runner
steps:
- name: Checkout code
- name: Checkout code at the specific tag
uses: actions/checkout@v4
with:
ref: ${{ github.ref }} # Checks out the specific Web tag
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
@ -76,16 +80,16 @@ jobs:
uses: docker/setup-buildx-action@v3
- name: Extract Web version from Git tag
id: web_version
id: web_version_extractor # Renamed for clarity
run: |
# github.ref_name will be like "web/v1.2.3"
VERSION=$(echo "${{ github.ref_name }}" | sed 's#^web/v##')
if [ -z "$VERSION" ]; then
if [ -z "$VERSION" ]; then # Should not happen due to startsWith condition
echo "Could not extract version from tag: ${{ github.ref_name }}"
VERSION="unknown" # Fallback or fail: exit 1
VERSION="unknown"
fi
echo "WEB_VERSION=$VERSION" >> $GITHUB_ENV
echo "web_version=$VERSION" >> $GITHUB_OUTPUT
echo "WEB_VERSION_ENV=$VERSION" >> $GITHUB_ENV # Set for current job
echo "web_version_output=$VERSION" >> $GITHUB_OUTPUT # Output for other steps if needed
echo "Extracted Web version: $VERSION"
shell: bash
@ -103,8 +107,8 @@ jobs:
file: ./web/Dockerfile
push: true
tags: |
${{ env.DOCKER_REGISTRY_OWNER }}/${{ env.WEB_IMAGE_NAME }}:${{ steps.web_version.outputs.web_version }}
${{ env.DOCKER_REGISTRY_OWNER }}/${{ env.WEB_IMAGE_NAME }}:${{ github.sha }} # Consider if SHA tag is still needed
${{ env.DOCKER_REGISTRY_OWNER }}/${{ env.WEB_IMAGE_NAME }}:${{ env.WEB_VERSION_ENV }}
${{ env.DOCKER_REGISTRY_OWNER }}/${{ env.WEB_IMAGE_NAME }}:${{ github.sha }} # SHA of the tag commit
${{ env.DOCKER_REGISTRY_OWNER }}/${{ env.WEB_IMAGE_NAME }}:latest
build-args: |
NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}

View File

@ -1,6 +1,10 @@
name: Manage Versions
on:
pull_request:
types: [closed]
branches:
- main
workflow_dispatch:
inputs:
component:
@ -18,9 +22,6 @@ on:
required: true
default: 'patch'
type: string
pull_request:
branches:
- evals # Target the 'evals' branch
permissions:
contents: write # To push commits and tags
@ -28,34 +29,41 @@ permissions:
jobs:
bump_versions:
runs-on: blacksmith
# Updated condition to run if PR is opened or on workflow_dispatch
if: github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request'
if: (github.event_name == 'pull_request' && github.event.pull_request.merged == true) || github.event_name == 'workflow_dispatch'
outputs:
new_api_version: ${{ steps.bump.outputs.new_api_version }}
new_web_version: ${{ steps.bump.outputs.new_web_version }}
new_cli_version: ${{ steps.bump.outputs.new_cli_version }}
api_tag_created: ${{ steps.tag.outputs.api_tag_created }}
web_tag_created: ${{ steps.tag.outputs.web_tag_created }}
cli_tag_created: ${{ steps.tag.outputs.cli_tag_created }}
steps:
- name: Determine Branch Name
- name: Determine Branch Name and SHA
id: branch_info
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "branch_name=${{ github.head_ref }}" >> $GITHUB_OUTPUT
echo "branch_name=${{ github.event.pull_request.base.ref }}" >> $GITHUB_OUTPUT
echo "checkout_sha=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "branch_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "checkout_sha=${{ github.sha }}" >> $GITHUB_OUTPUT
else
echo "branch_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "checkout_sha=${{ github.sha }}" >> $GITHUB_OUTPUT
fi
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ steps.branch_info.outputs.branch_name }}
token: ${{ secrets.GITHUB_TOKEN }} # Or a PAT if you push to protected branches from actions
fetch-depth: 0 # For git tagging and history
ref: ${{ github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20' # Specify a Node.js version
node-version: '20'
- name: Set up Rust toolchain
uses: actions-rs/toolchain@v1
@ -85,14 +93,32 @@ jobs:
VERSION_SPEC="${{ github.event.inputs.version_spec }}"
COMPONENT="${{ github.event.inputs.component }}"
echo "Using workflow_dispatch inputs: version_spec='$VERSION_SPEC', component='$COMPONENT'"
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.merged }}" == "true" ]]; then
PR_TITLE=$(echo "${{ github.event.pull_request.title }}" | tr '[:upper:]' '[:lower:]')
echo "Pull Request title (lowercase): $PR_TITLE"
COMPONENT="all"
if echo "$PR_TITLE" | grep -q -E "breaking change|feat!:"; then
VERSION_SPEC="major"
elif echo "$PR_TITLE" | grep -q -E "^feat\\([^)]+\\)!:"; then
VERSION_SPEC="major"
elif echo "$PR_TITLE" | grep -q -E "^feat:"; then
VERSION_SPEC="minor"
elif echo "$PR_TITLE" | grep -q -E "^fix:"; then
VERSION_SPEC="patch"
else
echo "No major/minor/fix keyword found in PR title. Defaulting to patch for merged PR."
VERSION_SPEC="patch"
fi
echo "Determined for PR merge: version_spec='$VERSION_SPEC', component='$COMPONENT'"
elif [[ "${{ github.event_name }}" == "push" ]]; then
COMMIT_MESSAGE_TEXT=$(echo "${{ github.event.head_commit.message }}" | tr '[:upper:]' '[:lower:]')
echo "Push event. Analyzing commit message (lowercase): $COMMIT_MESSAGE_TEXT"
COMPONENT="all" # Default component for push events
COMPONENT="all"
if echo "$COMMIT_MESSAGE_TEXT" | grep -q -E "breaking change|feat!:"; then
VERSION_SPEC="major"
elif echo "$COMMIT_MESSAGE_TEXT" | grep -q -E "^feat\\([^)]+\\)!:"; then # e.g., feat(scope)!:
elif echo "$COMMIT_MESSAGE_TEXT" | grep -q -E "^feat\\([^)]+\\)!:"; then
VERSION_SPEC="major"
elif echo "$COMMIT_MESSAGE_TEXT" | grep -q -E "^feat:"; then
VERSION_SPEC="minor"
@ -141,7 +167,6 @@ jobs:
NEW_WEB_VERSION=""
NEW_CLI_VERSION=""
# API Version Bump
if [[ "$COMPONENT" == "all" || "$COMPONENT" == "api" ]]; then
echo "Processing API version using spec: $VERSION_SPEC..."
cd api/server
@ -165,25 +190,22 @@ jobs:
fi
fi
# Web Version Bump
if [[ "$COMPONENT" == "all" || "$COMPONENT" == "web" ]]; then
echo "Bumping Web version using spec: $VERSION_SPEC..."
cd web
OLD_WEB_VERSION=$(jq -r .version package.json)
# npm version can handle bump types and specific versions directly
npm version "$VERSION_SPEC" --no-git-tag-version --allow-same-version
NEW_WEB_VERSION=$(jq -r .version package.json)
echo "Web: $OLD_WEB_VERSION -> $NEW_WEB_VERSION"
cd ..
if [[ "$OLD_WEB_VERSION" != "$NEW_WEB_VERSION" ]]; then
git add web/package.json web/package-lock.json # package-lock.json might also change
git add web/package.json web/package-lock.json
COMMIT_MESSAGE_PREFIX="$COMMIT_MESSAGE_PREFIX bump web to v$NEW_WEB_VERSION;"
COMMIT_CHANGES=true
echo "new_web_version=$NEW_WEB_VERSION" >> $GITHUB_OUTPUT
fi
fi
# CLI Version Bump
if [[ "$COMPONENT" == "all" || "$COMPONENT" == "cli" ]]; then
echo "Processing CLI version using spec: $VERSION_SPEC..."
cd cli/cli
@ -208,14 +230,13 @@ jobs:
fi
if [[ "$COMMIT_CHANGES" == true ]]; then
# Remove trailing semicolon if any
FINAL_COMMIT_MESSAGE=$(echo "$COMMIT_MESSAGE_PREFIX" | sed 's/;$//')
echo "Final Commit Message: $FINAL_COMMIT_MESSAGE [skip ci]"
echo "COMMIT_MESSAGE_CONTENT=$FINAL_COMMIT_MESSAGE [skip ci]" >> $GITHUB_ENV
echo "commit_message=$FINAL_COMMIT_MESSAGE [skip ci]" >> $GITHUB_OUTPUT
else
echo "No version changes detected."
echo "COMMIT_MESSAGE_CONTENT=" >> $GITHUB_ENV # Ensure it's empty
echo "COMMIT_MESSAGE_CONTENT=" >> $GITHUB_ENV
echo "commit_message=" >> $GITHUB_OUTPUT
fi
echo "New API Version Output: $NEW_API_VERSION"
@ -230,11 +251,11 @@ jobs:
git commit -m "$COMMIT_MESSAGE_TO_USE"
- name: Create and Push Tags
if: steps.bump.outputs.commit_message != '' # Only tag if there were changes
if: steps.bump.outputs.commit_message != ''
run: |
echo "Creating and pushing tags..."
TAG_INFO_FILE="tag_info.json"
echo "{" > $TAG_INFO_FILE # Start JSON object
echo "{" > $TAG_INFO_FILE
FIRST_TAG=true
NEW_API_VERSION="${{ steps.bump.outputs.new_api_version }}"
@ -266,7 +287,7 @@ jobs:
FIRST_TAG=false
fi
echo "}" >> $TAG_INFO_FILE # End JSON object
echo "}" >> $TAG_INFO_FILE
echo "Created tag info file:"
cat $TAG_INFO_FILE
@ -274,8 +295,12 @@ jobs:
echo "Pushing commit and tags to branch: $BRANCH_TO_PUSH"
git push origin HEAD:"refs/heads/$BRANCH_TO_PUSH" --follow-tags
echo "api_tag_created=$API_TAG_CREATED" >> $GITHUB_OUTPUT
echo "web_tag_created=$WEB_TAG_CREATED" >> $GITHUB_OUTPUT
echo "cli_tag_created=$CLI_TAG_CREATED" >> $GITHUB_OUTPUT
- name: Upload Tag Information Artifact
if: steps.bump.outputs.commit_message != '' && (steps.bump.outputs.new_api_version != '' || steps.bump.outputs.new_web_version != '' || steps.bump.outputs.new_cli_version != '')
if: steps.tag.outputs.api_tag_created == 'true' || steps.tag.outputs.web_tag_created == 'true' || steps.tag.outputs.cli_tag_created == 'true'
uses: actions/upload-artifact@v4
with:
name: version-tag-info
@ -283,12 +308,6 @@ jobs:
retention-days: 1
- name: Push changes (if only commit, no tags yet or if tag push failed)
# This condition implies commit happened, but no versions were actually outputted.
# This might occur if a bump was attempted but the version didn't change.
# The original condition was:
# if: steps.bump.outputs.commit_message != '' && (steps.bump.outputs.new_api_version == '' && steps.bump.outputs.new_web_version == '' && steps.bump.outputs.new_cli_version == '')
# A simpler way to check if tags were created might be needed or this step might be redundant if --follow-tags is robust.
# For now, keeping the original logic.
if: steps.bump.outputs.commit_message != '' && (steps.bump.outputs.new_api_version == '' && steps.bump.outputs.new_web_version == '' && steps.bump.outputs.new_cli_version == '')
run: |
BRANCH_TO_PUSH="${{ steps.branch_info.outputs.branch_name }}"

View File

@ -1,6 +1,6 @@
[package]
name = "buster_server"
version = "0.1.5"
version = "0.1.0"
edition = "2021"
default-run = "buster_server"

View File

@ -1,6 +1,6 @@
[package]
name = "buster-cli"
version = "0.1.5"
version = "0.1.0"
edition = "2021"
build = "build.rs"

View File

@ -1,6 +1,6 @@
{
"name": "web",
"version": "0.1.5",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev --turbo",