--- name: Get build number description: GitHub Action to get the build number for a repository outputs: BUILD_NUMBER: description: The build number, newly claimed or reused if this workflow run already claimed one value: ${{ steps.export.outputs.BUILD_NUMBER }} inputs: host-actions-root: description: Path to the actions folder on the host (used when called from another local action) default: '' runs: using: composite steps: - name: Set local action paths id: set-path shell: bash run: | echo "::group::Fix for using local actions" echo "GITHUB_ACTION_PATH=$GITHUB_ACTION_PATH" echo "github.action_path=${{ github.action_path }}" ACTION_PATH_GET_BUILD_NUMBER="${{ github.action_path }}" host_actions_root="${{ inputs.host-actions-root }}" if [[ -z "$host_actions_root" ]]; then host_actions_root="$(dirname "$ACTION_PATH_GET_BUILD_NUMBER")" else ACTION_PATH_GET_BUILD_NUMBER="$host_actions_root/get-build-number" fi echo "ACTION_PATH_GET_BUILD_NUMBER=$ACTION_PATH_GET_BUILD_NUMBER" echo "ACTION_PATH_GET_BUILD_NUMBER=$ACTION_PATH_GET_BUILD_NUMBER" >> "$GITHUB_ENV" echo "BUILD_NUMBER_FILE=.build_number.txt" >> "$GITHUB_ENV" echo "::endgroup::" # Reuse build number from environment if provided (e.g. from a parent workflow) - name: Save build number from environment to file id: from-env if: env.BUILD_NUMBER != '' shell: bash run: | echo "BUILD_NUMBER ${BUILD_NUMBER} provided from environment, skipping increment." echo "${BUILD_NUMBER}" > "$BUILD_NUMBER_FILE" echo "skip=true" >> $GITHUB_OUTPUT # Vault is only needed to read the legacy build_number property during migration to refs/build-number/* (see README); fetched # unconditionally for simplicity, since this whole dependency is temporary and slated for removal once migration is complete. # continue-on-error: a repository with no build_number history (or no {REPO_OWNER_NAME_DASH}-build-number preset configured # yet) has nothing to migrate - a failure here must not block claiming, only fall through to get_build_number.sh's own # no-migration-token warning path (an empty LEGACY_PROPERTY_TOKEN below, same as if this step is skipped entirely). - uses: SonarSource/vault-action-wrapper@a7fa5fd4a4e4e0f2593f6137c0812cac196cf4ce # 3.7.0 id: secrets if: steps.from-env.outputs.skip != 'true' continue-on-error: true with: secrets: development/github/token/{REPO_OWNER_NAME_DASH}-build-number token | github_token; # Reuses this run's own claim if one already exists (a rerun, or another job in the same run); otherwise claims a new one under # an exclusive, repository-wide lock, released as soon as it's no longer needed - see get_build_number.sh. - name: Get build number if: steps.from-env.outputs.skip != 'true' shell: bash env: GITHUB_TOKEN: ${{ github.token }} GH_TOKEN: ${{ github.token }} LEGACY_PROPERTY_TOKEN: ${{ steps.secrets.outputs.vault && fromJSON(steps.secrets.outputs.vault).github_token || '' }} run: ${ACTION_PATH_GET_BUILD_NUMBER}/get_build_number.sh - name: Export build number id: export shell: bash run: | BUILD_NUMBER=$(cat "$BUILD_NUMBER_FILE") if ! [[ "$BUILD_NUMBER" =~ ^[0-9]+$ ]]; then echo "::error title=Invalid build number::Build number '${BUILD_NUMBER}' is not a valid positive integer." >&2 exit 1 fi echo "BUILD_NUMBER: ${BUILD_NUMBER}" echo "BUILD_NUMBER=${BUILD_NUMBER}" >> "$GITHUB_ENV" echo "BUILD_NUMBER=${BUILD_NUMBER}" >> "$GITHUB_OUTPUT" - name: Remove build number file from workspace if: always() shell: bash run: rm -f "$BUILD_NUMBER_FILE"