Enhance version validation in CI workflow to handle first release scenarios
CI and Release / format (pull_request) Successful in 2m21s
CI and Release / analyze (pull_request) Successful in 23s
CI and Release / test (pull_request) Successful in 27s
CI and Release / pana (pull_request) Successful in 1m22s
CI and Release / version-and-changelog (pull_request) Successful in 22s
CI and Release / publish (pull_request) Successful in 20s
CI and Release / format (pull_request) Successful in 2m21s
CI and Release / analyze (pull_request) Successful in 23s
CI and Release / test (pull_request) Successful in 27s
CI and Release / pana (pull_request) Successful in 1m22s
CI and Release / version-and-changelog (pull_request) Successful in 22s
CI and Release / publish (pull_request) Successful in 20s
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
+55
-36
@@ -108,53 +108,68 @@ jobs:
|
||||
git fetch origin "${GITHUB_BASE_REF}" --depth=1
|
||||
|
||||
PR_VERSION="$(sed -nE 's/^version:\s*([^[:space:]]+)\s*$/\1/p' pubspec.yaml | head -n1)"
|
||||
BASE_VERSION="$(git show "origin/${GITHUB_BASE_REF}:pubspec.yaml" | sed -nE 's/^version:\s*([^[:space:]]+)\s*$/\1/p' | head -n1)"
|
||||
BASE_HAS_PUBSPEC="false"
|
||||
BASE_VERSION=""
|
||||
|
||||
if [ -z "$PR_VERSION" ] || [ -z "$BASE_VERSION" ]; then
|
||||
echo "Unable to read versions from pubspec.yaml."
|
||||
if git cat-file -e "origin/${GITHUB_BASE_REF}:pubspec.yaml" 2>/dev/null; then
|
||||
BASE_HAS_PUBSPEC="true"
|
||||
BASE_VERSION="$(git show "origin/${GITHUB_BASE_REF}:pubspec.yaml" | sed -nE 's/^version:\s*([^[:space:]]+)\s*$/\1/p' | head -n1)"
|
||||
fi
|
||||
|
||||
if [ -z "$PR_VERSION" ]; then
|
||||
echo "Unable to read version from PR pubspec.yaml."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
parse_semver_core() {
|
||||
printf '%s' "$1" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/'
|
||||
}
|
||||
if [ "$BASE_HAS_PUBSPEC" = "true" ]; then
|
||||
if [ -z "$BASE_VERSION" ]; then
|
||||
echo "Unable to read version from base branch pubspec.yaml."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASE_CORE="$(parse_semver_core "$BASE_VERSION")"
|
||||
PR_CORE="$(parse_semver_core "$PR_VERSION")"
|
||||
parse_semver_core() {
|
||||
printf '%s' "$1" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/'
|
||||
}
|
||||
|
||||
if ! printf '%s' "$BASE_CORE" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
echo "Base version is not valid semver: $BASE_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
BASE_CORE="$(parse_semver_core "$BASE_VERSION")"
|
||||
PR_CORE="$(parse_semver_core "$PR_VERSION")"
|
||||
|
||||
if ! printf '%s' "$PR_CORE" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
echo "PR version is not valid semver: $PR_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
if ! printf '%s' "$BASE_CORE" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
echo "Base version is not valid semver: $BASE_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASE_MAJOR="${BASE_CORE%%.*}"
|
||||
BASE_REST="${BASE_CORE#*.}"
|
||||
BASE_MINOR="${BASE_REST%%.*}"
|
||||
BASE_PATCH="${BASE_REST#*.}"
|
||||
if ! printf '%s' "$PR_CORE" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
echo "PR version is not valid semver: $PR_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PR_MAJOR="${PR_CORE%%.*}"
|
||||
PR_REST="${PR_CORE#*.}"
|
||||
PR_MINOR="${PR_REST%%.*}"
|
||||
PR_PATCH="${PR_REST#*.}"
|
||||
BASE_MAJOR="${BASE_CORE%%.*}"
|
||||
BASE_REST="${BASE_CORE#*.}"
|
||||
BASE_MINOR="${BASE_REST%%.*}"
|
||||
BASE_PATCH="${BASE_REST#*.}"
|
||||
|
||||
if [ "$PR_MAJOR" -lt "$BASE_MAJOR" ]; then
|
||||
echo "pubspec.yaml version must be greater than base version ($BASE_VERSION -> $PR_VERSION)."
|
||||
exit 1
|
||||
fi
|
||||
PR_MAJOR="${PR_CORE%%.*}"
|
||||
PR_REST="${PR_CORE#*.}"
|
||||
PR_MINOR="${PR_REST%%.*}"
|
||||
PR_PATCH="${PR_REST#*.}"
|
||||
|
||||
if [ "$PR_MAJOR" -eq "$BASE_MAJOR" ] && [ "$PR_MINOR" -lt "$BASE_MINOR" ]; then
|
||||
echo "pubspec.yaml version must be greater than base version ($BASE_VERSION -> $PR_VERSION)."
|
||||
exit 1
|
||||
fi
|
||||
if [ "$PR_MAJOR" -lt "$BASE_MAJOR" ]; then
|
||||
echo "pubspec.yaml version must be greater than base version ($BASE_VERSION -> $PR_VERSION)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$PR_MAJOR" -eq "$BASE_MAJOR" ] && [ "$PR_MINOR" -eq "$BASE_MINOR" ] && [ "$PR_PATCH" -le "$BASE_PATCH" ]; then
|
||||
echo "pubspec.yaml version must be at least 0.0.1 greater than base version ($BASE_VERSION -> $PR_VERSION)."
|
||||
exit 1
|
||||
if [ "$PR_MAJOR" -eq "$BASE_MAJOR" ] && [ "$PR_MINOR" -lt "$BASE_MINOR" ]; then
|
||||
echo "pubspec.yaml version must be greater than base version ($BASE_VERSION -> $PR_VERSION)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$PR_MAJOR" -eq "$BASE_MAJOR" ] && [ "$PR_MINOR" -eq "$BASE_MINOR" ] && [ "$PR_PATCH" -le "$BASE_PATCH" ]; then
|
||||
echo "pubspec.yaml version must be at least 0.0.1 greater than base version ($BASE_VERSION -> $PR_VERSION)."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Base branch has no pubspec.yaml; treating this as first release."
|
||||
fi
|
||||
|
||||
if git diff --quiet "origin/${GITHUB_BASE_REF}...HEAD" -- CHANGELOG.md; then
|
||||
@@ -167,7 +182,11 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Version/changelog gate passed: $BASE_VERSION -> $PR_VERSION"
|
||||
if [ "$BASE_HAS_PUBSPEC" = "true" ]; then
|
||||
echo "Version/changelog gate passed: $BASE_VERSION -> $PR_VERSION"
|
||||
else
|
||||
echo "Version/changelog gate passed for first release: $PR_VERSION"
|
||||
fi
|
||||
|
||||
publish:
|
||||
name: publish
|
||||
|
||||
Reference in New Issue
Block a user