From ce529fd6d8d2a9ddd6b25ea19048a8b7bc9eb864 Mon Sep 17 00:00:00 2001 From: Daniel Moore <9156191+drmrd@users.noreply.github.com> Date: Wed, 29 Nov 2023 17:51:38 -0500 Subject: [PATCH] Specify Docker image version tag in a config file Signed-off-by: Daniel Moore <9156191+drmrd@users.noreply.github.com> --- .docker_image_version | 1 + .github/workflows/cicd.yaml | 35 +++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 .docker_image_version diff --git a/.docker_image_version b/.docker_image_version new file mode 100644 index 00000000..bcab45af --- /dev/null +++ b/.docker_image_version @@ -0,0 +1 @@ +0.0.3 diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index e63d01f4..c7085591 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -1,11 +1,6 @@ name: cicd on: - push: - branches: - - 'build_pkg_**' - tags: - - 'v*' pull_request: branches: - 'main' @@ -13,11 +8,6 @@ on: jobs: docker-build-and-push-images: runs-on: ubuntu-latest - - permissions: - contents: read - packages: write - strategy: matrix: include: @@ -31,6 +21,25 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Ensure Docker image version is not referencing an existing release + id: docker-image-version-check + run: | + if ! [[ -s .docker_image_version ]]; then + echo 'Error: No .docker_image_version file found.' + exit 1 + fi + + SEMVER="$(cat .docker_images_version)" + if git show-ref --tags --verify --quiet "refs/tags/v${SEMVER}"; then + echo "Error: The tag 'v${SEMVER}' is already a GitHub release.' + echo ' Please update the version in .docker_image_version' + exit 1 + else + echo "SEMVER=${SEMVER}" >> "${GITHUB_OUTPUT}" + fi - name: Set Docker image metadata id: meta @@ -40,11 +49,9 @@ jobs: tags: | type=ref,event=branch type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} + type=semver,pattern=${{ steps.docker-image-version-check.SEMVER }} - name: Log into GitHub container registry - if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ghcr.io @@ -55,6 +62,6 @@ jobs: uses: docker/build-push-action@v5 with: context: ${{ matrix.context }} - push: ${{ github.event_name != 'pull_request' }} + push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}