Livechecks tap mvrpl/unix-apps #256
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Livechecks tap mvrpl/unix-apps | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * *' | |
jobs: | |
brew-livecheck: | |
runs-on: ubuntu-latest | |
outputs: | |
json-apps: ${{ steps.brew-checkver.outputs.apps }} | |
steps: | |
- name: Set up Homebrew | |
id: set-up-homebrew | |
uses: Homebrew/actions/setup-homebrew@master | |
- name: Livecheck brew | |
id: brew-checkver | |
run: | | |
brew tap mvrpl/unix-apps https://github.com/mvrpl/unix-apps | |
brew install jq | |
echo "apps=$(brew livecheck --tap mvrpl/unix-apps --json | jq -c '.')" >> "$GITHUB_OUTPUT" | |
updates: | |
runs-on: ubuntu-latest | |
needs: [brew-livecheck] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Homebrew | |
id: set-up-homebrew | |
uses: Homebrew/actions/setup-homebrew@master | |
- name: Updates | |
env: | |
APPS: ${{needs.brew-livecheck.outputs.json-apps}} | |
run: | | |
sudo apt-get install -y coreutils pcregrep | |
brew install jq | |
update_version () { formula=$1;new_version=$2;old_version=$3;awk -v old="$old_version" -v new="$new_version" '{if ($0 ~ /(url|version|bin\.install)/) {gsub(old, new, $0)};print $0 >"awk.out"}' ./${formula}.rb;mv awk.out ./${formula}.rb; } | |
export -f update_version | |
update_hashs () { formula=$1; paste -d ' ' <(pcregrep -o1 'url.*"(.*)"' ./${formula}.rb) <(pcregrep -o1 'sha256.*"(.*)"' ./${formula}.rb) | xargs -L1 bash -c 'hash=$(curl -sL $1 | sha256sum | cut -d " " -f 1);sed -ri "s/$2/$hash/g" ./'${formula}'.rb' bash; } | |
export -f update_hashs | |
update_versions() { tmp=$(mktemp); jq '."'$1'" = "'$2'"' versions.json > "$tmp" && mv "$tmp" versions.json; } | |
export -f update_versions | |
echo "$APPS" | jq '.[] | select(.version.outdated) | "update_version \(.formula) \(.version.latest) \(.version.current)"' | xargs -n1 bash -c '$1' bash | |
echo "$APPS" | jq '.[] | select(.version.outdated) | "update_hashs \(.formula)"' | xargs -n1 bash -c '$1' bash | |
echo "$APPS" | jq '.[] | select(.version.outdated) | "update_versions \(.formula) \(.version.latest)"' | xargs -n1 bash -c '$1' bash | |
- name: Push changes | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
file_pattern: '*.rb' | |
branch: main | |
- name: Push changes versions | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
file_pattern: 'versions.json' | |
branch: main |