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 }}