Skip to content

Commit 96ea7c9

Browse files
committed
actions: fix scripts of bump-pr and brew-audit
1 parent 8a7e48d commit 96ea7c9

File tree

5 files changed

+133
-54
lines changed

5 files changed

+133
-54
lines changed

.github/actions/brew-audit/script.sh

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# ========================
6+
# brew audit
7+
echo "> Running brew audit..."
8+
brew audit --tap brewforge/chinese -v
9+
10+
# ========================
11+
# bump dry-run for homebrew
12+
echo "> Running brew bump dry-run..."
13+
14+
items=$(brew livecheck --tap brewforge/chinese --full-name --json || echo "[]")
15+
16+
for item in $(echo $items | jq -r '.[] | .formula, .cask'); do
17+
if [ "$item" == "null" ]; then
18+
continue
19+
fi
20+
21+
echo "---" # newline
22+
23+
item_obj=$(echo $items | jq --arg item "$item" '.[] | select(.formula == $item or .cask == $item)')
24+
25+
is_cask=$(echo $item_obj | jq -r '.cask')
26+
is_formula=$(echo $item_obj | jq -r '.formula')
27+
28+
item_status=$(echo $item_obj | jq -r '.status')
29+
item_version_current=$(echo $item_obj | jq -r '.version.current')
30+
item_version_latest=$(echo $item_obj | jq -r '.version.latest')
31+
item_outdated=$(echo $item_obj | jq -r '.version.outdated')
32+
item_newer=$(echo $item_obj | jq -r '.version.newer_than_upstream')
33+
34+
if [ "$item_status" == "skipped" ]; then
35+
# skipped.
36+
echo -e "$item: \033[0;31m$(echo $item_obj | jq -r '.messages[0]')\033[0m"
37+
continue
38+
elif [ "$item_outdated" == "false" ]; then
39+
# up-to-date.
40+
echo -e "$item: \033[0;32mUp-to-date\033[0m"
41+
continue
42+
elif [ "$item_newer" == "true" ]; then
43+
# newer than upstream.
44+
echo -e "$item: \033[0;33mNewer than upstream\033[0m"
45+
continue
46+
fi
47+
48+
# bump.
49+
echo "> Bumping $item from $item_version_current to $item_version_latest..."
50+
51+
if [ "$item_version_latest" == "null" ]; then
52+
echo $item_obj
53+
54+
if [ -n "$is_cask" ]; then
55+
cat "$(brew edit --cask $item --print-path)"
56+
elif [ -n "$is_formula" ]; then
57+
cat "$(brew edit $item --print-path)"
58+
fi
59+
fi
60+
61+
if [ "$is_cask" != "null" ]; then
62+
brew bump-cask-pr $item --version=$item_version_latest --verbose --dry-run
63+
# echo "> TDOO: brew bump-cask-pr $item --version=$item_version_latest --verbose --dry-run"
64+
elif [ "$is_formula" != "null" ]; then
65+
# brew bump-formula-pr $item --version=$item_version_latest --verbose --dry-run
66+
echo -e "\033[0;33m> TDOO: brew bump-formula-pr $item --version=$item_version_latest --verbose --dry-run\033[0m"
67+
fi
68+
69+
echo "> Done for $item"
70+
done

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

-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
name: Brew Tap
22
description: Homebrew Tap
33

4-
inputs:
5-
HOMEBREW_GITHUB_API_TOKEN:
6-
description: "Homebrew GitHub API Token"
7-
required: true
8-
94
runs:
105
using: "composite"
116

