Repository navigation
Commit 2382dfd
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
349 | 353 | | |
350 | | - | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
351 | 357 | | |
352 | 358 | | |
353 | 359 | | |
| |||
442 | 448 | | |
443 | 449 | | |
444 | 450 | | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
445 | 455 | | |
446 | | - | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
447 | 459 | | |
448 | 460 | | |
449 | 461 | | |
| |||
0 commit comments