Skip to content

Commit

Permalink
create update-homebrew.yml
Browse files Browse the repository at this point in the history
up version to 1.0.3 to check out update-homebrew.yml workflow
  • Loading branch information
EugenDueck committed Mar 15, 2024
1 parent 76c844c commit ede5c59
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ jobs:
- uses: actions/checkout@v4

# Extract version information
- name: Extract project version
id: project_version
run: echo "version=$(grep 'const version =' colorexp.go | cut -d '"' -f 2)" >> $GITHUB_OUTPUT
- name: Extract commit hash
id: git_commit
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Extract project version and hash
id: project_info
run: |
echo "version=$(grep 'const version =' colorexp.go | cut -d '"' -f 2)" >> $GITHUB_OUTPUT
echo "version_and_hash=$(grep 'const version =' colorexp.go | cut -d '"' -f 2)-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
# Prepare build
- name: Set up Go
Expand All @@ -31,35 +30,35 @@ jobs:
- name: Build Linux
run: |
env GOOS=linux GOARCH=amd64 go build -o colorexp colorexp.go
tar -czvf colorexp-linux-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz colorexp
tar -czvf colorexp-linux-amd64-${{ steps.project_info.outputs.version_and_hash }}.tar.gz colorexp
- name: Upload Linux artifact
uses: actions/upload-artifact@v4
with:
name: colorexp-linux-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz
path: colorexp-linux-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz
name: colorexp-linux-amd64-${{ steps.project_info.outputs.version_and_hash }}.tar.gz
path: colorexp-linux-amd64-${{ steps.project_info.outputs.version_and_hash }}.tar.gz

# Build Darwin
- name: Build Darwin
run: |
env GOOS=darwin GOARCH=amd64 go build -o colorexp colorexp.go
chmod a+x colorexp
tar -czvf colorexp-darwin-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz colorexp
tar -czvf colorexp-darwin-amd64-${{ steps.project_info.outputs.version_and_hash }}.tar.gz colorexp
- name: Upload Darwin artifact
uses: actions/upload-artifact@v4
with:
name: colorexp-darwin-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}
path: colorexp-darwin-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}
name: colorexp-darwin-amd64-${{ steps.project_info.outputs.version_and_hash }}
path: colorexp-darwin-amd64-${{ steps.project_info.outputs.version_and_hash }}

# Build Windows
- name: Build Windows
run: |
env GOOS=windows GOARCH=amd64 go build -o colorexp.exe colorexp.go
zip colorexp-windows-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.zip colorexp.exe
zip colorexp-windows-amd64-${{ steps.project_info.outputs.version_and_hash }}.zip colorexp.exe
- name: Upload Windows artifact
uses: actions/upload-artifact@v4
with:
name: colorexp-windows-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.zip
path: colorexp-windows-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.zip
name: colorexp-windows-amd64-${{ steps.project_info.outputs.version_and_hash }}.zip
path: colorexp-windows-amd64-${{ steps.project_info.outputs.version_and_hash }}.zip

# Create a GitHub release
- name: Create Release
Expand All @@ -68,8 +67,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.project_version.outputs.version }}
release_name: Release ${{ steps.project_version.outputs.version }}
tag_name: v${{ steps.project_info.outputs.version }}
release_name: Release ${{ steps.project_info.outputs.version }}
draft: false
prerelease: false

Expand All @@ -81,8 +80,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./colorexp-linux-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz
asset_name: colorexp-linux-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz
asset_path: ./colorexp-linux-amd64-${{ steps.project_info.outputs.version_and_hash }}.tar.gz
asset_name: colorexp-linux-amd64-${{ steps.project_info.outputs.version_and_hash }}.tar.gz
asset_content_type: application/octet-stream

# Upload release asset for Darwin
Expand All @@ -92,8 +91,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./colorexp-darwin-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz
asset_name: colorexp-darwin-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.tar.gz
asset_path: ./colorexp-darwin-amd64-${{ steps.project_info.outputs.version_and_hash }}.tar.gz
asset_name: colorexp-darwin-amd64-${{ steps.project_info.outputs.version_and_hash }}.tar.gz
asset_content_type: application/octet-stream

# Upload release asset for Windows
Expand All @@ -103,6 +102,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./colorexp-windows-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.zip
asset_name: colorexp-windows-amd64-${{ steps.project_version.outputs.version }}-${{ steps.git_commit.outputs.sha }}.zip
asset_path: ./colorexp-windows-amd64-${{ steps.project_info.outputs.version_and_hash }}.zip
asset_name: colorexp-windows-amd64-${{ steps.project_info.outputs.version_and_hash }}.zip
asset_content_type: application/octet-stream
45 changes: 45 additions & 0 deletions .github/workflows/update-homebrew.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Update Homebrew Tap

on:
release:
types: [created]

jobs:
update-tap:
runs-on: ubuntu-latest
steps:
- name: Checkout colorexp repository at released tag
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- name: Extract project version and commit hash
id: project_info
run: |
echo "version=$(grep 'const version =' colorexp.go | cut -d '"' -f 2)" >> $GITHUB_OUTPUT
echo "version_and_hash=$(grep 'const version =' colorexp.go | cut -d '"' -f 2)-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "filename=colorexp-darwin-amd64-$(grep 'const version =' colorexp.go | cut -d '"' -f 2)-$(git rev-parse --short HEAD).tar.gz" >> $GITHUB_OUTPUT
- name: Checkout homebrew-tap repository
uses: actions/checkout@v4
with:
repository: EugenDueck/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_PAT }}
path: homebrew-tap

- name: Update Formula with dynamic filename
run: |
url="https://github.com/EugenDueck/colorexp/releases/download/${{ github.event.release.tag_name }}/${{ steps.project_info.outputs.filename }}"
sha256=$(curl -L $url | sha256sum | cut -d ' ' -f1)
sed -i "s|url .*|url \"$url\"|" homebrew-tap/Formula/colorexp.rb
sed -i "s|sha256 .*|sha256 \"$sha256\"|" homebrew-tap/Formula/colorexp.rb
shell: bash

- name: Commit and push changes
run: |
cd homebrew-tap
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add Formula/colorexp.rb
git commit -m "Update colorexp formula to version ${{ github.event.release.tag_name }}"
git push
2 changes: 1 addition & 1 deletion colorexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"regexp"
)

const version = "1.0.2"
const version = "1.0.3"

var foregroundColors = []string{
//"\033[30m", // Black
Expand Down

0 comments on commit ede5c59

Please sign in to comment.