Skip to content

Commit fa9bc26

Browse files
authored
ci: error if FRONTEND_VERSION not found (#2050)
Re #2042 (comment) Adding `-e` isn't enough to cause a helpful failure when `FRONTEND_VERSION` is missing from `docker-compose.yml` because: 1. it doesn't fail, despite `bash -e`, because the `jq` command runs inside the `echo` call, which succeeds, and 2. if the intention is for the failure to be easy to understand, `jq -e` won't help on its own
1 parent 42b4e0d commit fa9bc26

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

.github/workflows/main.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,7 @@ jobs:
9696

9797
- run: ./test/check-docker-context.sh --min-size 5000 --max-size 10000 --min-count 600 --max-count 700
9898

99-
- name: Extract FRONTEND_VERSION
100-
run: |
101-
touch .env
102-
echo "FRONTEND_VERSION=$(
103-
docker compose config --format json | jq -r .services.nginx.build.args.FRONTEND_VERSION
104-
)" >> "$GITHUB_ENV"
105-
99+
- run: ./files/ci/extract-frontend-version.sh
106100
- run: FRONTEND_BUILD_MODE=fetch ./test/test-images.sh
107101

108102
# Check out the current frontend version referenced by docker-compose, as it should build OK.
@@ -162,12 +156,7 @@ jobs:
162156
- name: Set up Docker Buildx
163157
uses: docker/setup-buildx-action@v4
164158

165-
- name: Extract FRONTEND_VERSION
166-
run: |
167-
touch .env
168-
echo "FRONTEND_VERSION=$(
169-
docker compose config --format json | jq -r .services.nginx.build.args.FRONTEND_VERSION
170-
)" >> "$GITHUB_ENV"
159+
- run: ./files/ci/extract-frontend-version.sh
171160

172161
- name: Build and push ${{ matrix.image }} Docker image
173162
uses: docker/build-push-action@v7
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash -eu
2+
set -o pipefail
3+
shopt -s inherit_errexit
4+
5+
log() { echo >&2 "[$(basename "$0")] $*"; }
6+
7+
log "Ensuring .env exists for docker compose..."
8+
touch .env
9+
10+
log "Reading FRONTEND_VERSION from docker-compose.yml..."
11+
if ! frontendVersion="$(docker compose config --format json | jq -er .services.nginx.build.args.FRONTEND_VERSION)"; then
12+
log "!!!"
13+
log "!!! Failed to read FRONTEND_VERSION from docker-compose.yml (got: '$frontendVersion')."
14+
log "!!!"
15+
exit 1
16+
fi
17+
18+
log "Writing FRONTEND_VERSION to GITHUB_ENV file ($GITHUB_ENV)..."
19+
echo "FRONTEND_VERSION=$frontendVersion" >> "$GITHUB_ENV"
20+
21+
log "Completed OK."

0 commit comments

Comments
 (0)