Skip to content

Update Homebrew Formula #18

Update Homebrew Formula

Update Homebrew Formula #18

Workflow file for this run

name: Update Homebrew Formula
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'Release tag to update Homebrew formula (e.g., v1.2.3)'
required: true
default: ''
jobs:
update-homebrew:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract release version
id: extract_version
run: |
if [ "${{ github.event_name }}" == "release" ]; then
TAG="${{ github.event.release.tag_name }}"
VERSION="${TAG#v}"
echo "Using release tag: $TAG"
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
TAG="${{ github.event.inputs.tag }}"
VERSION="${TAG#v}"
echo "Using workflow_dispatch tag: $TAG"
else
echo "Unsupported event: $GITHUB_EVENT_NAME"
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create temporary directory
run: mkdir temp
- name: Download macOS tarball
run: |
wget https://github.com/deggja/netfetch/releases/download/v${{ env.VERSION }}/netfetch_${{ env.VERSION }}_darwin_amd64.tar.gz -O temp/netfetch_darwin_amd64.tar.gz
- name: Calculate macOS SHA256
run: |
SHA=$(sha256sum temp/netfetch_darwin_amd64.tar.gz | awk '{print $1}')
echo "MACOS_SHA256=$SHA" >> $GITHUB_ENV
- name: Download Linux tarball
run: |
wget https://github.com/deggja/netfetch/releases/download/v${{ env.VERSION }}/netfetch_${{ env.VERSION }}_linux_amd64.tar.gz -O temp/netfetch_linux_amd64.tar.gz
- name: Calculate Linux SHA256
run: |
SHA=$(sha256sum temp/netfetch_linux_amd64.tar.gz | awk '{print $1}')
echo "LINUX_SHA256=$SHA" >> $GITHUB_ENV
- name: Debug - Print SHA256 Variables
run: |
echo "MACOS_SHA256: $MACOS_SHA256"
echo "LINUX_SHA256: $LINUX_SHA256"
- name: Update Homebrew Formula
run: |
FORMULA_FILE="formula/netfetch.rb"
sed -i "s|url \".*darwin_amd64\.tar\.gz\"|url \"https://github.com/deggja/netfetch/releases/download/v${{ env.VERSION }}/netfetch_${{ env.VERSION }}_darwin_amd64.tar.gz\"|" $FORMULA_FILE
sed -i "s|sha256 \".*\"|sha256 \"${{ env.MACOS_SHA256 }}\"|" $FORMULA_FILE
sed -i "s|url \".*linux_amd64\.tar\.gz\"|url \"https://github.com/deggja/netfetch/releases/download/v${{ env.VERSION }}/netfetch_${{ env.VERSION }}_linux_amd64.tar.gz\"|" $FORMULA_FILE
sed -i "s|sha256 \".*\"|sha256 \"${{ env.LINUX_SHA256 }}\"|" $FORMULA_FILE
- name: Remove temp directory
run: rm -rf temp
- name: Fetch Latest Changes from Main
run: |
git fetch origin main
git checkout main
git pull origin main
- name: Pull Remote Branch Changes
run: |
git fetch origin chore/homebrew-${{ env.VERSION }} || echo "Branch not found. Continuing..."
git checkout -B chore/homebrew-${{ env.VERSION }} origin/chore/homebrew-${{ env.VERSION }} || echo "Creating new branch chore/homebrew-${{ env.VERSION }}"
git pull origin chore/homebrew-${{ env.VERSION }} || echo "No remote changes to pull"
- name: Commit and Push changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore: update homebrew formula for v${{ env.VERSION }}"
branch: chore/homebrew-${{ env.VERSION }}
create_branch: true
file_pattern: "formula/netfetch.rb"
commit_user_name: "Netfetch Bot"
commit_author: "Netfetch Bot <[email protected]>"
commit_user_email: "[email protected]"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
base: main
title: "chore: update homebrew formula for v${{ env.VERSION }}"
committer: "Netfetch Bot <[email protected]>"
author: "Netfetch Bot <[email protected]>"
commit-message: "chore: update homebrew formula for v${{ env.VERSION }}"
body: "Automated update of Homebrew formula to version v${{ env.VERSION }}."
branch: chore/homebrew-${{ env.VERSION }}
add-paths: |
formula/netfetch.rb
delete-branch: true