Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: cd in script's shell instead of "if"s subshell #658

Merged
merged 1 commit into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions tools/infra/container/runtime/bin/write-build-meta
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env bash
#
# write-build-meta - collect and write out build job details
# write-build-meta - collect and write out build job & environment details
#
has_command() { type "$1" &>/dev/null; }

# shellcheck source=../lib/lib.bash
source "${RUNTIME_SCRIPT_LIB:-../lib}/lib.bash"

write_common() {
echo "${USER}" > build-user
Expand All @@ -24,10 +26,13 @@ write_codebuild() {
echo "${CODEBUILD_BUILD_ARN}" > build-codebuild-arn
}

if ! { mkdir -p "build/meta" && cd "build/meta"; }; then
logger -s -t ERROR "could not create build/meta directory for writing"
if ! mkdir -p "build/meta"; then
logger -t ERROR "could not create build/meta directory for writing"
exit 1
fi
cd build/meta

# Write build environment information to disk

write_common

Expand All @@ -36,7 +41,7 @@ if [[ -n "${CODEBUILD_BUILD_ID}" ]]; then
fi

if [[ ! -s "build-service" ]]; then
logger -s -t WARN "unknown service, cannot write out CI build metadata"
logger -t WARN "unknown service, cannot write out CI build metadata"
echo "unknown" > build-service
exit 0
fi
6 changes: 6 additions & 0 deletions tools/infra/container/runtime/lib/lib.bash
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ logger() {

return 0
}

# has_command returns true for present commands
has_command() {
local name="${1:?has_command requires a name to check}"
command -v "$name" &>/dev/null
}