From 829cd04e519aaac3d2fd772abea1c360e86fe594 Mon Sep 17 00:00:00 2001 From: David Mihalcik Date: Tue, 1 Jul 2025 13:11:09 -0400 Subject: [PATCH] chore(ci): Fixes for version checks upon release - The version information must be up to date and accurate before tagging and publishing releases --- .github/workflows/reusable_deliver.yaml | 10 +------- scripts/check-version-is.sh | 33 +++++++++++++++++++++---- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/.github/workflows/reusable_deliver.yaml b/.github/workflows/reusable_deliver.yaml index af5ee51e..423d5766 100644 --- a/.github/workflows/reusable_deliver.yaml +++ b/.github/workflows/reusable_deliver.yaml @@ -30,16 +30,8 @@ jobs: - name: "Check version number is same between tag, library, and/or release" id: check-version - env: - REF: ${{ github.ref }} run: | - if [[ "$REF" = refs/heads/release/* ]]; then - scripts/check-version-is.sh "${GITHUB_REF##*release/}" - elif [[ "$REF" = refs/tags/sdk/v* ]]; then - scripts/check-version-is.sh "${GITHUB_REF_NAME#sdk/v}" - else - scripts/check-version-is.sh - fi + scripts/check-version-is.sh "${GITHUB_REF}" - name: "Output build metadata" id: guess-build-metadata diff --git a/scripts/check-version-is.sh b/scripts/check-version-is.sh index 8bbcaa28..44a7a5c3 100755 --- a/scripts/check-version-is.sh +++ b/scripts/check-version-is.sh @@ -1,15 +1,38 @@ #!/usr/bin/env bash # Validate that version number is same across all expected files +# If no parameter is found, validates that the lib/package.json is consistent throughout the repo. +# +# Expected usage: +# ./scripts/check-version-is.sh [expected_version, e.g. from branch or tag name] +# Output: +# ::error file=Makefile,line=5::Incorrect version line, should be setting it to [1.0.0] set -euo pipefail -lib_version="$(cd lib && node -p "require('./package.json').version")" - -expected_version="${1:-$lib_version}" +# Parse github.ref context parameter if provided +if [[ ${1:-} =~ refs/heads/release/sdk/v(.*) ]]; then + minor_version="${BASH_REMATCH[1]}" + lib_version="$(cd lib && node -p "require('./package.json').version")" + if [[ $lib_version != $minor_version* ]]; then + echo "::error file=lib/package.json::lib version [$lib_version] does not start with expected minor version [$minor_version]" + exit 1 + fi + expected_version="$lib_version" +elif [[ ${1:-} =~ refs/tags/sdk/v(.*) ]]; then + expected_version="${BASH_REMATCH[1]}" +elif [[ ${1:-} =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then + expected_version="${1}" +else + lib_version="$(cd lib && node -p "require('./package.json').version")" + if [[ -n ${1:-} ]]; then + echo "::error::Unrecognized ref '${1}'; ignored in favor of lib/package.json's version [${lib_version}]" + fi + expected_version="${lib_version}" +fi if ! grep --fixed-strings --line-regexp --quiet "version=${expected_version}" "Makefile"; then if grep --quiet "^version=" "Makefile"; then - echo "::error file=Makefile,line=$(sed -n '/version/=' Makefile)::Incorrect version line, should be setting it to [${expected_version}]" + echo "::error file=Makefile,line=$(sed -n '/^version/=' Makefile)::Incorrect version line, should be setting it to [${expected_version}]" else echo "::error file=Makefile::Makefile missing version line [version=${expected_version}]" fi @@ -18,7 +41,7 @@ fi if ! grep --fixed-strings --line-regexp --quiet "export const version = '${expected_version}'; // x-release-please-version" "lib/src/version.ts"; then if grep --quiet "^export const version" "lib/src/version.ts"; then - echo "::error file=lib/src/version.ts,line=$(sed -n '/export const version/=' lib/src/version.ts)::Incorrect version line, should be setting it to [${expected_version}]" + echo "::error file=lib/src/version.ts,line=$(sed -n '/^export const version/=' lib/src/version.ts)::Incorrect version line, should be setting it to [${expected_version}]" else echo "::error file=lib/src/version.ts::Missing version line [version=${expected_version}]" fi