Skip to content

Commit 03e4d51

Browse files
committed
fix(workflow): fix prerelease version validation and add manual publish option
- Fix version mismatch for prerelease tags: v3.1.1-beta1 now only requires base version (3.1.1) to match build.gradle versionName, not the full tag - Add publish_release boolean input to workflow_dispatch: allows publishing to GitHub Release page from any branch (useful for test releases) - Replace is_manual flag with is_publish flag for controlling release steps, making intent clearer - workflow_dispatch with publish_release=true now publishes to Release page, enabling non-master branch test releases without spamming master
1 parent a6a9100 commit 03e4d51

1 file changed

Lines changed: 55 additions & 38 deletions

File tree

.github/workflows/release.yml

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ on:
1010
workflow_dispatch:
1111
inputs:
1212
version:
13-
description: 'Version number (e.g., 3.1.1 or 3.1.1-beta1, without leading v) - Manual trigger will NOT publish to Release page'
13+
description: 'Version tag to build (e.g., v3.1.1 or v3.1.1-beta1). Must be an existing tag. Prerelease tags will be published to Release page.'
1414
required: true
1515
type: string
16+
publish_release:
17+
description: 'Publish to GitHub Release page (only effective for non-master branches / test purposes)'
18+
required: false
19+
type: boolean
20+
default: false
1621

