Skip to content

Commit 210e811

Browse files
committed
fix(#49): github actions permission denied
1 parent 3808137 commit 210e811

File tree

8 files changed

+119
-35
lines changed

8 files changed

+119
-35
lines changed

.github/actions/brew-tap/action.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Brew Tap
2+
3+
inputs:
4+
HOMEBREW_GITHUB_API_TOKEN:
5+
description: 'Homebrew GitHub API Token'
6+
required: true
7+
8+
runs:
9+
using: 'composite'
10+
11+
steps:
12+
- name: Add Tap
13+
env:
14+
HOMEBREW_GITHUB_API_TOKEN: ${{ inputs.HOMEBREW_GITHUB_API_TOKEN }}
15+
shell: bash
16+
run: |
17+
brew tap brewforge/chinese
18+
brew update
19+
20+
- name: Install Homebrew's dependencies
21+
shell: bash
22+
run: |
23+
brew install ripgrep sd gcc parallel coreutils
24+
brew unlink coreutils && brew link coreutils
25+
brew install-bundler-gems --groups "audit,style"
26+
27+
- uses: oleksiyrudenko/gha-git-credentials@v2-latest
28+
with:
29+
global: true
30+
name: 'Brewforge-Bot'
31+
32+
token: '${{ inputs.HOMEBREW_GITHUB_API_TOKEN }}'
33+
34+
- name: show git context
35+
shell: bash
36+
run: |
37+
cat $HOME/.gitconfig
38+
cat $GITHUB_ENV

.github/actions/bump-casks/action.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ runs:
1212
- name: Bump outdated casks
1313
# continue-on-error: true
1414
env:
15+
HOMEBREW_DEVELOPER: '1'
1516
HOMEBREW_GITHUB_API_TOKEN: ${{ inputs.HOMEBREW_GITHUB_API_TOKEN }}
1617
shell: bash
18+
# https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#primary-rate-limit-for-authenticated-users
19+
# Github Actions: 5000 requests per hour
20+
# 1 * 60 * 24 = 1440 (because bump-pr will checkout a new branch and push to remote)
21+
# 1 concurrent parallel jobs, 1 second delay between jobs.
1722
run: |
18-
parallel -j0 --group --halt now,fail=1 \
19-
'./.github/actions/bump-casks/script.sh {}' \
23+
parallel -j1 --delay 1s --group --halt now,fail=1 \
24+
"./.github/actions/bump-casks/script.sh {}" \
2025
::: $(ls $(brew --repository brewforge/chinese)/Casks/*.rb | xargs -I {} basename {} .rb)

.github/actions/bump-casks/script.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ toV=${cleanCheck#*==>}
2727

2828
echo "Updating $cask from $fromV to $toV"
2929
if [[ "$fromV" != "$toV" ]]; then
30-
brew bump-cask-pr "$cask" --version "$toV" --verbose --force
30+
brew bump-cask-pr "$cask" --version "$toV" --verbose --force --fork-org Brewforge-Bot
3131
fi
3232
echo "Done for $cask"

.github/actions/bump-formulas/action.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ runs:
1212
- name: Bump outdated formulas
1313
# continue-on-error: true
1414
env:
15+
HOMEBREW_DEVELOPER: '1'
1516
HOMEBREW_GITHUB_API_TOKEN: ${{ inputs.HOMEBREW_GITHUB_API_TOKEN }}
1617
shell: bash
18+
# https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#primary-rate-limit-for-authenticated-users
19+
# Github Actions: 5000 requests per hour
20+
# 1 * 60 * 24 = 1440 (because bump-pr will checkout a new branch and push to remote)
21+
# 1 concurrent parallel jobs, 1 second delay between jobs.
1722
run: |
18-
parallel -j0 --group --halt now,fail=1 \
19-
'./.github/actions/bump-formulas/script.sh {}' \
23+
parallel -j1 --delay 1s --group --halt now,fail=1 \
24+
"./.github/actions/bump-formulas/script.sh {}" \
2025
::: $(ls $(brew --repository brewforge/chinese)/Formula/*.rb | xargs -I {} basename {} .rb)

.github/actions/bump-formulas/script.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ toV=${cleanCheck#*==>}
2727

2828
echo "Updating $formula from $fromV to $toV"
2929
if [[ "$fromV" != "$toV" ]]; then
30-
brew bump-formula-pr "$formula" --version "$toV" --verbose --force
30+
brew bump-formula-pr "$formula" --version "$toV" --verbose --force --fork-org Brewforge-Bot
3131
fi
3232
echo "Done for $formula"
+5-22
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,17 @@
11
name: Homebrew Action
22

3-
inputs:
4-
HOMEBREW_GITHUB_API_TOKEN:
5-
description: 'Homebrew GitHub API Token'
6-
required: true
7-
83
runs:
94
using: 'composite'
105

116
steps:
127
- name: Set up Homebrew
13-
id: set-up-homebrew
14-
uses: Homebrew/actions/setup-homebrew@master
15-
with:
16-
core: true
17-
cask: true
18-
test-bot: false
19-
20-
- name: Add parallel cli
218
shell: bash
229
run: |
23-
brew install parallel
24-
# makesure brew livecheck works
25-
brew livecheck parallel
10+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
2611
27-
- name: Add Tap
28-
env:
29-
HOMEBREW_GITHUB_API_TOKEN: ${{ inputs.HOMEBREW_GITHUB_API_TOKEN }}
12+
- name: Add Homebrew to PATH
3013
shell: bash
3114
run: |
32-
brew tap brewforge/chinese
33-
brew update
34-
brew install ripgrep sd
15+
touch $HOME/.bash_profile
16+
(echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> $HOME/.bash_profile
17+
eval "$(/usr/local/bin/brew shellenv)"
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Linuxbrew Action
2+
3+
runs:
4+
using: 'composite'
5+
6+
steps:
7+
- name: Set up Linuxbrew
8+
shell: bash
9+
run: |
10+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
11+
12+
- name: Add Linuxbrew to PATH
13+
shell: bash
14+
run: |
15+
touch $HOME/.bashrc
16+
(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> $HOME/.bashrc
17+
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
18+
19+
- name: Install Homebrew's dependencies
20+
shell: bash
21+
run: |
22+
sudo apt-get install build-essential

.github/workflows/main.yml .github/workflows/schedule.yml

+38-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name: CI
1+
name: schedule
22

33
on:
4-
pull_request:
5-
branches: [main, bump-*]
4+
# pull_request:
5+
# branches: [main]
66
push:
77
branches: [fix-*]
88
schedule:
@@ -11,7 +11,9 @@ on:
1111
# Every day at 6am
1212
- cron: "0 6 * * *"
1313
# allow run manually
14-
workflow_dispatch: {}
14+
workflow_dispatch:
15+
16+
permissions: write-all
1517

1618
jobs:
1719
casks:
@@ -24,11 +26,13 @@ jobs:
2426
os: [macos-latest]
2527

2628
steps:
27-
# checkout myself.
2829
- uses: actions/checkout@v3
2930

3031
- name: Homebrew env
3132
uses: ./.github/actions/homebrew-env
33+
34+
- name: Brew Tap
35+
uses: ./.github/actions/brew-tap
3236
with:
3337
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
3438

@@ -44,14 +48,41 @@ jobs:
4448

4549
strategy:
4650
matrix:
47-
os: [macos-latest, ubuntu-latest]
51+
os: [macos-latest]
4852

4953
steps:
50-
# checkout myself.
5154
- uses: actions/checkout@v3
5255

5356
- name: Homebrew env
5457
uses: ./.github/actions/homebrew-env
58+
59+
- name: Brew Tap
60+
uses: ./.github/actions/brew-tap
61+
with:
62+
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
63+
64+
- name: Bump formulas
65+
uses: ./.github/actions/bump-formulas
66+
with:
67+
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
68+
69+
formulas-linuxbrew:
70+
name: Bump Formulas in parallel (Linuxbrew)
71+
if: github.repository == 'brewforge/homebrew-chinese'
72+
runs-on: ${{ matrix.os }}
73+
74+
strategy:
75+
matrix:
76+
os: [ubuntu-latest]
77+
78+
steps:
79+
- uses: actions/checkout@v3
80+
81+
- name: Homebrew env
82+
uses: ./.github/actions/linuxbrew-env
83+
84+
- name: Brew Tap
85+
uses: ./.github/actions/brew-tap
5586
with:
5687
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
5788

0 commit comments

Comments
 (0)