From 97cb326ea65588745966a96a32f9a8a7dad0dc19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ch=C4=99ci=C5=84ski?= Date: Wed, 16 Apr 2025 15:06:34 +0200 Subject: [PATCH] [BRE-461] Implement new self-host docker unified release process (#366) * Add option to use latest core version in build unified workflow * Add support for publishing on tag triggers in build workflow * Add echo statement to output image tag in build workflow * Fix step ref * Remove echo --- .github/workflows/build-unified.yml | 46 ++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-unified.yml b/.github/workflows/build-unified.yml index 452177c..06b8fd8 100644 --- a/.github/workflows/build-unified.yml +++ b/.github/workflows/build-unified.yml @@ -11,6 +11,10 @@ on: description: "Server branch name to deploy (examples: 'main', 'rc', 'feature/sm')" type: string default: main + use_latest_core_version: + description: "Use the latest core version from versions.json instead of branch" + type: boolean + default: false pull_request: paths: - ".github/workflows/build-unified.yml" @@ -36,23 +40,35 @@ jobs: env: SERVER_BRANCH: ${{ inputs.server_branch }} run: | - if [[ -z "${SERVER_BRANCH}" ]]; then - echo "server_branch=main" >> $GITHUB_OUTPUT + if [[ "${{ inputs.use_latest_core_version }}" == "true" ]]; then + # Extract coreVersion from versions.json + CORE_VERSION=$(jq -r '.versions.coreVersion' versions.json) + echo "Server version from versions.json: $CORE_VERSION" + echo "server_ref=refs/tags/v$CORE_VERSION" >> $GITHUB_OUTPUT + echo "ref_type=tag" >> $GITHUB_OUTPUT + elif [[ -z "${SERVER_BRANCH}" ]]; then + echo "server_ref=main" >> $GITHUB_OUTPUT + echo "ref_type=branch" >> $GITHUB_OUTPUT else - echo "server_branch=${SERVER_BRANCH#refs/heads/}" >> $GITHUB_OUTPUT + echo "server_ref=${SERVER_BRANCH#refs/heads/}" >> $GITHUB_OUTPUT + echo "ref_type=branch" >> $GITHUB_OUTPUT fi - name: Check Branch to Publish env: PUBLISH_BRANCHES: "main,rc,hotfix-rc" - SERVER_BRANCH: ${{ steps.server-branch-name.outputs.server_branch }} + SERVER_BRANCH: ${{ steps.server-branch-name.outputs.server_ref }} + REF_TYPE: ${{ steps.server-branch-name.outputs.ref_type }} id: publish-branch-check run: | REF=${GITHUB_REF#refs/heads/} IFS="," read -a publish_branches <<< $PUBLISH_BRANCHES - if [[ "${publish_branches[*]}" =~ "${REF}" && "${publish_branches[*]}" =~ "${SERVER_BRANCH}" ]]; then + if [[ "${REF_TYPE}" == "tag" ]]; then + # If the build is triggered by a tag, always publish + echo "is_publish_branch=true" >> $GITHUB_ENV + elif [[ "${publish_branches[*]}" =~ "${REF}" && "${publish_branches[*]}" =~ "${SERVER_BRANCH}" ]]; then echo "is_publish_branch=true" >> $GITHUB_ENV else echo "is_publish_branch=false" >> $GITHUB_ENV @@ -85,13 +101,21 @@ jobs: - name: Generate Docker image tag id: tag env: - SERVER_BRANCH: ${{ steps.server-branch-name.outputs.server_branch }} + SERVER_BRANCH: ${{ steps.server-branch-name.outputs.server_ref }} + REF_TYPE: ${{ steps.server-branch-name.outputs.ref_type }} run: | - IMAGE_TAG=$(echo "${SERVER_BRANCH}" | sed "s#/#-#g") # slash safe branch name - if [[ "${IMAGE_TAG}" == "main" ]]; then - IMAGE_TAG=dev - elif [[ ("${IMAGE_TAG}" == "rc") || ("${IMAGE_TAG}" == "hotfix-rc") ]]; then + if [[ "${REF_TYPE}" == "tag" ]]; then + # When using a tag (core version), always use beta tag IMAGE_TAG=beta + echo "Using beta tag for core version release" + else + # For branch-based builds, use the logic + IMAGE_TAG=$(echo "${SERVER_BRANCH}" | sed "s#/#-#g") # slash safe branch name + if [[ "${IMAGE_TAG}" == "main" ]]; then + IMAGE_TAG=dev + elif [[ ("${IMAGE_TAG}" == "rc") || ("${IMAGE_TAG}" == "hotfix-rc") ]]; then + IMAGE_TAG=beta + fi fi echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT @@ -120,7 +144,7 @@ jobs: with: repository: bitwarden/server token: ${{ steps.app-token.outputs.token }} - ref: ${{ steps.server-branch-name.outputs.server_branch }} + ref: ${{ steps.server-branch-name.outputs.server_ref }} path: "server" - name: Build and push Docker image