1722
concurrency:
1823
group: release-${{ github.ref }}
@@ -69,10 +74,11 @@ jobs:
6974
env:
7075
EVENT_NAME: ${{ github.event_name }}
7176
INPUT_VERSION: ${{ github.event.inputs.version }}
77+
INPUT_PUBLISH: ${{ github.event.inputs.publish_release }}
7278
run: |
7379
# Determine if this is a manual trigger or tag push
7480
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
75-
# Manual trigger - sanitize and normalize input version
81+
# Manual trigger - accept tag name (with or without leading v)
7682
RAW_VERSION="$INPUT_VERSION"
7783
RAW_VERSION="${RAW_VERSION#${RAW_VERSION%%[![:space:]]*}}"
7884
RAW_VERSION="${RAW_VERSION%${RAW_VERSION##*[![:space:]]}}"
@@ -82,24 +88,24 @@ jobs:
8288
exit 1
8389
fi
8490
91+
# Accept either "v3.1.1-beta1" or "3.1.1-beta1"
8592
VERSION="${RAW_VERSION#v}"
86-
if [ "$VERSION" != "$RAW_VERSION" ]; then
87-
echo "⚠️ Input starts with 'v'; auto-stripped to '$VERSION'"
88-
fi
89-
90-
if [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9\.]+)?$ ]]; then
91-
echo "❌ Invalid version input: $RAW_VERSION"
92-
echo "Expected format: {major}.{minor}.{patch}[-prerelease], e.g., 3.1.1 or 3.1.1-beta1"
93-
exit 1
94-
fi
95-
9693
TAG_NAME="v$VERSION"
9794
IS_MANUAL="true"
98-
echo "🔧 Manual trigger detected"
95+
96+
# Determine if we should publish to Release page
97+
if [ "$INPUT_PUBLISH" = "true" ]; then
98+
IS_PUBLISH="true"
99+
echo "📢 Manual trigger with publish enabled"
100+
else
101+
IS_PUBLISH="false"
102+
echo "🔧 Manual trigger detected (artifacts only, no Release page publish)"
103+
fi
99104
else
100105
# Tag push - extract from ref
101106
TAG_NAME="${GITHUB_REF#refs/tags/}"
102107
IS_MANUAL="false"
108+
IS_PUBLISH="true"
103109
fi
104110
105111
# Extract and validate version numbers supporting prerelease tags
@@ -132,26 +138,33 @@ jobs:
132138
echo "version=$VERSION" >> $GITHUB_OUTPUT
133139
echo "base_version=$BASE_VERSION" >> $GITHUB_OUTPUT
134140
echo "is_manual=$IS_MANUAL" >> $GITHUB_OUTPUT
141+
echo "is_publish=$IS_PUBLISH" >> $GITHUB_OUTPUT
135142
echo "is_prerelease=$IS_PRERELEASE" >> $GITHUB_OUTPUT
136-
echo "✅ Valid version: $VERSION (tag: $TAG_NAME, prerelease: $IS_PRERELEASE, manual: $IS_MANUAL)"
143+
echo "✅ Valid version: $VERSION (tag: $TAG_NAME, prerelease: $IS_PRERELEASE, manual: $IS_MANUAL, publish: $IS_PUBLISH)"
137144
138145
- name: Validate version matches project version
139146
run: |
140147
PROJECT_VERSION=$(grep -E 'versionName\s*:' build.gradle | sed -E 's/.*versionName\s*:\s*"([^"]+)".*/\1/')
141148
TAG_VERSION="${{ steps.tag_version.outputs.version }}"
149+
BASE_VERSION="${{ steps.tag_version.outputs.base_version }}"
142150
143-
echo "Project version: $PROJECT_VERSION"
151+
echo "Project version (build.gradle): $PROJECT_VERSION"
144152
echo "Tag full version: $TAG_VERSION"
145-
146-
# Tag version must exactly match versionName in build.gradle
147-
if [ "$PROJECT_VERSION" != "$TAG_VERSION" ]; then
153+
echo "Tag base version: $BASE_VERSION"
154+
155+
# For prerelease tags (e.g., v3.1.1-beta1), only the base version (3.1.1)
156+
# needs to match build.gradle. This allows tagging prereleases without
157+
# updating build.gradle every time.
158+
if [ "$PROJECT_VERSION" = "$TAG_VERSION" ]; then
159+
echo "✅ Exact version match: $TAG_VERSION"
160+
elif [ "$PROJECT_VERSION" = "$BASE_VERSION" ] && [ "$TAG_VERSION" != "$BASE_VERSION" ]; then
161+
echo "✅ Base version match for prerelease: build.gradle=$PROJECT_VERSION, tag=$TAG_VERSION"
162+
else
148163
echo "❌ Version mismatch!"
149-
echo "Tag version ($TAG_VERSION) does not match project version ($PROJECT_VERSION)"
150-
echo "Please update the versionName in build.gradle to match the tag, or use the correct tag."
164+
echo "build.gradle versionName ($PROJECT_VERSION) does not match tag version ($TAG_VERSION) or base version ($BASE_VERSION)"
165+
echo "Please ensure build.gradle versionName matches the tag's base version."
151166
exit 1
152167
fi
153-
154-
echo "✅ Version validation passed: $TAG_VERSION"
155168
156169
- name: Setup local.properties for publishing
157170
run: |
@@ -320,7 +333,7 @@ jobs:
320333
echo "✅ Individual checksum files created"
321334
322335
- name: Sync artifacts to maven repo and open PR
323-
if: steps.tag_version.outputs.is_manual != 'true'
336+
if: steps.tag_version.outputs.is_publish == 'true'
324337
id: sync_maven_repo
325338
env:
326339
ARTIFACT_REPO_TOKEN: ${{ secrets.ARTIFACT_REPO_TOKEN }}
@@ -487,7 +500,7 @@ jobs:
487500
echo "✅ Release notes generated"
488501
489502
- name: Create GitHub Release
490-
if: steps.tag_version.outputs.is_manual != 'true'
503+
if: steps.tag_version.outputs.is_publish == 'true'
491504
uses: softprops/action-gh-release@v2
492505
with:
493506
tag_name: ${{ steps.tag_version.outputs.tag_name }}
@@ -505,49 +518,50 @@ jobs:
505518
env:
506519
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
507520

508-
- name: Upload artifacts (Manual trigger)
509-
if: steps.tag_version.outputs.is_manual == 'true'
521+
- name: Upload artifacts (build-only mode)
522+
if: steps.tag_version.outputs.is_publish != 'true'
510523
uses: actions/upload-artifact@v4
511524
with:
512525
name: release-artifacts-${{ steps.tag_version.outputs.version }}
513526
path: /tmp/release-artifacts/
514527
retention-days: 7
515528

