Skip to content

Commit

Permalink
fix(#49): github actions permission denied
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscaner committed Jan 13, 2024
1 parent 3808137 commit f2e436e
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 39 deletions.
38 changes: 38 additions & 0 deletions .github/actions/brew-tap/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Brew Tap

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

runs:
using: 'composite'

steps:
- name: Add Tap
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ inputs.HOMEBREW_GITHUB_API_TOKEN }}
shell: bash -ieo pipefail {0}
run: |
brew tap brewforge/chinese
brew update
- name: Install Homebrew's dependencies
shell: bash -ieo pipefail {0}
run: |
brew install ripgrep sd gcc parallel coreutils
brew unlink coreutils && brew link coreutils
brew install-bundler-gems --groups "audit,style"
- uses: oleksiyrudenko/gha-git-credentials@v2-latest
with:
global: true
name: 'Brewforge-Bot'
email: '[email protected]'
token: '${{ inputs.HOMEBREW_GITHUB_API_TOKEN }}'

- name: show git context
shell: bash -ieo pipefail {0}
run: |
cat $HOME/.gitconfig
cat $GITHUB_ENV
11 changes: 8 additions & 3 deletions .github/actions/bump-casks/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ runs:
- name: Bump outdated casks
# continue-on-error: true
env:
HOMEBREW_DEVELOPER: '1'
HOMEBREW_GITHUB_API_TOKEN: ${{ inputs.HOMEBREW_GITHUB_API_TOKEN }}
shell: bash
shell: bash -ieo pipefail {0}
# 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
# Github Actions: 5000 requests per hour
# 1 * 60 * 24 = 1440 (because bump-pr will checkout a new branch and push to remote)
# 1 concurrent parallel jobs, 1 second delay between jobs.
run: |
parallel -j0 --group --halt now,fail=1 \
'./.github/actions/bump-casks/script.sh {}' \
parallel -j1 --delay 1s --group --halt now,fail=1 \
"./.github/actions/bump-casks/script.sh {}" \
::: $(ls $(brew --repository brewforge/chinese)/Casks/*.rb | xargs -I {} basename {} .rb)
11 changes: 8 additions & 3 deletions .github/actions/bump-formulas/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ runs:
- name: Bump outdated formulas
# continue-on-error: true
env:
HOMEBREW_DEVELOPER: '1'
HOMEBREW_GITHUB_API_TOKEN: ${{ inputs.HOMEBREW_GITHUB_API_TOKEN }}
shell: bash
shell: bash -ieo pipefail {0}
# 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
# Github Actions: 5000 requests per hour
# 1 * 60 * 24 = 1440 (because bump-pr will checkout a new branch and push to remote)
# 1 concurrent parallel jobs, 1 second delay between jobs.
run: |
parallel -j0 --group --halt now,fail=1 \
'./.github/actions/bump-formulas/script.sh {}' \
parallel -j1 --delay 1s --group --halt now,fail=1 \
"./.github/actions/bump-formulas/script.sh {}" \
::: $(ls $(brew --repository brewforge/chinese)/Formula/*.rb | xargs -I {} basename {} .rb)
31 changes: 7 additions & 24 deletions .github/actions/homebrew-env/action.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
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
shell: bash -ieo pipefail {0}
run: |
brew install parallel
# makesure brew livecheck works
brew livecheck parallel
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
- name: Add Tap
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ inputs.HOMEBREW_GITHUB_API_TOKEN }}
shell: bash
- name: Add Homebrew to PATH
shell: bash -ieo pipefail {0}
run: |
brew tap brewforge/chinese
brew update
brew install ripgrep sd
touch $HOME/.bash_profile
(echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> $HOME/.bash_profile
eval "$(/usr/local/bin/brew shellenv)"
18 changes: 18 additions & 0 deletions .github/actions/linuxbrew-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Linuxbrew Action

runs:
using: 'composite'

steps:
- name: Set up Linuxbrew
shell: bash -ieo pipefail {0}
run: |
sudo apt-get install build-essential procps curl file git
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
- name: Add Linuxbrew to PATH
shell: bash -ieo pipefail {0}
run: |
touch $HOME/.bashrc
(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> $HOME/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
49 changes: 40 additions & 9 deletions .github/workflows/main.yml → .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
name: CI
name: schedule

on:
pull_request:
branches: [main, bump-*]
push:
branches: [fix-*]
# pull_request:
# branches: [main]
# push:
# branches: [fix-*]
schedule:
# run every 12 hours
# - cron: "20 */12 * * *"
# Every day at 6am
- cron: "0 6 * * *"
# allow run manually
workflow_dispatch: {}
workflow_dispatch:

permissions: write-all

jobs:
casks:
Expand All @@ -24,11 +26,13 @@ jobs:
os: [macos-latest]

steps:
# checkout myself.
- uses: actions/checkout@v3

- name: Homebrew env
uses: ./.github/actions/homebrew-env

- name: Brew Tap
uses: ./.github/actions/brew-tap
with:
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}

Expand All @@ -44,18 +48,45 @@ jobs:

strategy:
matrix:
os: [macos-latest, ubuntu-latest]
os: [macos-latest]

steps:
# checkout myself.
- uses: actions/checkout@v3

- name: Homebrew env
uses: ./.github/actions/homebrew-env

- name: Brew Tap
uses: ./.github/actions/brew-tap
with:
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}

- name: Bump formulas
uses: ./.github/actions/bump-formulas
with:
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}

# formulas-linuxbrew:
# name: Bump Formulas in parallel (Linuxbrew)
# if: github.repository == 'brewforge/homebrew-chinese'
# runs-on: ${{ matrix.os }}

# strategy:
# matrix:
# os: [ubuntu-latest]

# steps:
# - uses: actions/checkout@v3

# - name: Linuxbrew env
# uses: ./.github/actions/linuxbrew-env

# - name: Brew Tap
# uses: ./.github/actions/brew-tap
# with:
# HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}

# - name: Bump formulas
# uses: ./.github/actions/bump-formulas
# with:
# HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}

0 comments on commit f2e436e

Please sign in to comment.