Skip to content

Commit 2382dfd

Browse files
authored
Read the latest release version for the Docker image tag with the workflow token (#265)
### Problem The `build-docker` and `build-docker-alpine` jobs get the version for the image tag from an anonymous `curl` to `api.github.com/repos/OpenIdentityPlatform/OpenIDM/releases/latest`. In run [39763486259](https://github.com/OpenIdentityPlatform/OpenIDM/actions/runs/39763486259) of #264 the answer to `build-docker` had no `"name"`. The step printed `last release: ` and still passed, the tag came out empty, and `build-push-action` failed with `tag is needed when pushing to registry`. `build-docker-alpine` of the same run got `7.1.2`. The step does not log the answer. The likely cause is the rate limit for anonymous API calls, which the runner's IP shares with other jobs. Two more weaknesses hid the failure: - `export var="$(...)"` returns the status of `export`, so a failed call cannot fail the step; - an empty version passes the step, so the failure surfaces two steps later as a buildx error. ### Fix In both jobs the `Get latest release version` step: - calls the API through `gh api ... --jq .name` with `GH_TOKEN: ${{ github.token }}`. The jobs already have `contents: read`. An authenticated call has its own rate limit and does not share the runner's IP limit; - assigns the version without `export`, so a failed `gh` call fails the step through `-e` and logs its error; - fails with `test -n` when the version is empty. ### Test - Locally `gh api repos/OpenIdentityPlatform/OpenIDM/releases/latest --jq .name` returns `7.1.2`, the same value the old `grep`/`cut` gave. - In the run of this PR, both `build-docker` and `build-docker-alpine` must print `last release: 7.1.2` and build the image.
1 parent 169a8a8 commit 2382dfd

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,14 @@ jobs:
346346
grep -q '^COPY openidm-zip/target/openidm-' ./Dockerfile
347347
- name: Get latest release version
348348
shell: bash
349+
env:
350+
# an anonymous call shares the API rate limit of the runner's IP with other jobs and,
351+
# once that is used up, left the version and with it the image tag empty
352+
GH_TOKEN: ${{ github.token }}
349353
run: |
350-
export git_version_last="$(curl -i -o - --silent https://api.github.com/repos/OpenIdentityPlatform/OpenIDM/releases/latest | grep -m1 "\"name\"" | cut -d\" -f4)" ; echo "last release: $git_version_last"
354+
# no "export" in front: it would hide a failed gh call from the -e of the step
355+
git_version_last="$(gh api repos/OpenIdentityPlatform/OpenIDM/releases/latest --jq .name)" ; echo "last release: $git_version_last"
356+
test -n "$git_version_last"
351357
echo "release_version=$git_version_last" >> $GITHUB_ENV
352358
echo "image_repository=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
353359
- name: Docker meta
@@ -442,8 +448,14 @@ jobs:
442448
grep -q '^COPY openidm-zip/target/openidm-' ./Dockerfile-alpine
443449
- name: Get latest release version
444450
shell: bash
451+
env:
452+
# an anonymous call shares the API rate limit of the runner's IP with other jobs and,
453+
# once that is used up, left the version and with it the image tag empty
454+
GH_TOKEN: ${{ github.token }}
445455
run: |
446-
export git_version_last="$(curl -i -o - --silent https://api.github.com/repos/OpenIdentityPlatform/OpenIDM/releases/latest | grep -m1 "\"name\"" | cut -d\" -f4)" ; echo "last release: $git_version_last"
456+
# no "export" in front: it would hide a failed gh call from the -e of the step
457+
git_version_last="$(gh api repos/OpenIdentityPlatform/OpenIDM/releases/latest --jq .name)" ; echo "last release: $git_version_last"
458+
test -n "$git_version_last"
447459
echo "release_version=$git_version_last" >> $GITHUB_ENV
448460
echo "image_repository=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
449461
- name: Docker meta

0 commit comments

Comments
 (0)