516-
- name: Manual trigger success message
517-
if: steps.tag_version.outputs.is_manual == 'true'
529+
- name: Build-only mode success message
530+
if: steps.tag_version.outputs.is_publish != 'true'
518531
run: |
519532
echo "🎉 ============================================"
520-
echo "🎉 Manual build completed successfully!"
533+
echo "🎉 Build completed successfully (artifacts only)!"
521534
echo "🎉 ============================================"
522535
echo ""
523536
echo "📦 Version: ${{ steps.tag_version.outputs.version }}"
524537
echo "📦 Artifacts are available for download from the workflow run."
525538
echo ""
526-
echo "⚠️ Note: This is a manual trigger build."
539+
echo "⚠️ Note: publish_release was not set to true."
527540
echo "⚠️ Artifacts are NOT published to the Release page."
528-
echo "⚠️ To create an official release, push a tag (e.g., git tag v${{ steps.tag_version.outputs.version }} && git push origin v${{ steps.tag_version.outputs.version }})"
541+
echo "⚠️ To publish, re-run with publish_release=true or push a tag."
529542
echo ""
530543
echo "📦 Built artifacts:"
531544
ls -lh /tmp/release-artifacts/
532545
533546
- name: Summary
534547
run: |
548+
IS_PUBLISH="${{ steps.tag_version.outputs.is_publish }}"
535549
IS_MANUAL="${{ steps.tag_version.outputs.is_manual }}"
536550
VERSION="${{ steps.tag_version.outputs.version }}"
537551
TAG_NAME="${{ steps.tag_version.outputs.tag_name }}"
538552
539-
if [ "$IS_MANUAL" = "true" ]; then
540-
echo "## 🔧 Manual Build Completed Successfully!" >> $GITHUB_STEP_SUMMARY
553+
if [ "$IS_PUBLISH" != "true" ]; then
554+
echo "## 🔧 Build-Only Mode Completed Successfully!" >> $GITHUB_STEP_SUMMARY
541555
echo "" >> $GITHUB_STEP_SUMMARY
542556
echo "**Version**: $VERSION" >> $GITHUB_STEP_SUMMARY
543-
echo "**Trigger**: Manual (workflow_dispatch)" >> $GITHUB_STEP_SUMMARY
557+
echo "**Trigger**: Manual (workflow_dispatch, publish_release=false)" >> $GITHUB_STEP_SUMMARY
544558
echo "" >> $GITHUB_STEP_SUMMARY
545559
echo "### ⚠️ Note" >> $GITHUB_STEP_SUMMARY
546-
echo "This is a **manual trigger build**. Artifacts are **NOT published** to the Release page." >> $GITHUB_STEP_SUMMARY
560+
echo "Artifacts are **NOT published** to the Release page (publish_release was false)." >> $GITHUB_STEP_SUMMARY
547561
echo "" >> $GITHUB_STEP_SUMMARY
548-
echo "To create an official release, push a tag:" >> $GITHUB_STEP_SUMMARY
562+
echo "To publish to Release page, re-run with **publish_release=true**, or push a tag:" >> $GITHUB_STEP_SUMMARY
549563
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
550-
echo "git tag v$VERSION && git push origin v$VERSION" >> $GITHUB_STEP_SUMMARY
564+
echo "git push origin $TAG_NAME" >> $GITHUB_STEP_SUMMARY
551565
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
552566
echo "" >> $GITHUB_STEP_SUMMARY
553567
echo "### 📦 Built Artifacts (available for download):" >> $GITHUB_STEP_SUMMARY
@@ -556,6 +570,9 @@ jobs:
556570
echo "" >> $GITHUB_STEP_SUMMARY
557571
echo "**Release**: $TAG_NAME" >> $GITHUB_STEP_SUMMARY
558572
echo "**Version**: $VERSION" >> $GITHUB_STEP_SUMMARY
573+
if [ "$IS_MANUAL" = "true" ]; then
574+
echo "**Trigger**: Manual (workflow_dispatch, publish_release=true)" >> $GITHUB_STEP_SUMMARY
575+
fi
559576
echo "" >> $GITHUB_STEP_SUMMARY
560577
echo "### ✅ Version Validation" >> $GITHUB_STEP_SUMMARY
561578
echo "- ✅ Tag format validated: v\${major}.\${minor}.\${patch}" >> $GITHUB_STEP_SUMMARY
@@ -574,7 +591,7 @@ jobs:
574591
echo "- gpuimage-plus-$VERSION-16k-min.aar (16KB, image-only)" >> $GITHUB_STEP_SUMMARY
575592
echo "" >> $GITHUB_STEP_SUMMARY
576593
577-
if [ "$IS_MANUAL" != "true" ]; then
594+
if [ "$IS_PUBLISH" = "true" ]; then
578595
echo "Release page: ${{ github.server_url }}/${{ github.repository }}/releases/tag/$TAG_NAME" >> $GITHUB_STEP_SUMMARY
579596
fi
580597

0 commit comments

Comments
 (0)