Skip to content

Commit 8ef950a

Browse files
committed
feat(brew-bump): add check for cleanup step
1 parent e5f03e0 commit 8ef950a

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

ci/steps/brew-bump.sh

+20-13
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ main() {
1010
echo "Checking environment variables"
1111

1212
# We need VERSION to bump the brew formula
13-
if [[ $(is_env_var_set "VERSION") -eq 1 ]]; then
13+
if is_env_var_set "VERSION"; then
1414
echo "VERSION is not set"
1515
exit 1
1616
fi
1717

1818
# We need HOMEBREW_GITHUB_API_TOKEN to push up commits
19-
if [[ $(is_env_var_set "HOMEBREW_GITHUB_API_TOKEN") -eq 1 ]]; then
19+
if is_env_var_set "HOMEBREW_GITHUB_API_TOKEN"; then
2020
echo "HOMEBREW_GITHUB_API_TOKEN is not set"
2121
exit 1
2222
fi
@@ -29,14 +29,14 @@ main() {
2929
git clone https://github.com/cdrci/homebrew-core.git
3030

3131
# Make sure the git clone step is successful
32-
if [[ $(directory_exists "homebrew-core") -eq 1 ]]; then
32+
if directory_exists "homebrew-core"; then
3333
echo "git clone failed. Cannot find homebrew-core directory."
3434
ls -la
3535
exit 1
3636
fi
3737

3838
echo "Changing into homebrew-core directory"
39-
cd homebrew-core && pwd
39+
pushd homebrew-core && pwd
4040

4141
echo "Adding Homebrew/homebrew-core"
4242
git remote add upstream https://github.com/Homebrew/homebrew-core.git
@@ -61,28 +61,31 @@ main() {
6161

6262
# GIT_ASKPASS lets us use the password when pushing without revealing it in the process list
6363
# See: https://serverfault.com/a/912788
64-
GIT_ASKPASS="$HOME/git-askpass.sh"
64+
PATH_TO_GIT_ASKPASS="$HOME/git-askpass.sh"
6565
# Source: https://serverfault.com/a/912788
6666
# shellcheck disable=SC2016,SC2028
67-
echo '#!/bin/sh\nexec echo "$HOMEBREW_GITHUB_API_TOKEN"' > "$GIT_ASKPASS"
67+
echo 'echo $HOMEBREW_GITHUB_API_TOKEN' > "$PATH_TO_ASKPASS"
6868

6969
# Make sure the git-askpass.sh file creation is successful
70-
if [[ $(file_exists "git-askpass.sh") -eq 1 ]]; then
70+
if file_exists "$PATH_TO_GIT_ASKPASS"; then
7171
echo "git-askpass.sh not found in $HOME."
7272
ls -la "$HOME"
7373
exit 1
7474
fi
7575

7676
# Ensure it's executable since we just created it
77-
chmod +x "$GIT_ASKPASS"
77+
chmod +x "$PATH_TO_GIT_ASKPASS"
7878

7979
# Make sure the git-askpass.sh file is executable
80-
if [[ $(is_executable "$GIT_ASKPASS") -eq 1 ]]; then
81-
echo "git-askpass.sh is not executable."
82-
ls -la "$GIT_ASKPASS"
80+
if is_executable "$PATH_TO_GIT_ASKPASS"; then
81+
echo "$PATH_TO_GIT_ASKPASS is not executable."
82+
ls -la "$PATH_TO_GIT_ASKPASS"
8383
exit 1
8484
fi
8585

86+
# Export the variables so git sees them
87+
export HOMEBREW_GITHUB_API_TOKEN="$HOMEBREW_GITHUB_API_TOKEN"
88+
export GIT_ASKPASS="$PATH_TO_ASKPASS"
8689
git push https://[email protected]/cdr-oss/homebrew-core.git --all
8790

8891
# Find the docs for bump-formula-pr here
@@ -98,10 +101,14 @@ main() {
98101
fi
99102

100103
# Clean up and remove homebrew-core
101-
cd ..
104+
popd
102105
rm -rf homebrew-core
103106

104-
# TODO@jsjoeio - check that homebrew-core was removed
107+
# Make sure homebrew-core is removed
108+
if directory_exists "homebrew-core"; then
109+
echo "rm -rf homebrew-core failed."
110+
ls -la
111+
fi
105112
}
106113

107114
main "$@"

ci/steps/steps-lib.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@
1010
is_env_var_set() {
1111
local name="${1:-}"
1212
if test -n "${!name:-}"; then
13-
echo 0
13+
return 0
1414
else
15-
echo 1
15+
return 1
1616
fi
1717
}
1818

1919
# Checks whether a directory exists.
2020
directory_exists() {
2121
local dir="${1:-}"
2222
if [[ -d "${dir:-}" ]]; then
23-
echo 0
23+
return 0
2424
else
25-
echo 1
25+
return 1
2626
fi
2727
}
2828

2929
# Checks whether a file exists.
3030
file_exists() {
3131
local file="${1:-}"
3232
if test -f "${file:-}"; then
33-
echo 0
33+
return 0
3434
else
35-
echo 1
35+
return 1
3636
fi
3737
}
3838

3939
# Checks whether a file is executable.
4040
is_executable() {
4141
local file="${1:-}"
4242
if [ -f "${file}" ] && [ -r "${file}" ] && [ -x "${file}" ]; then
43-
echo 0
43+
return 0
4444
else
45-
echo 1
45+
return 1
4646
fi
4747
}

test/scripts/steps-lib.bats

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,40 @@ source "$SCRIPT"
77

88
@test "is_env_var_set should return 1 if env var is not set" {
99
run is_env_var_set "ASDF_TEST_SET"
10-
[ "$output" = 1 ]
10+
[ "$status" = 1 ]
1111
}
1212

1313
@test "is_env_var_set should return 0 if env var is set" {
1414
ASDF_TEST_SET="test" run is_env_var_set "ASDF_TEST_SET"
15-
[ "$output" = 0 ]
15+
[ "$status" = 0 ]
1616
}
1717

1818
@test "directory_exists should 1 if directory doesn't exist" {
1919
run directory_exists "/tmp/asdfasdfasdf"
20-
[ "$output" = 1 ]
20+
[ "$status" = 1 ]
2121
}
2222

2323
@test "directory_exists should 0 if directory exists" {
2424
run directory_exists "$(pwd)"
25-
[ "$output" = 0 ]
25+
[ "$status" = 0 ]
2626
}
2727

2828
@test "file_exists should 1 if file doesn't exist" {
2929
run file_exists "hello-asfd.sh"
30-
[ "$output" = 1 ]
30+
[ "$status" = 1 ]
3131
}
3232

3333
@test "file_exists should 0 if file exists" {
3434
run file_exists "$SCRIPT"
35-
[ "$output" = 0 ]
35+
[ "$status" = 0 ]
3636
}
3737

3838
@test "is_executable should 1 if file isn't executable" {
3939
run is_executable "hello-asfd.sh"
40-
[ "$output" = 1 ]
40+
[ "$status" = 1 ]
4141
}
4242

4343
@test "is_executable should 0 if file is executable" {
4444
run is_executable "$SCRIPT"
45-
[ "$output" = 0 ]
45+
[ "$status" = 0 ]
4646
}

0 commit comments

Comments
 (0)