|
59 | 59 |
|
60 | 60 | # Compute tags. We want the following behaviour:
|
61 | 61 | #
|
62 |
| - # 1. Building on tag: image tagged `tag` |
63 |
| - # 2. Building on release: image tagged `latest` |
| 62 | + # 1. Building on tag: |
| 63 | + # |
| 64 | + # a. Image tagged `<tag>` |
| 65 | + # |
| 66 | + # b. If the tag is the "latest" one for the present major release, |
| 67 | + # then also tag it as "latest" |
| 68 | + # |
64 | 69 | # 3. Building on master: image tagged `unstable`.
|
65 | 70 |
|
66 | 71 | # Let's default to 'unstable'.
|
|
75 | 80 | IMAGE_LABEL=${{github.ref_name}} && \
|
76 | 81 | VERSION=${{github.ref_name}}
|
77 | 82 |
|
78 |
| - # If we're running on the release branch, tag it as `latest`, |
79 |
| - # and leave the version as the git commit. |
80 |
| - [[ ${GITHUB_REF_NAME} = "release" ]] && \ |
81 |
| - IMAGE_LABEL=latest |
82 |
| -
|
83 | 83 | # If we're running on master, tag it as "unstable" and
|
84 |
| - # and again leave the version as the git commit. |
| 84 | + # and leave the version as the git commit. |
85 | 85 | [[ ${GITHUB_REF_NAME} = "master" ]] && \
|
86 | 86 | IMAGE_LABEL=unstable
|
87 | 87 |
|
|
95 | 95 | --label org.opencontainers.image.version=${VERSION} \
|
96 | 96 | --tag ${IMAGE_NAME}:${IMAGE_LABEL} -
|
97 | 97 |
|
| 98 | + # Tag the build as 'latest' if it's the latest tag. |
| 99 | + if [[ ${BUILDING_TAG} = true ]]; then |
| 100 | + # Build a sorted list of tags . We have to grep-exclude some tags |
| 101 | + # that we don't want to include; i.e. ones that don't point to our |
| 102 | + # actual releases. |
| 103 | + git tag -l | grep -P '^\d+.\d+.\d+$' >tags.txt |
| 104 | +
|
| 105 | + # Get the largest one (sort -V sorts as versions). |
| 106 | + sort -V tags.txt | tail -n1 >latest.txt |
| 107 | +
|
| 108 | + # Compare it to mine; and if it's the same, then I am the latest, so |
| 109 | + # we can tag it as such. |
| 110 | + echo ${{ github.ref_name }}>mine.txt |
| 111 | +
|
| 112 | + # Note: This will also print the diff if it fails, which is useful |
| 113 | + # for debugging. |
| 114 | + if (diff mine.txt latest.txt); then |
| 115 | + docker tag ${IMAGE_NAME}:${IMAGE_LABEL} ${IMAGE_NAME}:latest |
| 116 | + fi |
| 117 | + fi |
| 118 | +
|
98 | 119 | # Also tag with ref name when manually dispatched
|
99 | 120 | [[ ${{github.event_name == 'workflow_dispatch'}} = true ]] && \
|
100 | 121 | docker tag ${IMAGE_NAME}:${IMAGE_LABEL} ${IMAGE_NAME}:workflow_dispatch-${{github.event.inputs.ref_name}}
|
|
0 commit comments