feat(brew-bump): add check for cleanup step
This commit is contained in:
parent
e5f03e0b06
commit
8ef950af4c
|
@ -10,13 +10,13 @@ main() {
|
||||||
echo "Checking environment variables"
|
echo "Checking environment variables"
|
||||||
|
|
||||||
# We need VERSION to bump the brew formula
|
# We need VERSION to bump the brew formula
|
||||||
if [[ $(is_env_var_set "VERSION") -eq 1 ]]; then
|
if is_env_var_set "VERSION"; then
|
||||||
echo "VERSION is not set"
|
echo "VERSION is not set"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# We need HOMEBREW_GITHUB_API_TOKEN to push up commits
|
# We need HOMEBREW_GITHUB_API_TOKEN to push up commits
|
||||||
if [[ $(is_env_var_set "HOMEBREW_GITHUB_API_TOKEN") -eq 1 ]]; then
|
if is_env_var_set "HOMEBREW_GITHUB_API_TOKEN"; then
|
||||||
echo "HOMEBREW_GITHUB_API_TOKEN is not set"
|
echo "HOMEBREW_GITHUB_API_TOKEN is not set"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -29,14 +29,14 @@ main() {
|
||||||
git clone https://github.com/cdrci/homebrew-core.git
|
git clone https://github.com/cdrci/homebrew-core.git
|
||||||
|
|
||||||
# Make sure the git clone step is successful
|
# Make sure the git clone step is successful
|
||||||
if [[ $(directory_exists "homebrew-core") -eq 1 ]]; then
|
if directory_exists "homebrew-core"; then
|
||||||
echo "git clone failed. Cannot find homebrew-core directory."
|
echo "git clone failed. Cannot find homebrew-core directory."
|
||||||
ls -la
|
ls -la
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Changing into homebrew-core directory"
|
echo "Changing into homebrew-core directory"
|
||||||
cd homebrew-core && pwd
|
pushd homebrew-core && pwd
|
||||||
|
|
||||||
echo "Adding Homebrew/homebrew-core"
|
echo "Adding Homebrew/homebrew-core"
|
||||||
git remote add upstream https://github.com/Homebrew/homebrew-core.git
|
git remote add upstream https://github.com/Homebrew/homebrew-core.git
|
||||||
|
@ -61,28 +61,31 @@ main() {
|
||||||
|
|
||||||
# GIT_ASKPASS lets us use the password when pushing without revealing it in the process list
|
# GIT_ASKPASS lets us use the password when pushing without revealing it in the process list
|
||||||
# See: https://serverfault.com/a/912788
|
# See: https://serverfault.com/a/912788
|
||||||
GIT_ASKPASS="$HOME/git-askpass.sh"
|
PATH_TO_GIT_ASKPASS="$HOME/git-askpass.sh"
|
||||||
# Source: https://serverfault.com/a/912788
|
# Source: https://serverfault.com/a/912788
|
||||||
# shellcheck disable=SC2016,SC2028
|
# shellcheck disable=SC2016,SC2028
|
||||||
echo '#!/bin/sh\nexec echo "$HOMEBREW_GITHUB_API_TOKEN"' > "$GIT_ASKPASS"
|
echo 'echo $HOMEBREW_GITHUB_API_TOKEN' > "$PATH_TO_ASKPASS"
|
||||||
|
|
||||||
# Make sure the git-askpass.sh file creation is successful
|
# Make sure the git-askpass.sh file creation is successful
|
||||||
if [[ $(file_exists "git-askpass.sh") -eq 1 ]]; then
|
if file_exists "$PATH_TO_GIT_ASKPASS"; then
|
||||||
echo "git-askpass.sh not found in $HOME."
|
echo "git-askpass.sh not found in $HOME."
|
||||||
ls -la "$HOME"
|
ls -la "$HOME"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure it's executable since we just created it
|
# Ensure it's executable since we just created it
|
||||||
chmod +x "$GIT_ASKPASS"
|
chmod +x "$PATH_TO_GIT_ASKPASS"
|
||||||
|
|
||||||
# Make sure the git-askpass.sh file is executable
|
# Make sure the git-askpass.sh file is executable
|
||||||
if [[ $(is_executable "$GIT_ASKPASS") -eq 1 ]]; then
|
if is_executable "$PATH_TO_GIT_ASKPASS"; then
|
||||||
echo "git-askpass.sh is not executable."
|
echo "$PATH_TO_GIT_ASKPASS is not executable."
|
||||||
ls -la "$GIT_ASKPASS"
|
ls -la "$PATH_TO_GIT_ASKPASS"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Export the variables so git sees them
|
||||||
|
export HOMEBREW_GITHUB_API_TOKEN="$HOMEBREW_GITHUB_API_TOKEN"
|
||||||
|
export GIT_ASKPASS="$PATH_TO_ASKPASS"
|
||||||
git push https://cdr-oss@github.com/cdr-oss/homebrew-core.git --all
|
git push https://cdr-oss@github.com/cdr-oss/homebrew-core.git --all
|
||||||
|
|
||||||
# Find the docs for bump-formula-pr here
|
# Find the docs for bump-formula-pr here
|
||||||
|
@ -98,10 +101,14 @@ main() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean up and remove homebrew-core
|
# Clean up and remove homebrew-core
|
||||||
cd ..
|
popd
|
||||||
rm -rf homebrew-core
|
rm -rf homebrew-core
|
||||||
|
|
||||||
# TODO@jsjoeio - check that homebrew-core was removed
|
# Make sure homebrew-core is removed
|
||||||
|
if directory_exists "homebrew-core"; then
|
||||||
|
echo "rm -rf homebrew-core failed."
|
||||||
|
ls -la
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
is_env_var_set() {
|
is_env_var_set() {
|
||||||
local name="${1:-}"
|
local name="${1:-}"
|
||||||
if test -n "${!name:-}"; then
|
if test -n "${!name:-}"; then
|
||||||
echo 0
|
return 0
|
||||||
else
|
else
|
||||||
echo 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,9 +20,9 @@ is_env_var_set() {
|
||||||
directory_exists() {
|
directory_exists() {
|
||||||
local dir="${1:-}"
|
local dir="${1:-}"
|
||||||
if [[ -d "${dir:-}" ]]; then
|
if [[ -d "${dir:-}" ]]; then
|
||||||
echo 0
|
return 0
|
||||||
else
|
else
|
||||||
echo 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,9 +30,9 @@ directory_exists() {
|
||||||
file_exists() {
|
file_exists() {
|
||||||
local file="${1:-}"
|
local file="${1:-}"
|
||||||
if test -f "${file:-}"; then
|
if test -f "${file:-}"; then
|
||||||
echo 0
|
return 0
|
||||||
else
|
else
|
||||||
echo 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,8 +40,8 @@ file_exists() {
|
||||||
is_executable() {
|
is_executable() {
|
||||||
local file="${1:-}"
|
local file="${1:-}"
|
||||||
if [ -f "${file}" ] && [ -r "${file}" ] && [ -x "${file}" ]; then
|
if [ -f "${file}" ] && [ -r "${file}" ] && [ -x "${file}" ]; then
|
||||||
echo 0
|
return 0
|
||||||
else
|
else
|
||||||
echo 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,40 +7,40 @@ source "$SCRIPT"
|
||||||
|
|
||||||
@test "is_env_var_set should return 1 if env var is not set" {
|
@test "is_env_var_set should return 1 if env var is not set" {
|
||||||
run is_env_var_set "ASDF_TEST_SET"
|
run is_env_var_set "ASDF_TEST_SET"
|
||||||
[ "$output" = 1 ]
|
[ "$status" = 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "is_env_var_set should return 0 if env var is set" {
|
@test "is_env_var_set should return 0 if env var is set" {
|
||||||
ASDF_TEST_SET="test" run is_env_var_set "ASDF_TEST_SET"
|
ASDF_TEST_SET="test" run is_env_var_set "ASDF_TEST_SET"
|
||||||
[ "$output" = 0 ]
|
[ "$status" = 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "directory_exists should 1 if directory doesn't exist" {
|
@test "directory_exists should 1 if directory doesn't exist" {
|
||||||
run directory_exists "/tmp/asdfasdfasdf"
|
run directory_exists "/tmp/asdfasdfasdf"
|
||||||
[ "$output" = 1 ]
|
[ "$status" = 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "directory_exists should 0 if directory exists" {
|
@test "directory_exists should 0 if directory exists" {
|
||||||
run directory_exists "$(pwd)"
|
run directory_exists "$(pwd)"
|
||||||
[ "$output" = 0 ]
|
[ "$status" = 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "file_exists should 1 if file doesn't exist" {
|
@test "file_exists should 1 if file doesn't exist" {
|
||||||
run file_exists "hello-asfd.sh"
|
run file_exists "hello-asfd.sh"
|
||||||
[ "$output" = 1 ]
|
[ "$status" = 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "file_exists should 0 if file exists" {
|
@test "file_exists should 0 if file exists" {
|
||||||
run file_exists "$SCRIPT"
|
run file_exists "$SCRIPT"
|
||||||
[ "$output" = 0 ]
|
[ "$status" = 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "is_executable should 1 if file isn't executable" {
|
@test "is_executable should 1 if file isn't executable" {
|
||||||
run is_executable "hello-asfd.sh"
|
run is_executable "hello-asfd.sh"
|
||||||
[ "$output" = 1 ]
|
[ "$status" = 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "is_executable should 0 if file is executable" {
|
@test "is_executable should 0 if file is executable" {
|
||||||
run is_executable "$SCRIPT"
|
run is_executable "$SCRIPT"
|
||||||
[ "$output" = 0 ]
|
[ "$status" = 0 ]
|
||||||
}
|
}
|
Loading…
Reference in New Issue