8181 echo "📋 Valid version pattern: $VALID_PATTERN"
8282 echo ""
8383
84+ # Function to extract base version (strip RC suffix)
85+ get_base_version() {
86+ echo "$1" | sed 's/-rc\.helm\.[0-9]*$//'
87+ }
88+
89+ # Function to compare semver versions
90+ # Returns: 0 if equal, 1 if first > second, 2 if first < second
91+ compare_versions() {
92+ local v1=$(get_base_version "$1")
93+ local v2=$(get_base_version "$2")
94+ if [[ "$v1" == "$v2" ]]; then
95+ echo 0
96+ elif [[ "$(printf '%s\n' "$v1" "$v2" | sort -V | head -n1)" == "$v2" ]]; then
97+ echo 1 # v1 > v2
98+ else
99+ echo 2 # v1 < v2
100+ fi
101+ }
102+
84103 VALIDATION_FAILED=false
85104 FAILED_CHARTS=""
105+ AHEAD_CHARTS=""
86106
87107 for CHART_FILE in $(find charts -name "Chart.yaml" -type f); do
88108 CHART_DIR=$(dirname "$CHART_FILE")
@@ -95,30 +115,48 @@ jobs:
95115 echo " appVersion: $APP_VERSION"
96116
97117 # Validate chart version
98- if [[ ! "$CHART_VERSION" =~ $VALID_PATTERN ]]; then
99- echo " ❌ ERROR: Chart version '$CHART_VERSION' does not match release pattern"
100- echo " Expected: '$RELEASE_VERSION' or '$RELEASE_VERSION-rc.helm.<number>'"
101- VALIDATION_FAILED=true
102- FAILED_CHARTS="$FAILED_CHARTS $CHART_NAME(version:$CHART_VERSION)"
103- else
118+ if [[ "$CHART_VERSION" =~ $VALID_PATTERN ]]; then
104119 echo " ✅ Chart version is valid"
120+ else
121+ VERSION_CMP=$(compare_versions "$CHART_VERSION" "$RELEASE_VERSION")
122+ if [[ "$VERSION_CMP" == "1" ]]; then
123+ echo " ⚠️ WARNING: Chart version '$CHART_VERSION' is ahead of release '$RELEASE_VERSION'"
124+ echo " This PR may need to be rebased after the next release"
125+ AHEAD_CHARTS="$AHEAD_CHARTS $CHART_NAME(version:$CHART_VERSION)"
126+ else
127+ echo " ❌ ERROR: Chart version '$CHART_VERSION' does not match release pattern"
128+ echo " Expected: '$RELEASE_VERSION' or '$RELEASE_VERSION-rc.helm.<number>'"
129+ VALIDATION_FAILED=true
130+ FAILED_CHARTS="$FAILED_CHARTS $CHART_NAME(version:$CHART_VERSION)"
131+ fi
105132 fi
106133
107134 # Validate appVersion if it exists and is not empty
108135 if [[ -n "$APP_VERSION" && "$APP_VERSION" != "null" ]]; then
109- if [[ ! "$APP_VERSION" =~ $VALID_PATTERN ]]; then
110- echo " ❌ ERROR: appVersion '$APP_VERSION' does not match release pattern"
111- echo " Expected: '$RELEASE_VERSION' or '$RELEASE_VERSION-rc.helm.<number>'"
112- VALIDATION_FAILED=true
113- FAILED_CHARTS="$FAILED_CHARTS $CHART_NAME(appVersion:$APP_VERSION)"
114- else
136+ if [[ "$APP_VERSION" =~ $VALID_PATTERN ]]; then
115137 echo " ✅ appVersion is valid"
138+ else
139+ APP_VERSION_CMP=$(compare_versions "$APP_VERSION" "$RELEASE_VERSION")
140+ if [[ "$APP_VERSION_CMP" == "1" ]]; then
141+ echo " ⚠️ WARNING: appVersion '$APP_VERSION' is ahead of release '$RELEASE_VERSION'"
142+ echo " This PR may need to be rebased after the next release"
143+ AHEAD_CHARTS="$AHEAD_CHARTS $CHART_NAME(appVersion:$APP_VERSION)"
144+ else
145+ echo " ❌ ERROR: appVersion '$APP_VERSION' does not match release pattern"
146+ echo " Expected: '$RELEASE_VERSION' or '$RELEASE_VERSION-rc.helm.<number>'"
147+ VALIDATION_FAILED=true
148+ FAILED_CHARTS="$FAILED_CHARTS $CHART_NAME(appVersion:$APP_VERSION)"
149+ fi
116150 fi
117151 fi
118152
119153 echo ""
120154 done
121155
156+ # Output ahead charts for PR comment
157+ AHEAD_CHARTS=$(echo "$AHEAD_CHARTS" | xargs)
158+ echo "ahead_charts=$AHEAD_CHARTS" >> $GITHUB_OUTPUT
159+
122160 if [[ "$VALIDATION_FAILED" == "true" ]]; then
123161 echo ""
124162 echo "════════════════════════════════════════════════════════════════"
@@ -131,14 +169,67 @@ jobs:
131169 echo "All chart versions and appVersions must match one of:"
132170 echo " - Exact release version: $RELEASE_VERSION"
133171 echo " - RC version pattern: $RELEASE_VERSION-rc.helm.<number>"
172+ echo " - A higher version (if you're working on a future release)"
134173 echo ""
135174 echo "Please update the chart versions to match the latest release."
136175 echo "════════════════════════════════════════════════════════════════"
137176 exit 1
138177 fi
139178
179+ if [[ -n "$AHEAD_CHARTS" ]]; then
180+ echo ""
181+ echo "⚠️ Some charts have versions ahead of the current release."
182+ echo " This is allowed, but you may need to rebase after the next release."
183+ fi
184+
140185 echo "✅ All chart versions are valid against release version $RELEASE_VERSION"
141186
187+ - name : 💬 Comment on PR if charts are ahead
188+ if : github.event_name == 'pull_request' && steps.validate.outputs.ahead_charts != ''
189+ uses : actions/github-script@v7
190+ with :
191+ script : |
192+ const aheadCharts = '${{ steps.validate.outputs.ahead_charts }}'.split(' ').filter(c => c);
193+ const releaseVersion = '${{ steps.release.outputs.release_version }}';
194+
195+ const chartList = aheadCharts.map(c => `- \`${c}\``).join('\n');
196+ const body = `## ⚠️ Chart Version Notice
197+
198+ The following charts have versions **ahead** of the current release (\`${releaseVersion}\`) :
199+
200+ ${chartList}
201+
202+ This is allowed, but **you will need to rebase this PR** after a new release is created to ensure version consistency.
203+
204+ If this is intentional (e.g., you're preparing for an upcoming release), you can ignore this message.`;
205+
206+ // Check if we already commented
207+ const { data : comments } = await github.rest.issues.listComments({
208+ owner : context.repo.owner,
209+ repo : context.repo.repo,
210+ issue_number : context.issue.number
211+ });
212+
213+ const botComment = comments.find(c =>
214+ c.user.type === 'Bot' && c.body.includes('Chart Version Notice')
215+ );
216+
217+ if (botComment) {
218+ await github.rest.issues.updateComment({
219+ owner : context.repo.owner,
220+ repo : context.repo.repo,
221+ comment_id : botComment.id,
222+ body : body
223+ });
224+ } else {
225+ await github.rest.issues.createComment({
226+ owner : context.repo.owner,
227+ repo : context.repo.repo,
228+ issue_number : context.issue.number,
229+ body : body
230+ });
231+ }
232+
142233 - name : 🔍 Detect changed charts
143234 id : detect
144235 run : |
0 commit comments