Skip to content

Commit 6cbbdaf

Browse files
committed
fix formula CI/CD
1 parent d2ed89c commit 6cbbdaf

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

.github/workflows/cd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@ jobs:
108108

109109
- name: Update homebrew formula
110110
# if: steps.get_branch.outputs.branch == 'main' && inputs.production_release == 'true'
111-
run: scripts/update-brew-formula.sh "dist/helloworld-*-py-none-any.whl" "daniel-makerx/homebrew-tap"
111+
run: scripts/update-brew-formula.sh "dist/helloworld-*-py3-none-any.whl" "daniel-makerx/homebrew-tap"
112112
env:
113113
API_TOKEN_GITHUB: ${{ secrets.TAP_GITHUB_TOKEN }}

scripts/update-brew-formula.sh

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@
22

33
#script arguments
44
wheel_files=( $1 )
5+
wheel_file=${wheel_files[0]}
56
homebrew_tap_repo=$2
67

8+
#error codes
9+
MISSING_WHEEL=1
10+
RESOURCE_GENERATION_FAILED=2
11+
FORMULA_GENERATION_FAILED=3
12+
PR_CREATION_FAILED=4
13+
14+
if [[ ! -f $wheel_file ]]; then
15+
>&2 echo "$wheel_file not found. 🚫"
16+
exit $MISSING_WHEEL
17+
else
18+
echo "Found $wheel_file 🎉"
19+
fi
20+
721
create_resources() {
822
local wheel=`realpath $1`
923
local package=$2
@@ -18,9 +32,9 @@ create_resources() {
1832
source venv/bin/activate
1933

2034
echo "Using poet to generate resources."
21-
pip install $wheel homebrew-pypi-poet >/dev/null 2>&1
35+
pip install $wheel homebrew-pypi-poet
2236
#also strip out resource block for referenced package
23-
local resources=`poet $package 2>/dev/null | sed "/resource \"$package\" do/{N;N;N;N;d;}"`
37+
local resources=`poet $package | sed "/resource \"$package\" do/{N;N;N;N;d;}"`
2438

2539
echo "Cleanup."
2640
deactivate
@@ -29,6 +43,15 @@ create_resources() {
2943

3044
echo "Saving resources to $output"
3145
echo "$resources" > $output
46+
lines=`wc -l < $output`
47+
48+
expected_lines=4 #assumption that there is at least one dependency
49+
if [[ ! -f $output || "$lines" -lt "$expected_lines" ]]; then
50+
>&2 echo "Failed to generate $output 🚫"
51+
exit $RESOURCE_GENERATION_FAILED
52+
else
53+
echo "Created $output 🎉"
54+
fi
3255
}
3356

3457
get_metadata() {
@@ -39,8 +62,7 @@ get_metadata() {
3962
create_formula() {
4063
repo="https://github.com/${GITHUB_REPOSITORY}"
4164
homepage="$repo"
42-
43-
wheel_file=${wheel_files[0]}
65+
4466
wheel=`basename $wheel_file`
4567
echo "Creating brew formula from $wheel_file"
4668

@@ -73,7 +95,7 @@ create_formula() {
7395
sha256=`curl -s -L $url | sha256sum | cut -f 1 -d ' '`
7496

7597
echo "Determining resources for $command..."
76-
create_resources $wheel $command resources.txt
98+
create_resources $wheel_file $command resources.txt
7799
resources=`cat resources.txt`
78100

79101
formula=`echo ${command:0:1} | tr '[a-z]' '[A-Z]'`${command:1}
@@ -93,6 +115,7 @@ class $formula < Formula
93115
license "$license"
94116
head "$head", branch: "main"
95117
118+
depends_on "pipx"
96119
depends_on "python@3.10"
97120
98121
$resources
@@ -106,21 +129,27 @@ $resources
106129
end
107130
end
108131
EOF
132+
133+
if [[ ! -f $ruby ]]; then
134+
>&2 echo "Failed to generate $ruby 🚫"
135+
exit $FORMULA_GENERATION_FAILED
136+
else
137+
echo "Created $ruby 🎉"
138+
fi
109139
}
110140

111141
create_pr() {
112142
export GH_TOKEN=$API_TOKEN_GITHUB
143+
local full_ruby=`realpath $ruby`
113144
echo "Cloning $homebrew_tap_repo..."
114145
clone_dir=`mktemp -d`
115146
git clone "https://${API_TOKEN_GITHUB}@github.com/${homebrew_tap_repo}.git" $clone_dir
116147

117-
echo "Updating Formula/$ruby..."
118-
cp $ruby $clone_dir/Formula
119-
120-
echo "Commiting..."
148+
echo "Commiting Formula/$ruby..."
121149
pushd $clone_dir
122150
dest_branch="$command-update-$version"
123151
git checkout -b $dest_branch
152+
cp $full_ruby $clone_dir/Formula
124153
git add .
125154
git commit --message "Updating $command to $version"
126155

@@ -129,11 +158,19 @@ create_pr() {
129158

130159
echo "Creating a pull request..."
131160
gh pr create --fill
161+
pr_exit_code=$?
132162

133163
popd
134164

135165
echo "Cleanup."
136166
rm -rf $clone_dir
167+
168+
if [[ $pr_exit_code != 0 ]]; then
169+
>&2 echo "PR creation failed 🚫"
170+
exit $PR_CREATION_FAILED
171+
else
172+
echo "PR creation successful 🎉"
173+
fi
137174
}
138175

139176
create_formula

0 commit comments

Comments
 (0)