127
steps:
138
- name: Add Tap
14-
env:
15-
HOMEBREW_GITHUB_API_TOKEN: ${{ inputs.HOMEBREW_GITHUB_API_TOKEN }}
169
shell: bash -ieo pipefail {0}
1710
run: |
1811
brew tap brewforge/chinese
19-
cp -rf ./* "$(brew --repository brewforge/chinese)"
2012
2113
- name: Install Homebrew's dependencies
2214
shell: bash -ieo pipefail {0}

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

+49-41
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,68 @@
33
set -e
44

55
# ========================
6-
# Bump casks for Homebrew
7-
casks=$(brew livecheck --tap brewforge/chinese --casks --json)
6+
# brew audit
7+
echo "> Running brew audit..."
8+
brew audit --tap brewforge/chinese -v
89

9-
for cask in $(echo $casks | jq -r '.[] | .cask'); do
10-
cask_obj=$(echo $casks | jq --arg cask "$cask" '.[] | select(.cask == $cask)')
10+
# ========================
11+
# bump dry-run for homebrew
12+
echo "> Running brew bump dry-run..."
1113

12-
cask_status=$(echo $cask_obj | jq -r '.status // empty')
13-
cask_version_current=$(echo $cask_obj | jq -r '.version.current')
14-
cask_version_latest=$(echo $cask_obj | jq -r '.version.latest')
15-
cask_outdated=$(echo $cask_obj | jq -r '.version.outdated')
16-
cask_newer=$(echo $cask_obj | jq -r '.version.newer_than_upstream')
14+
items=$(brew livecheck --tap brewforge/chinese --full-name --json || echo "[]")
1715

18-
if [ "$cask_status" == "skipped" ]; then
19-
echo -e "$cask: \033[0;31m$(echo $cask_obj | jq -r '.messages[0]')\033[0m"
20-
continue
21-
elif [ "$cask_outdated" == "false" ]; then
22-
echo -e "$cask: \033[0;32mUp-to-date\033[0m"
23-
continue
24-
elif [ "$cask_newer" == "true" ]; then
25-
echo -e "$cask: \033[0;33mNewer than upstream\033[0m"
16+
for item in $(echo $items | jq -r '.[] | .formula, .cask'); do
17+
if [ "$item" == "null" ]; then
2618
continue
2719
fi
2820

29-
echo "> Bumping $cask from $cask_version_current to $cask_version_latest..."
30-
brew bump-cask-pr $cask --version=$cask_version_latest --verbose
31-
echo "> Done for $cask"
32-
done
21+
echo "---" # newline
3322

34-
# ========================
35-
# Bump formulae for Homebrew
36-
formulae=$(brew livecheck --tap brewforge/chinese --formulae --json)
23+
item_obj=$(echo $items | jq --arg item "$item" '.[] | select(.formula == $item or .cask == $item)')
3724

38-
for formula in $(echo $formulae | jq -r '.[] | .formula'); do
39-
formula_obj=$(echo $formulae | jq --arg formula "$formula" '.[] | select(.formula == $formula)')
25+
is_cask=$(echo $item_obj | jq -r '.cask')
26+
is_formula=$(echo $item_obj | jq -r '.formula')
4027

41-
formula_status=$(echo $formula_obj | jq -r '.status // empty')
42-
formula_version_current=$(echo $formula_obj | jq -r '.version.current')
43-
formula_version_latest=$(echo $formula_obj | jq -r '.version.latest')
44-
formula_outdated=$(echo $formula_obj | jq -r '.version.outdated')
45-
formula_newer=$(echo $formula_obj | jq -r '.version.newer_than_upstream')
28+
item_status=$(echo $item_obj | jq -r '.status')
29+
item_version_current=$(echo $item_obj | jq -r '.version.current')
30+
item_version_latest=$(echo $item_obj | jq -r '.version.latest')
31+
item_outdated=$(echo $item_obj | jq -r '.version.outdated')
32+
item_newer=$(echo $item_obj | jq -r '.version.newer_than_upstream')
4633

47-
if [ "$formula_status" == "skipped" ]; then
48-
echo -e "$formula: \033[0;31m$(echo $formula_obj | jq -r '.messages[0]')\033[0m"
34+
if [ "$item_status" == "skipped" ]; then
35+
# skipped.
36+
echo -e "$item: \033[0;31m$(echo $item_obj | jq -r '.messages[0]')\033[0m"
4937
continue
50-
elif [ "$formula_outdated" == "false" ]; then
51-
echo -e "$formula: \033[0;32mUp-to-date\033[0m"
38+
elif [ "$item_outdated" == "false" ]; then
39+
# up-to-date.
40+
echo -e "$item: \033[0;32mUp-to-date\033[0m"
5241
continue
53-
elif [ "$formula_newer" == "true" ]; then
54-
echo -e "$formula: \033[0;33mNewer than upstream\033[0m"
42+
elif [ "$item_newer" == "true" ]; then
43+
# newer than upstream.
44+
echo -e "$item: \033[0;33mNewer than upstream\033[0m"
5545
continue
5646
fi
5747

58-
echo "> Bumping $formula from $formula_version_current to $formula_version_latest..."
59-
# brew bump-formula-pr $formula --version=$formula_version_latest --verbose
60-
echo -e "\033[0;33m> TDOO: brew bump-formula-pr $formula --version=$formula_version_latest --verbose\033[0m"
61-
echo "> Done for $formula"
48+
# bump.
49+
echo "> Bumping $item from $item_version_current to $item_version_latest..."
50+
51+
if [ "$item_version_latest" == "null" ]; then
52+
echo $item_obj
53+
54+
if [ -n "$is_cask" ]; then
55+
cat "$(brew edit --cask $item --print-path)"
56+
elif [ -n "$is_formula" ]; then
57+
cat "$(brew edit $item --print-path)"
58+
fi
59+
fi
60+
61+
if [ "$is_cask" != "null" ]; then
62+
brew bump-cask-pr $item --version=$item_version_latest --verbose
63+
# echo "> TDOO: brew bump-cask-pr $item --version=$item_version_latest --verbose"
64+
elif [ "$is_formula" != "null" ]; then
65+
# brew bump-formula-pr $item --version=$item_version_latest --verbose
66+
echo -e "\033[0;33m> TDOO: brew bump-formula-pr $item --version=$item_version_latest --verbose\033[0m"
67+
fi
68+
69+
echo "> Done for $item"
6270
done

.github/workflows/audit.yml

+11-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ on:
88
branches:
99
- '**'
1010

11-
permissions: write-all
11+
concurrency:
12+
group: ${{ github.head_ref || github.ref_name }}
13+
# cancel-in-progress: true
14+
15+
# permissions: write-all
1216

1317
jobs:
1418
audit:
@@ -30,8 +34,10 @@ jobs:
3034

3135
- name: Brew Audit
3236
shell: bash -ieo pipefail {0}
37+
env:
38+
HOMEBREW_DEVELOPER: "1"
39+
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
3340
run: |
34-
brew audit --tap brewforge/chinese -v
35-
# TODO: livecheck
36-
# TODO: bump-cask-pr dry-run
37-
# TODO: bump-formula-pr dry-run
41+
cp -rf ./ "$(brew --repository brewforge/chinese)"
42+
cd "$(brew --repository brewforge/chinese)"
43+
./.github/actions/brew-audit/script.sh

.github/workflows/schedule.yml

+3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ jobs:
4444
HOMEBREW_DEVELOPER: "1"
4545
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
4646
shell: bash -ieo pipefail {0}
47+
timeout-minutes: 60
4748
run: |
49+
cp -rf ./ "$(brew --repository brewforge/chinese)"
50+
cd "$(brew --repository brewforge/chinese)"
4851
./.github/actions/bump-pr/script.sh
4952
5053
# formulas-linuxbrew:

0 commit comments

Comments
 (0)