@@ -40,67 +40,105 @@ jobs:
4040 runs-on : ubuntu-latest
4141 outputs :
4242 version : ${{ steps.get_version.outputs.version }}
43+ base_rc_version : ${{ steps.get_version.outputs.base_rc_version }}
4344 steps :
4445 - uses : actions/checkout@v4
4546 - id : get_version
4647 run : |
4748 if [ -f "oss_version.txt" ]; then
49+ # Read version from oss_version.txt and prevent manual override.
4850 if [[ "${{ github.event.inputs.version }}" != "" ]]; then
4951 echo "Error: The 'version' input field must not be set for repositories using 'oss_version.txt' (like j2cl)."
5052 exit 1
5153 fi
5254 version=$(xargs < oss_version.txt)
5355 echo "Using version from oss_version.txt: ${version}."
5456 echo "version=${version}" >> "$GITHUB_OUTPUT"
57+
58+ if [[ "${{ github.event.inputs.base_rc_version }}" != "" ]]; then
59+ echo "Error: The 'base_rc_version' input field must not be set for repositories using 'oss_version.txt'."
60+ exit 1
61+ fi
62+
63+ # Auto-detect base_rc_version for final semantic releases by finding the last RC tag.
64+ repo_name="${{ github.event.repository.name }}"
65+ RC_REGEX='^([0-9]+\.[0-9]+\.[0-9]+)-RC\.?[0-9]+$'
66+ VERSION_REGEX='^[0-9]+\.[0-9]+\.[0-9]+$'
67+
68+ base_rc_version=""
69+
70+ if [[ "$version" =~ $VERSION_REGEX ]] && [[ ! "$version" =~ $RC_REGEX ]]; then
71+ echo "This is a final release for a semantic versioned project. Finding last RC tag."
72+ tags=$(git ls-remote --tags --refs ${{ github.server_url }}/${{ github.repository }} "${version}-RC*" | awk -F'refs/tags/' '{print $2}')
73+ if [[ -z "$tags" ]]; then
74+ echo "Error: No tags found starting with ${version}-RC"
75+ exit 1
76+ fi
77+ base_rc_version=$(echo "$tags" | sort -V | tail -n 1)
78+ echo "Found last RC tag: $base_rc_version"
79+ fi
80+ echo "base_rc_version=$base_rc_version" >> "$GITHUB_OUTPUT"
5581 else
5682 echo "version=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT"
83+ echo "base_rc_version=${{ github.event.inputs.base_rc_version }}" >> "$GITHUB_OUTPUT"
5784 fi
5885
5986 validate_inputs :
6087 needs : get_version
6188 runs-on : ubuntu-latest
6289 steps :
63- - name : Validate inputs
90+ - name : Validate version
6491 run : |
6592 version="${{ needs.get_version.outputs.version }}"
93+ repo_name="${{ github.event.repository.name }}"
94+
6695 if [[ -z "$version" ]]; then
67- echo "Error: Release version is missing. It must be provided via the 'version' input or 'oss_version.txt' file. "
96+ echo "Error: Release version is missing."
6897 exit 1
6998 fi
7099
71- base_rc_version="${{ github.event.inputs.base_rc_version }}"
72- if [[ -z "$base_rc_version" ]]; then
73- echo "The base RC version field is empty, no validation needed."
74- exit 0
100+ if [[ "$repo_name" == "j2cl" || "$repo_name" == "jsinterop-generator" ]]; then
101+ if [[ ! "$version" =~ ^v[0-9]{8}$ ]]; then
102+ echo "Error: Invalid date-based version format. Expected vYYYYMMDD, but got '${version}'."
103+ exit 1
104+ fi
105+ else
106+ if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-RC[0-9]+)?$ ]]; then
107+ echo "Error: Invalid semantic version format. Expected X.Y.Z or X.Y.Z-RCN, but got '${version}'."
108+ exit 1
109+ fi
75110 fi
76111
112+ - name : Validate base RC version
113+ # TODO(dramaix): remove this step when base_rc_version cannot be passed manually
114+ if : github.event.inputs.base_rc_version != ''
115+ run : |
116+ version="${{ needs.get_version.outputs.version }}"
117+ base_rc_version="${{ needs.get_version.outputs.base_rc_version }}"
77118 repo_name="${{ github.event.repository.name }}"
78- RC_REGEX='^([0-9]+\.[0-9]+\.[0-9]+)-RC\.?[0-9]+$'
79- VERSION_REGEX='^[0-9]+\.[0-9]+\.[0-9]+$'
119+ RC_REGEX='^([0-9]+\.[0-9]+\.[0-9]+)-RC[0-9]+$'
80120
81- # Ensure base_rc_version is not set for repositories that do not use RC versions.
121+ # Ensure base_rc_version is not set for repositories that do not use semantic versionning
82122 if [[ "$repo_name" == "jsinterop-generator" || "$repo_name" == "j2cl" ]]; then
83123 echo "Error: The base RC version field should not be set for repository '${repo_name}'."
84124 exit 1
85125 fi
86126
87127 # Ensure base_rc_version is not set for for RC releases.
88- # RC releases should not be based on another RC version.
89128 if [[ "$version" =~ $RC_REGEX ]]; then
90- echo "Error: If the version '${version}' is an RC version, the base RC version field must be empty."
129+ echo "Error: If the version '${version}' is an RC version, the base RC version must be empty."
91130 exit 1
92131 fi
93132
94133 # Validate base_rc_version format
95134 if [[ ! "$base_rc_version" =~ $RC_REGEX ]]; then
96- echo "Error: Invalid base_rc_version format. Expected X.Y.Z-RC.N , but got '${base_rc_version}'."
135+ echo "Error: Invalid base_rc_version format. Expected X.Y.Z-RCN , but got '${base_rc_version}'."
97136 exit 1
98137 fi
99138
100139 # Extract the base version from base_rc_version using the first captured group from the regex match.
140+ # TODO(dramaix): remove when base_rc_version cannot be passed manually
101141 base_version_from_rc="${BASH_REMATCH[1]}"
102- # Ensure the base version extracted from `base_rc_version` matches the intended release `version`.
103- # This prevents releasing a final version based on an incorrect Release Candidate.
104142 if [[ "$base_version_from_rc" != "$version" ]]; then
105143 echo "Error: The base_rc_version '${base_rc_version}' does not match the version '${version}'."
106144 exit 1
@@ -126,7 +164,7 @@ jobs:
126164 # Pass the inputs from the trigger to the reusable workflow.
127165 with :
128166 version : ${{ needs.get_version.outputs.version }}
129- git_ref : ${{ github.event.inputs .base_rc_version && format('refs/tags/{0}', github.event.inputs .base_rc_version) || github.ref }}
167+ git_ref : ${{ needs.get_version.outputs .base_rc_version && format('refs/tags/{0}', needs.get_version.outputs .base_rc_version) || github.ref }}
130168 publish_to_sonatype : ${{ github.event.repository.name != 'jsinterop-generator' && github.event.repository.name != 'j2cl' }}
131169 publish_to_bcr : ${{ github.event.repository.name != 'jsinterop-annotations' }}
132170
0 commit comments