Skip to content

Commit 167ab28

Browse files
authored
fix: fix ERRPIPE in build scripts, fix deploy (#2492)
1 parent 075e891 commit 167ab28

File tree

2 files changed

+70
-43
lines changed

2 files changed

+70
-43
lines changed

.github/workflows/coder.yaml

+17-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,23 @@ jobs:
372372
run: make -B site/out/index.html
373373

374374
- name: Build Release
375-
run: make build
375+
run: |
376+
set -euo pipefail
377+
go mod download
378+
379+
mkdir -p ./dist
380+
# build slim binaries
381+
./scripts/build_go_slim.sh \
382+
--output ./dist/ \
383+
linux:amd64,armv7,arm64 \
384+
windows:amd64,arm64 \
385+
darwin:amd64,arm64
386+
387+
# build linux amd64 packages
388+
./scripts/build_go_matrix.sh \
389+
--output ./dist/ \
390+
--package-linux \
391+
linux:amd64
376392
377393
- name: Install Release
378394
run: |

scripts/lib.sh

+53-42
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ PROJECT_ROOT="$(cd "$SCRIPT_DIR" && realpath "$(git rev-parse --show-toplevel)")
3535

3636
# pushd is a silent alternative to the real pushd shell command.
3737
pushd() {
38-
command pushd "$@" >/dev/null
38+
command pushd "$@" >/dev/null || error "Could not pushd to '$*'"
3939
}
4040

4141
# popd is a silent alternative to the real popd shell command.
4242
# shellcheck disable=SC2120
4343
popd() {
44-
command popd "$@" >/dev/null
44+
command popd >/dev/null || error "Could not restore directory with popd"
4545
}
4646

4747
# cdself changes directory to the directory of the current script. This should
@@ -116,51 +116,62 @@ isdarwin() {
116116
[[ "${OSTYPE:-darwin}" == *darwin* ]]
117117
}
118118

119-
libsh_bad_dependencies=0
119+
# We don't need to check dependencies more than once per script, but some
120+
# scripts call other scripts that also `source lib.sh`, so we set an environment
121+
# variable after successfully checking dependencies once.
122+
if [[ "${CODER_LIBSH_NO_CHECK_DEPENDENCIES:-}" != *t* ]]; then
123+
libsh_bad_dependencies=0
124+
125+
if ((BASH_VERSINFO[0] < 4)); then
126+
libsh_bad_dependencies=1
127+
log "ERROR: You need at least bash 4.0 to run the scripts in the Coder repo."
128+
if isdarwin; then
129+
log "On darwin:"
130+
log "- brew install bash"
131+
log "- Restart your terminal"
132+
fi
133+
log
134+
fi
120135

121-
if ((BASH_VERSINFO[0] < 4)); then
122-
libsh_bad_dependencies=1
123-
log "ERROR: You need at least bash 4.0 to run the scripts in the Coder repo."
124-
if isdarwin; then
125-
log "On darwin:"
126-
log "- brew install bash"
127-
log "- Restart your terminal"
136+
# BSD getopt (which is installed by default on Macs) is not supported.
137+
if [[ "$(getopt --version)" == *--* ]]; then
138+
libsh_bad_dependencies=1
139+
log "ERROR: You need GNU getopt to run the scripts in the Coder repo."
140+
if isdarwin; then
141+
log "On darwin:"
142+
log "- brew install gnu-getopt"
143+
# shellcheck disable=SC2016
144+
log '- Add "$(brew --prefix)/opt/gnu-getopt/bin" to your PATH'
145+
log "- Restart your terminal"
146+
fi
147+
log
128148
fi
129-
log
130-
fi
131149

132-
# BSD getopt (which is installed by default on Macs) is not supported.
133-
if [[ "$(getopt --version)" == *--* ]]; then
134-
libsh_bad_dependencies=1
135-
log "ERROR: You need GNU getopt to run the scripts in the Coder repo."
136-
if isdarwin; then
137-
log "On darwin:"
138-
log "- brew install gnu-getopt"
139-
# shellcheck disable=SC2016
140-
log '- Add "$(brew --prefix)/opt/gnu-getopt/bin" to your PATH'
141-
log "- Restart your terminal"
150+
# The bash scripts don't call Make directly, but we want to make (ha ha)
151+
# sure that make supports the features the repo uses. Notably, Macs have an
152+
# old version of Make installed out of the box that doesn't support new
153+
# features like ONESHELL.
154+
#
155+
# Piping commands directly into `head -n1` may result in ERRPIPE errors, so
156+
# we capture the version output first before
157+
make_version_raw="$(make --version 2>/dev/null)"
158+
make_version="$(echo "$make_version_raw" | head -n1 | grep -oE '([[:digit:]]+\.){1,2}[[:digit:]]+')"
159+
if [ "${make_version//.*/}" -lt 4 ]; then
160+
libsh_bad_dependencies=1
161+
log "ERROR: You need at least make 4.0 to run the scripts in the Coder repo."
162+
if isdarwin; then
163+
log "On darwin:"
164+
log "- brew install make"
165+
# shellcheck disable=SC2016
166+
log '- Add "$(brew --prefix)/opt/make/libexec/gnubin" to your PATH (you should Google this first)'
167+
log "- Restart your terminal"
168+
fi
169+
log
142170
fi
143-
log
144-
fi
145171

146-
# The bash scripts don't call Make directly, but we want to make (ha ha) sure
147-
# that make supports the features the repo uses. Notably, Macs have an old
148-
# version of Make installed out of the box that doesn't support new features
149-
# like ONESHELL.
150-
make_version="$(make --version 2>/dev/null | head -n1 | grep -oE '([[:digit:]]+\.){1,2}[[:digit:]]+')"
151-
if [ "${make_version//.*/}" -lt 4 ]; then
152-
libsh_bad_dependencies=1
153-
log "ERROR: You need at least make 4.0 to run the scripts in the Coder repo."
154-
if isdarwin; then
155-
log "On darwin:"
156-
log "- brew install make"
157-
# shellcheck disable=SC2016
158-
log '- Add "$(brew --prefix)/opt/make/libexec/gnubin" to your PATH (you should Google this first)'
159-
log "- Restart your terminal"
172+
if [[ "$libsh_bad_dependencies" == 1 ]]; then
173+
error "Invalid dependencies, see above for more details."
160174
fi
161-
log
162-
fi
163175

164-
if [[ "$libsh_bad_dependencies" == 1 ]]; then
165-
error "Invalid dependencies, see above for more details."
176+
export CODER_LIBSH_NO_CHECK_DEPENDENCIES=true
166177
fi

0 commit comments

Comments
 (0)