Skip to content

Commit

Permalink
chore: update ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscaner committed Dec 27, 2023
1 parent b515e3c commit a1b994c
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 113 deletions.
20 changes: 20 additions & 0 deletions .github/actions/bump-casks/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Bump casks

inputs:
HOMEBREW_GITHUB_API_TOKEN:
description: 'Homebrew GitHub API Token'
required: true

runs:
using: 'composite'

steps:
- name: Bump outdated casks
# continue-on-error: true
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ inputs.HOMEBREW_GITHUB_API_TOKEN }}
shell: bash
run: |
parallel -j0 --group --halt now,fail=1 \
'./.github/actions/bump-casks/script.sh {}' \
::: $(ls $(brew --repository brewforge/chinese)/Casks/*.rb | xargs -I {} basename {} .rb)
22 changes: 22 additions & 0 deletions .github/actions/bump-casks/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -ev

cask=$1

echo "Checking for updates to $cask..."

# "sed" command not working on github action,
# because of the color code in the output of "brew livecheck --cask" command
check=$(echo $(brew livecheck --cask "$cask") | tr -d ' ' | cut -d':' -f2- | sed 's/\x1b[[0-9;]*m//g')

echo "Check result: $check"

fromV=${check%==>*}
toV=${check#*==>}

echo "Updating $cask from $fromV to $toV"

if [[ "$fromV" != "$toV" ]]; then
brew bump-cask-pr "$cask" --version "$toV" --verbose --force
fi
32 changes: 32 additions & 0 deletions .github/actions/homebrew-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Homebrew Action

inputs:
HOMEBREW_GITHUB_API_TOKEN:
description: 'Homebrew GitHub API Token'
required: true

runs:
using: 'composite'

steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
with:
core: true
cask: true
test-bot: false

- name: Add parallel cli
shell: bash
run: |
brew install parallel
- name: Add Tap
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ inputs.HOMEBREW_GITHUB_API_TOKEN }}
shell: bash
run: |
brew tap brewforge/chinese
brew update
brew install ripgrep sd
121 changes: 8 additions & 113 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
branches: [main, bump-*]
push:
branches: [fix-*]
branches: [fix-*, feature-*]
schedule:
# run every 12 hours
# - cron: "20 */12 * * *"
Expand All @@ -15,129 +15,24 @@ on:

jobs:
job1:
name: Test Casks
name: Bump Casks in parallel
if: github.repository == 'brewforge/homebrew-chinese'
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [macos-latest]

# https://github.com/orgs/Homebrew/discussions/4474#discussioncomment-5781752
# permissions:
# actions: read
# packages: write
# contents: write
# pull-requests: write

steps:
- uses: actions/checkout@v2
with:
repository: brewforge/homebrew-chinese
ref: main
path: homebrew-chinese
# checkout myself.
- uses: actions/checkout@v3

- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Homebrew env
uses: ./.github/actions/homebrew-env
with:
core: true
cask: true
test-bot: false

- name: Add Tap
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
run: |
brew tap brewforge/chinese
brew update
brew install ripgrep sd
- name: Bump outdated casks b-l
# continue-on-error: true
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
run: |
cd $(brew --prefix)/Homebrew/Library/Taps/brewforge/homebrew-chinese/Casks
for cask in [b-l]*.rb; do
cask=$(echo "$cask" | sd "/Casks" "" | sd ".rb" "")
echo "Checking $cask"
# "sed" command not working on github action,
# because of the color code in the output of "brew livecheck --cask" command
check=$(echo $(brew livecheck --cask "$cask") | tr -d ' ' | cut -d':' -f2- | sed 's/\x1b[[0-9;]*m//g')
echo "Check result: $check"

fromV=${check%==>*}
toV=${check#*==>}
echo "Updating $cask from $fromV to $toV"
if [[ "$fromV" != "$toV" ]]; then
brew bump-cask-pr "$cask" --version "$toV" --verbose --force
fi
done
job2:
name: Test Casks
if: github.repository == 'brewforge/homebrew-chinese'
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [macos-latest]

# https://github.com/orgs/Homebrew/discussions/4474#discussioncomment-5781752
# permissions:
# actions: read
# packages: write
# contents: write
# pull-requests: write

steps:
- uses: actions/checkout@v2
- name: Bump casks
uses: ./.github/actions/bump-casks
with:
repository: brewforge/homebrew-chinese
ref: main
path: homebrew-chinese

- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
with:
core: true
cask: true
test-bot: false

- name: Add Tap
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
run: |
brew tap brewforge/chinese
brew update
brew install ripgrep sd
- name: Bump outdated casks m-z
# continue-on-error: true
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
run: |
cd $(brew --prefix)/Homebrew/Library/Taps/brewforge/homebrew-chinese/Casks
for cask in [m-z]*.rb; do
cask=$(echo "$cask" | sd "/Casks" "" | sd ".rb" "")
echo "Checking $cask"
# "sed" command not working on github action,
# because of the color code in the output of "brew livecheck --cask" command
check=$(echo $(brew livecheck --cask "$cask") | tr -d ' ' | cut -d':' -f2- | sed 's/\x1b[[0-9;]*m//g')
echo "Check result: $check"
fromV=${check%==>*}
toV=${check#*==>}
echo "Updating $cask from $fromV to $toV"
if [[ "$fromV" != "$toV" ]]; then
brew bump-cask-pr "$cask" --version "$toV" --verbose
fi
done

0 comments on commit a1b994c

Please sign in to comment.