From ca3d982dc28c8781aa359784924643a5836ea312 Mon Sep 17 00:00:00 2001 From: jekkos Date: Wed, 23 Sep 2026 11:38:31 +0200 Subject: [PATCH] fix(ci): stop stamping app version onto master and branch Docker tags (#4709) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #4695 Master and PR builds were tagging every Docker image with the App.php version (e.g. 3.4.2-master-), flooding Docker Hub with tags for versions that were never released. Docker tags are now scoped to the ref: - master → master, - branch → - - semver tag → , latest Additional hardening: - Release tag trigger restricted to three-component semver (N.N.N) so non-semver tags (e.g. 3.preview) no longer publish a `latest` image - Branch names sanitized: chars outside [a-zA-Z0-9_.-] replaced with _, total tag truncated to stay within Docker's 128-char limit, leading `.` or `-` prevented - Fixed README.md claim that master builds push a `latest` tag --- .github/workflows/README.md | 14 ++++++++------ .github/workflows/build-release.yml | 20 ++++++++++++++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index ff51f5276..e4adb1f83 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -13,8 +13,10 @@ This document describes the CI/CD workflows for OSPOS. ### Docker Images - Build and push `opensourcepos` Docker image for multiple architectures (linux/amd64, linux/arm64) -- On master: tagged with version and `latest` -- On other branches: tagged with version only +- On `master`: tagged `master` and `` +- On other branches: tagged `-` +- On a semver tag (e.g. `3.4.2`): tagged `` and `latest` +- The version number is never stamped onto `master`/branch builds — it only appears on tag releases - Pushed to Docker Hub ### Releases @@ -39,10 +41,10 @@ The `GITHUB_TOKEN` is automatically provided by GitHub Actions. ## Workflow Triggers -- **Push to master** - Runs build, Docker push (with `latest` tag), and release -- **Push to other branches** - Runs build and Docker push (version tag only) -- **Push tags** - Runs build and Docker push (version tag only) -- **Pull requests** - Runs build only (PHPUnit tests run in parallel via phpunit.yml) +- **Push to master** - Runs build, Docker push (`master` + `` tags), and creates/updates the `unstable` release +- **Push to other branches** - Runs build and Docker push (`-` tag) +- **Push a semver tag** (e.g. `3.4.2`) - Runs build and Docker push (`` + `latest` tags) +- **Pull requests** - Runs build only (PHPUnit tests run in parallel via phpunit.yml); no Docker push ## Existing Workflows diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 23774385e..6f8efe6e6 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -2,6 +2,10 @@ name: Build and Release on: push: + branches: + - '**' + tags: + - '[0-9]+.[0-9]+.[0-9]+' pull_request: branches: - master @@ -154,11 +158,19 @@ jobs: - name: Determine Docker tags id: tags run: | - BRANCH=$(echo "${GITHUB_REF#refs/heads/}" | tr '/' '_') - if [ "$BRANCH" = "master" ]; then - echo "tags=${{ secrets.DOCKER_USERNAME }}/opensourcepos:${{ needs.build.outputs.version-tag }},${{ secrets.DOCKER_USERNAME }}/opensourcepos:master" >> $GITHUB_OUTPUT + REGISTRY="${{ secrets.DOCKER_USERNAME }}/opensourcepos" + SHA="${{ needs.build.outputs.short-sha }}" + if [[ "$GITHUB_REF" == refs/tags/* ]]; then + VERSION="${GITHUB_REF#refs/tags/}" + echo "tags=${REGISTRY}:${VERSION},${REGISTRY}:latest" >> "$GITHUB_OUTPUT" + elif [[ "$GITHUB_REF" == refs/heads/master ]]; then + echo "tags=${REGISTRY}:master,${REGISTRY}:${SHA}" >> "$GITHUB_OUTPUT" else - echo "tags=${{ secrets.DOCKER_USERNAME }}/opensourcepos:${{ needs.build.outputs.version-tag }}" >> $GITHUB_OUTPUT + BRANCH="${GITHUB_REF#refs/heads/}" + BRANCH="$(printf '%s' "$BRANCH" | LC_ALL=C tr -c 'A-Za-z0-9_.-' '_')" + BRANCH="${BRANCH:0:$((128 - ${#SHA} - 1))}" + [[ "$BRANCH" == [-.]* ]] && BRANCH="_${BRANCH:1}" + echo "tags=${REGISTRY}:${BRANCH}-${SHA}" >> "$GITHUB_OUTPUT" fi env: GITHUB_REF: ${{ github.ref }}