diff --git a/.github/workflows/build.yml b/.github/workflows/build-and-release.yml similarity index 52% rename from .github/workflows/build.yml rename to .github/workflows/build-and-release.yml index 934810b..0efdc86 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build-and-release.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/update-homebrew.yml b/.github/workflows/update-homebrew.yml new file mode 100644 index 0000000..c84c5bd --- /dev/null +++ b/.github/workflows/update-homebrew.yml @@ -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 "action@github.com" + 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 diff --git a/colorexp.go b/colorexp.go index 618feb9..ffb825b 100644 --- a/colorexp.go +++ b/colorexp.go @@ -8,7 +8,7 @@ import ( "regexp" ) -const version = "1.0.2" +const version = "1.0.3" var foregroundColors = []string{ //"\033[30m", // Black