From 6b1da67f3a1effc532d18941a633535d5c1bb9ab Mon Sep 17 00:00:00 2001 From: Vince Grassia <593223+vgrassia@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:20:40 +0000 Subject: [PATCH] DEVOPS-1840 - Update version bump workflow for automatic version calculation (#8306) --- .github/workflows/version-auto-bump.yml | 35 +--- .github/workflows/version-bump.yml | 265 ++++++++++++++++++------ 2 files changed, 209 insertions(+), 91 deletions(-) diff --git a/.github/workflows/version-auto-bump.yml b/.github/workflows/version-auto-bump.yml index 940a130c29..d0d028e570 100644 --- a/.github/workflows/version-auto-bump.yml +++ b/.github/workflows/version-auto-bump.yml @@ -6,37 +6,11 @@ on: tags: - desktop-v** -defaults: - run: - shell: bash - jobs: bump-version: name: Bump Desktop Version runs-on: ubuntu-22.04 steps: - - name: Checkout Branch - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - - name: Calculate bumped version - id: version - env: - RELEASE_TAG: ${{ github.ref }} - run: | - CURR_MAJOR=$(echo $RELEASE_TAG | sed -r 's/refs\/tags\/[a-z]*-v([0-9]{4}\.[0-9]{1,2})\.([0-9]{1,2})/\1/') - CURR_PATCH=$(echo $RELEASE_TAG | sed -r 's/refs\/tags\/[a-z]*-v([0-9]{4}\.[0-9]{1,2})\.([0-9]{1,2})/\2/') - echo "Current Major: $CURR_MAJOR" - echo "Current Patch: $CURR_PATCH" - - NEW_PATCH=$((CURR_PATCH+1)) - - echo "New patch: $NEW_PATCH" - - NEW_VER=$CURR_MAJOR.$NEW_PATCH - echo "New Version: $NEW_VER" - echo "New Version: $NEW_VER" >> $GITHUB_STEP_SUMMARY - echo "new_version=$NEW_VER" >> $GITHUB_OUTPUT - - name: Login to Azure - CI Subscription uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 with: @@ -49,10 +23,13 @@ jobs: keyvault: bitwarden-ci secrets: "github-pat-bitwarden-devops-bot-repo-scope" - - name: "Bump version to ${{ steps.version.outputs.new_version }}" + - name: Trigger Version Bump workflow env: GH_TOKEN: ${{ steps.retrieve-bot-secrets.outputs.github-pat-bitwarden-devops-bot-repo-scope }} run: | - echo '{"cut_rc_branch": "false", "version_number": "${{ steps.version.outputs.new_version }}", - "bump_browser": "false", "bump_cli": "false", "bump_desktop": "true", "bump_web": "false"}' | \ + echo '{"cut_rc_branch": "false", \ + "bump_browser": "false", \ + "bump_cli": "false", \ + "bump_desktop": "true", \ + "bump_web": "false"}' | \ gh workflow run version-bump.yml --json --repo bitwarden/clients diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 7329667452..5aec22926d 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -1,6 +1,5 @@ --- name: Version Bump -run-name: Version Bump - v${{ inputs.version_number }} on: workflow_dispatch: @@ -21,9 +20,10 @@ on: description: "Bump Web?" type: boolean default: false - version_number: - description: "New version (example: '2024.1.0')" - required: true + version_number_override: + description: "New version override (leave blank for automatic calculation, example: '2024.1.0')" + required: false + type: string cut_rc_branch: description: "Cut RC branch?" default: true @@ -31,22 +31,19 @@ on: jobs: bump_version: - name: "Bump Version to v${{ inputs.version_number }}" + name: Bump Version runs-on: ubuntu-22.04 + outputs: + version_browser: ${{ steps.set-final-version-output.outputs.version_browser }} + version_cli: ${{ steps.set-final-version-output.outputs.version_cli }} + version_desktop: ${{ steps.set-final-version-output.outputs.version_desktop }} + version_web: ${{ steps.set-final-version-output.outputs.version_web }} steps: - - name: Login to Azure - Prod Subscription - uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 + - name: Validate version input + if: ${{ inputs.version_number_override != '' }} + uses: bitwarden/gh-actions/version-check@main with: - creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - - - name: Retrieve secrets - id: retrieve-secrets - uses: bitwarden/gh-actions/get-keyvault-secrets@main - with: - keyvault: "bitwarden-ci" - secrets: "github-gpg-private-key, - github-gpg-private-key-passphrase, - github-pat-bitwarden-devops-bot-repo-scope" + version: ${{ inputs.version_number_override }} - name: Checkout Branch uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 @@ -63,6 +60,20 @@ jobs: exit 1 fi + - name: Login to Azure - CI Subscription + uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 + with: + creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} + + - name: Retrieve secrets + id: retrieve-secrets + uses: bitwarden/gh-actions/get-keyvault-secrets@main + with: + keyvault: "bitwarden-ci" + secrets: "github-gpg-private-key, + github-gpg-private-key-passphrase, + github-pat-bitwarden-devops-bot-repo-scope" + - name: Import GPG key uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0 with: @@ -71,6 +82,11 @@ jobs: git_user_signingkey: true git_commit_gpgsign: true + - name: Setup git + run: | + git config --local user.email "106330231+bitwarden-devops-bot@users.noreply.github.com" + git config --local user.name "bitwarden-devops-bot" + - name: Create Version Branch id: create-branch run: | @@ -90,7 +106,7 @@ jobs: printf -v joined '%s,' "${CLIENTS[@]}" echo "client=${joined%,}" >> $GITHUB_OUTPUT - NAME=version_bump_${{ github.ref_name }}_${{ inputs.version_number }} + NAME=version_bump_${{ github.ref_name }}_$(date +"%Y-%m-%d") git switch -c $NAME echo "name=$NAME" >> $GITHUB_OUTPUT @@ -99,13 +115,20 @@ jobs: ######################## ### Browser - - name: Browser - Verify input version + - name: Get current Browser version if: ${{ inputs.bump_browser == true }} - env: - NEW_VERSION: ${{ inputs.version_number }} + id: current-browser-version run: | CURRENT_VERSION=$(cat package.json | jq -r '.version') + echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + working-directory: apps/browser + - name: Browser - Verify input version + if: ${{ inputs.bump_browser == true && inputs.version_number_override != '' }} + env: + CURRENT_VERSION: ${{ steps.current-browser-version.outputs.version }} + NEW_VERSION: ${{ inputs.version_number_override }} + run: | # Error if version has not changed. if [[ "$NEW_VERSION" == "$CURRENT_VERSION" ]]; then echo "Version has not changed." @@ -122,23 +145,52 @@ jobs: fi working-directory: apps/browser - - name: Bump Browser Version - if: ${{ inputs.bump_browser == true }} - run: npm version --workspace=@bitwarden/browser ${{ inputs.version_number }} + - name: Calculate next Browser release version + if: ${{ inputs.bump_browser == true && inputs.version_number_override == '' }} + id: calculate-next-browser-version + uses: bitwarden/gh-actions/version-next@main + with: + version: ${{ steps.current-browser-version.outputs.version }} - - name: Bump Browser Version - Manifest - if: ${{ inputs.bump_browser == true }} + - name: Bump Browser Version - Version Override + if: ${{ inputs.bump_browser == true && inputs.version_number_override != '' }} + id: bump-browser-version-override + run: npm version --workspace=@bitwarden/browser ${{ inputs.version_number_override }} + + - name: Bump Browser Version - Automatic Calculation + if: ${{ inputs.bump_browser == true && inputs.version_number_override == '' }} + id: bump-browser-version-automatic + env: + VERSION: ${{ steps.calculate-next-browser-version.outputs.version }} + run: npm version --workspace=@bitwarden/browser $VERSION + + - name: Bump Browser Version - Manifest - Version Override + if: ${{ inputs.bump_browser == true && inputs.version_number_override != '' }} uses: bitwarden/gh-actions/version-bump@main with: - version: ${{ inputs.version_number }} file_path: "apps/browser/src/manifest.json" + version: ${{ inputs.version_number_override }} - - name: Bump Browser Version - Manifest v3 - if: ${{ inputs.bump_browser == true }} + - name: Bump Browser Version - Manifest - Automatic Calculation + if: ${{ inputs.bump_browser == true && inputs.version_number_override == '' }} + uses: bitwarden/gh-actions/version-bump@main + with: + file_path: "apps/browser/src/manifest.json" + version: ${{ steps.calculate-next-browser-version.outputs.version }} + + - name: Bump Browser Version - Manifest v3 - Version Override + if: ${{ inputs.bump_browser == true && inputs.version_number_override != '' }} uses: bitwarden/gh-actions/version-bump@main with: - version: ${{ inputs.version_number }} file_path: "apps/browser/src/manifest.v3.json" + version: ${{ inputs.version_number_override }} + + - name: Bump Browser Version - Manifest v3 - Automatic Calculation + if: ${{ inputs.bump_browser == true && inputs.version_number_override == '' }} + uses: bitwarden/gh-actions/version-bump@main + with: + file_path: "apps/browser/src/manifest.v3.json" + version: ${{ steps.calculate-next-browser-version.outputs.version }} - name: Run Prettier after Browser Version Bump if: ${{ inputs.bump_browser == true }} @@ -148,13 +200,20 @@ jobs: prettier --write apps/browser/src/manifest.v3.json ### CLI - - name: CLI - Verify input version + - name: Get current CLI version if: ${{ inputs.bump_cli == true }} - env: - NEW_VERSION: ${{ inputs.version_number }} + id: current-cli-version run: | CURRENT_VERSION=$(cat package.json | jq -r '.version') + echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + working-directory: apps/cli + - name: CLI - Verify input version + if: ${{ inputs.bump_cli == true && inputs.version_number_override != '' }} + env: + CURRENT_VERSION: ${{ steps.current-cli-version.outputs.version }} + NEW_VERSION: ${{ inputs.version_number_override }} + run: | # Error if version has not changed. if [[ "$NEW_VERSION" == "$CURRENT_VERSION" ]]; then echo "Version has not changed." @@ -171,18 +230,40 @@ jobs: fi working-directory: apps/cli - - name: Bump CLI Version - if: ${{ inputs.bump_cli == true }} - run: npm version --workspace=@bitwarden/cli ${{ inputs.version_number }} + - name: Calculate next CLI release version + if: ${{ inputs.bump_cli == true && inputs.version_number_override == '' }} + id: calculate-next-cli-version + uses: bitwarden/gh-actions/version-next@main + with: + version: ${{ steps.current-cli-version.outputs.version }} + + - name: Bump CLI Version - Version Override + if: ${{ inputs.bump_cli == true && inputs.version_number_override != '' }} + id: bump-cli-version-override + run: npm version --workspace=@bitwarden/cli ${{ inputs.version_number_override }} + + - name: Bump CLI Version - Automatic Calculation + if: ${{ inputs.bump_cli == true && inputs.version_number_override == '' }} + id: bump-cli-version-automatic + env: + VERSION: ${{ steps.calculate-next-cli-version.outputs.version }} + run: npm version --workspace=@bitwarden/cli $VERSION ### Desktop - - name: Desktop - Verify input version + - name: Get current Desktop version if: ${{ inputs.bump_desktop == true }} - env: - NEW_VERSION: ${{ inputs.version_number }} + id: current-desktop-version run: | CURRENT_VERSION=$(cat package.json | jq -r '.version') + echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + working-directory: apps/desktop + - name: Desktop - Verify input version + if: ${{ inputs.bump_desktop == true && inputs.version_number_override != '' }} + env: + CURRENT_VERSION: ${{ steps.current-desktop-version.outputs.version }} + NEW_VERSION: ${{ inputs.version_number_override }} + run: | # Error if version has not changed. if [[ "$NEW_VERSION" == "$CURRENT_VERSION" ]]; then echo "Version has not changed." @@ -199,23 +280,52 @@ jobs: fi working-directory: apps/desktop - - name: Bump Desktop Version - Root - if: ${{ inputs.bump_desktop == true }} - run: npm version --workspace=@bitwarden/desktop ${{ inputs.version_number }} + - name: Calculate next Desktop release version + if: ${{ inputs.bump_desktop == true && inputs.version_number_override == '' }} + id: calculate-next-desktop-version + uses: bitwarden/gh-actions/version-next@main + with: + version: ${{ steps.current-desktop-version.outputs.version }} - - name: Bump Desktop Version - App - if: ${{ inputs.bump_desktop == true }} - run: npm version ${{ inputs.version_number }} + - name: Bump Desktop Version - Root - Version Override + if: ${{ inputs.bump_desktop == true && inputs.version_number_override != '' }} + id: bump-desktop-version-override + run: npm version --workspace=@bitwarden/desktop ${{ inputs.version_number_override }} + + - name: Bump Desktop Version - Root - Automatic Calculation + if: ${{ inputs.bump_desktop == true && inputs.version_number_override == '' }} + id: bump-desktop-version-automatic + env: + VERSION: ${{ steps.calculate-next-desktop-version.outputs.version }} + run: npm version --workspace=@bitwarden/desktop $VERSION + + - name: Bump Desktop Version - App - Version Override + if: ${{ inputs.bump_desktop == true && inputs.version_number_override != '' }} + run: npm version ${{ inputs.version_number_override }} + working-directory: "apps/desktop/src" + + - name: Bump Desktop Version - App - Automatic Calculation + if: ${{ inputs.bump_desktop == true && inputs.version_number_override == '' }} + env: + VERSION: ${{ steps.calculate-next-desktop-version.outputs.version }} + run: npm version $VERSION working-directory: "apps/desktop/src" ### Web - - name: Web - Verify input version + - name: Get current Web version if: ${{ inputs.bump_web == true }} - env: - NEW_VERSION: ${{ inputs.version_number }} + id: current-web-version run: | CURRENT_VERSION=$(cat package.json | jq -r '.version') + echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + working-directory: apps/web + - name: Web - Verify input version + if: ${{ inputs.bump_web == true && inputs.version_number_override != '' }} + env: + CURRENT_VERSION: ${{ steps.current-web-version.outputs.version }} + NEW_VERSION: ${{ inputs.version_number_override }} + run: | # Error if version has not changed. if [[ "$NEW_VERSION" == "$CURRENT_VERSION" ]]; then echo "Version has not changed." @@ -232,16 +342,47 @@ jobs: fi working-directory: apps/web - - name: Bump Web Version - if: ${{ inputs.bump_web == true }} - run: npm version --workspace=@bitwarden/web-vault ${{ inputs.version_number }} + - name: Calculate next Web release version + if: ${{ inputs.bump_web == true && inputs.version_number_override == '' }} + id: calculate-next-web-version + uses: bitwarden/gh-actions/version-next@main + with: + version: ${{ steps.current-web-version.outputs.version }} + + - name: Bump Web Version - Version Override + if: ${{ inputs.bump_web == true && inputs.version_number_override != '' }} + id: bump-web-version-override + run: npm version --workspace=@bitwarden/web-vault ${{ inputs.version_number_override }} + + - name: Bump Web Version - Automatic Calculation + if: ${{ inputs.bump_web == true && inputs.version_number_override == '' }} + id: bump-web-version-automatic + env: + VERSION: ${{ steps.calculate-next-web-version.outputs.version }} + run: npm version --workspace=@bitwarden/web-vault $VERSION ######################## - - name: Setup git + - name: Set final version output + id: set-final-version-output run: | - git config --local user.email "106330231+bitwarden-devops-bot@users.noreply.github.com" - git config --local user.name "bitwarden-devops-bot" + if [[ "${{ steps.bump-browser-version-override.outcome }}" = "success" ]]; then + echo "version=${{ inputs.version_number_override }}" >> $GITHUB_OUTPUT + elif [[ "${{ steps.bump-browser-version-automatic.outcome }}" = "success" ]]; then + echo "version=${{ steps.calculate-next-browser-version.outputs.version }}" >> $GITHUB_OUTPUT + elif [[ "${{ steps.bump-cli-version-override.outcome }}" = "success" ]]; then + echo "version=${{ inputs.version_number_override }}" >> $GITHUB_OUTPUT + elif [[ "${{ steps.bump-cli-version-automatic.outcome }}" = "success" ]]; then + echo "version=${{ steps.calculate-next-cli-version.outputs.version }}" >> $GITHUB_OUTPUT + elif [[ "${{ steps.bump-desktop-version-override.outcome }}" = "success" ]]; then + echo "version=${{ inputs.version_number_override }}" >> $GITHUB_OUTPUT + elif [[ "${{ steps.bump-desktop-version-automatic.outcome }}" = "success" ]]; then + echo "version=${{ steps.calculate-next-desktop-version.outputs.version }}" >> $GITHUB_OUTPUT + elif [[ "${{ steps.bump-web-version-override.outcome }}" = "success" ]]; then + echo "version=${{ inputs.version_number_override }}" >> $GITHUB_OUTPUT + elif [[ "${{ steps.bump-web-version-automatic.outcome }}" = "success" ]]; then + echo "version=${{ steps.calculate-next-web-version.outputs.version }}" >> $GITHUB_OUTPUT + fi - name: Check if version changed id: version-changed @@ -257,7 +398,7 @@ jobs: if: ${{ steps.version-changed.outputs.changes_to_commit == 'TRUE' }} env: CLIENT: ${{ steps.create-branch.outputs.client }} - VERSION: ${{ inputs.version_number }} + VERSION: ${{ steps.set-final-version-output.outputs.version }} run: git commit -m "Bumped ${CLIENT} version to ${VERSION}" -a - name: Push changes @@ -272,7 +413,7 @@ jobs: env: GH_TOKEN: ${{ steps.retrieve-secrets.outputs.github-pat-bitwarden-devops-bot-repo-scope }} PR_BRANCH: ${{ steps.create-branch.outputs.name }} - TITLE: "Bump ${{ steps.create-branch.outputs.client }} version to ${{ inputs.version_number }}" + TITLE: "Bump ${{ steps.create-branch.outputs.client }} version to ${{ steps.set-final-version-output.outputs.version }}" run: | PR_URL=$(gh pr create --title "$TITLE" \ --base "main" \ @@ -288,7 +429,7 @@ jobs: - [X] Other ## Objective - Automated ${{ steps.create-branch.outputs.client }} version bump to ${{ inputs.version_number }}") + Automated ${{ steps.create-branch.outputs.client }} version bump to ${{ steps.set-final-version-output.outputs.version }}") echo "pr_number=${PR_URL##*/}" >> $GITHUB_OUTPUT - name: Approve PR @@ -307,8 +448,8 @@ jobs: cut_rc: name: Cut RC branch - needs: bump_version if: ${{ inputs.cut_rc_branch == true }} + needs: bump_version runs-on: ubuntu-22.04 steps: - name: Checkout Branch @@ -320,7 +461,7 @@ jobs: - name: Browser - Verify version has been updated if: ${{ inputs.bump_browser == true }} env: - NEW_VERSION: ${{ inputs.version_number }} + NEW_VERSION: ${{ needs.bump_version.outputs.version_browser }} run: | # Wait for version to change. while : ; do @@ -338,7 +479,7 @@ jobs: - name: CLI - Verify version has been updated if: ${{ inputs.bump_cli == true }} env: - NEW_VERSION: ${{ inputs.version_number }} + NEW_VERSION: ${{ needs.bump_version.outputs.version_cli }} run: | # Wait for version to change. while : ; do @@ -356,7 +497,7 @@ jobs: - name: Desktop - Verify version has been updated if: ${{ inputs.bump_desktop == true }} env: - NEW_VERSION: ${{ inputs.version_number }} + NEW_VERSION: ${{ needs.bump_version.outputs.version_desktop }} run: | # Wait for version to change. while : ; do @@ -374,7 +515,7 @@ jobs: - name: Web - Verify version has been updated if: ${{ inputs.bump_web == true }} env: - NEW_VERSION: ${{ inputs.version_number }} + NEW_VERSION: ${{ needs.bump_version.outputs.version_web }} run: | # Wait for version to change. while : ; do