Publish tagged image #15
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Publish tagged image" | |
on: | |
workflow_dispatch: | |
push: | |
tags: | |
- 'v*' | |
release: | |
types: | |
- created | |
tags: | |
- 'v*' | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: drand/go-drand | |
jobs: | |
tagged-deploy: | |
strategy: | |
fail-fast: true | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Note: The push step is at the end of this workflow, because we want to validate the binary | |
# is the right version for this tag | |
- name: Build tagged Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: false | |
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }} | |
build-args: | | |
gitCommit: ${{ github.sha }} | |
- name: Validate versions | |
shell: bash | |
run: | | |
set -eou pipefail | |
drand_version=$(docker run --entrypoint /bin/sh -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }} -c "/usr/local/bin/drand -v | awk '{ print \"v\" \$2 }'") | |
# see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string | |
tag_version=$(git describe --tags | grep -P \ | |
'^v(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)'\ | |
'(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)'\ | |
'(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?'\ | |
'(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' | |
) | |
if [[ "$drand_version" != "$tag_version" ]]; then | |
>&2 echo "Error unexpected binary version $drand_version found on tag $tag_version" | |
exit 1 | |
fi | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: '1.22.1' | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push tagged Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }} | |
build-args: | | |
gitCommit: ${{ github.sha }} | |
# This should use the previous cached build before the validation test | |
- name: Build and push tagged Docker image without TLS | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-local:${{ github.ref_name }} | |
build-args: | | |
gitCommit: ${{ github.sha }} | |
buildTag: conn_insecure |