name: Version Bump on: workflow_dispatch: inputs: version_number_override: description: "New version override (leave blank for automatic calculation, example: '2024.1.0')" required: false type: string permissions: {} jobs: bump_version: name: Bump Version runs-on: ubuntu-24.04 permissions: contents: write id-token: write steps: - name: Validate version input if: ${{ inputs.version_number_override != '' }} uses: bitwarden/gh-actions/version-check@main with: version: ${{ inputs.version_number_override }} - name: Log in to Azure uses: bitwarden/gh-actions/azure-login@main with: subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} tenant_id: ${{ secrets.AZURE_TENANT_ID }} client_id: ${{ secrets.AZURE_CLIENT_ID }} - name: Get Azure Key Vault secrets id: get-kv-secrets uses: bitwarden/gh-actions/get-keyvault-secrets@main with: keyvault: gh-org-bitwarden secrets: "BW-GHAPP-ID,BW-GHAPP-KEY" - name: Log out from Azure uses: bitwarden/gh-actions/azure-logout@main - name: Generate GH App token uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1 id: app-token with: app-id: ${{ steps.get-kv-secrets.outputs.BW-GHAPP-ID }} private-key: ${{ steps.get-kv-secrets.outputs.BW-GHAPP-KEY }} - name: Checkout Branch uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: token: ${{ steps.app-token.outputs.token }} - name: Setup git run: | git config user.name github-actions git config user.email github-actions@github.com - name: Get current version id: current-version run: | CURRENT_VERSION=$(cat package.json | jq -r '.version') echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT - name: Verify input version if: ${{ inputs.version_number_override != '' }} env: CURRENT_VERSION: ${{ steps.current-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." exit 1 fi # Check if version is newer. printf '%s\n' "${CURRENT_VERSION}" "${NEW_VERSION}" | sort -C -V if [ $? -eq 0 ]; then echo "Version check successful." else echo "Version check failed." exit 1 fi - name: Calculate next release version if: ${{ inputs.version_number_override == '' }} id: calculate-next-version uses: bitwarden/gh-actions/version-next@main with: version: ${{ steps.current-version.outputs.version }} - name: Bump Version - Package - Version Override if: ${{ inputs.version_number_override != '' }} id: bump-version-override uses: bitwarden/gh-actions/version-bump@main with: file_path: "./package.json" version: ${{ inputs.version_number_override }} - name: Bump Version - Package - Automatic Calculation if: ${{ inputs.version_number_override == '' }} id: bump-version-automatic uses: bitwarden/gh-actions/version-bump@main with: file_path: "./package.json" version: ${{ steps.calculate-next-version.outputs.version }} - name: Set final version output id: set-final-version-output run: | if [[ "${{ steps.bump-version-override.outcome }}" == "success" ]]; then echo "version=${{ inputs.version_number_override }}" >> $GITHUB_OUTPUT elif [[ "${{ steps.bump-version-automatic.outcome }}" == "success" ]]; then echo "version=${{ steps.calculate-next-version.outputs.version }}" >> $GITHUB_OUTPUT fi - name: Check if version changed id: version-changed run: | if [ -n "$(git status --porcelain)" ]; then echo "changes_to_commit=TRUE" >> $GITHUB_OUTPUT else echo "changes_to_commit=FALSE" >> $GITHUB_OUTPUT echo "No changes to commit!"; fi - name: Commit files if: ${{ steps.version-changed.outputs.changes_to_commit == 'TRUE' }} run: git commit -m "Bumped version to ${{ steps.set-final-version-output.outputs.version }}" -a - name: Push changes if: ${{ steps.version-changed.outputs.changes_to_commit == 'TRUE' }} run: git push