Skip to content

feat: enhance Homebrew formula automation with proper authentication … #24

feat: enhance Homebrew formula automation with proper authentication …

feat: enhance Homebrew formula automation with proper authentication … #24

Workflow file for this run

name: Build and Release
on:
push:
branches:
- master # Trigger on merges to master
permissions:
contents: write
packages: write
jobs:
tag-and-release:
name: Tag and Release
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.create_tag.outputs.new_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history for versioning
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: true
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
# Extract current version and create new version tag
- name: Create Tag
id: create_tag
run: |
# Extract current version from version command
CURRENT_VERSION=$(grep -o 'commitron v[0-9]\+\.[0-9]\+\.[0-9]\+' cmd/commitron/commands.go | head -1 | sed 's/commitron v//')
if [ -z "$CURRENT_VERSION" ]; then
CURRENT_VERSION="0.1.0" # Default if no version found
fi
# Split the version into components
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
# Increment patch version
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
TAG_VERSION="v$NEW_VERSION"
# Set outputs for later steps
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "tag_version=$TAG_VERSION" >> $GITHUB_OUTPUT
# Create and push tag
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Update version in code
awk -v new_version="$NEW_VERSION" '{gsub(/commitron v[0-9]+\.[0-9]+\.[0-9]+/, "commitron v" new_version); print}' cmd/commitron/commands.go > cmd/commitron/commands.go.tmp && mv cmd/commitron/commands.go.tmp cmd/commitron/commands.go
# Commit the version change
git add cmd/commitron/commands.go
git commit -m "Bump version to $NEW_VERSION [skip ci]"
# Create and push the tag
git tag $TAG_VERSION
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git push origin $TAG_VERSION
git push origin HEAD
echo "Created and pushed tag $TAG_VERSION"
build:
name: Build (${{ matrix.os }})
needs: tag-and-release
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
artifact_name: commitron
asset_name: commitron-linux-amd64
- os: windows-latest
artifact_name: commitron.exe
asset_name: commitron-windows-amd64.exe
- os: macos-latest
artifact_name: commitron
asset_name: commitron-macos-amd64
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: v${{ needs.tag-and-release.outputs.new_version }}
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
# Build the application for the current OS/architecture
- name: Build
run: |
go build -v -o ${{ matrix.artifact_name }} ./cmd/commitron
# Upload the binary as an artifact for this workflow run
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: ${{ matrix.artifact_name }}
release:
name: Create Release
needs: [tag-and-release, build]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: v${{ needs.tag-and-release.outputs.new_version }}
# Download all artifacts from the build job
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
# Debug: List downloaded artifacts
- name: List artifacts
run: |
echo "Artifacts directory structure:"
find ./artifacts -type f -exec ls -la {} \;
echo "Artifacts directory contents:"
ls -la ./artifacts/
# Copy artifacts to release directory with proper names
- name: Prepare release files
run: |
mkdir -p ./release
find ./artifacts -type f -name "commitron*" -exec cp {} ./release/ \;
echo "Release files:"
ls -la ./release/
# Create a new GitHub release with the tag that triggered the workflow
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.tag-and-release.outputs.new_version }}
name: Release v${{ needs.tag-and-release.outputs.new_version }}
files: ./release/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}