Skip to content

Commit de3e025

Browse files
authored
Merge pull request #47 from TrueNine/dev
v0.0.34
2 parents 80bc36a + c43d0c7 commit de3e025

File tree

1 file changed

+126
-22
lines changed

1 file changed

+126
-22
lines changed

.github/workflows/maven-central-publish.yaml

Lines changed: 126 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
version: ${{ steps.version-info.outputs.version }}
4343
is-snapshot: ${{ steps.version-info.outputs.is-snapshot }}
4444
should-publish: ${{ steps.version-info.outputs['should-publish'] }}
45+
version-exists-on-central: ${{ steps.version-info.outputs['version-exists-on-central'] }}
4546
java-version: ${{ steps.libs-versions.outputs.java-version }}
4647
gradle-version: ${{ steps.libs-versions.outputs.gradle-version }}
4748

@@ -114,6 +115,36 @@ jobs:
114115
fi
115116
}
116117
118+
check_artifact_exists() {
119+
local group="$1"
120+
local artifact="$2"
121+
local version="$3"
122+
123+
# Method 1: Check via Maven Central REST API
124+
local rest_url="https://repo1.maven.org/maven2/${group//\.//}/${artifact}/${version}/"
125+
echo "Checking REST API: $rest_url" >> $GITHUB_STEP_SUMMARY
126+
127+
if curl -f -s --max-time 10 --head "$rest_url" > /dev/null 2>&1; then
128+
echo "Found via REST API: $artifact-$version exists" >> $GITHUB_STEP_SUMMARY
129+
return 0
130+
fi
131+
132+
# Method 2: Check via Search API
133+
local search_url="https://search.maven.org/solrsearch/select?q=g:\"${group}\"+AND+a:\"${artifact}\"+AND+v:\"${version}\"&rows=1&wt=json"
134+
echo "Checking Search API: $search_url" >> $GITHUB_STEP_SUMMARY
135+
136+
local response=$(curl -f -s --max-time 15 "$search_url" 2>/dev/null || echo '{"response":{"numFound":0}}')
137+
local found=$(echo "$response" | jq -r '.response.numFound' 2>/dev/null || echo "0")
138+
139+
if [[ "$found" -gt 0 ]]; then
140+
echo "Found via Search API: $artifact-$version exists" >> $GITHUB_STEP_SUMMARY
141+
return 0
142+
fi
143+
144+
echo "Not found: $artifact-$version does not exist" >> $GITHUB_STEP_SUMMARY
145+
return 1
146+
}
147+
117148
echo "Determining release version..." >> $GITHUB_STEP_SUMMARY
118149
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
119150
version="${{ github.event.inputs.version }}"
@@ -149,6 +180,7 @@ jobs:
149180
fi
150181
151182
should_publish="false"
183+
version_exists_on_central="false"
152184
force_publish="${{ github.event.inputs.force_publish }}"
153185
154186
echo "" >> $GITHUB_STEP_SUMMARY
@@ -162,24 +194,33 @@ jobs:
162194
echo "Checking if version $version exists on Maven Central..." >> $GITHUB_STEP_SUMMARY
163195
164196
group="io.github.truenine"
165-
search_url="https://search.maven.org/solrsearch/select?q=g:${group}+AND+v:${version}&rows=1&wt=json"
197+
# Check core artifacts to determine if version exists
198+
core_artifacts=("composeserver-shared" "composeserver-cacheable" "composeserver-bom")
166199
167-
echo "Query URL: $search_url" >> $GITHUB_STEP_SUMMARY
200+
version_found_count=0
201+
for artifact in "${core_artifacts[@]}"; do
202+
if check_artifact_exists "$group" "$artifact" "$version"; then
203+
version_found_count=$((version_found_count + 1))
204+
fi
205+
done
168206
169-
response=$(curl -f -s --max-time 15 "$search_url" 2>/dev/null || echo '{"response":{"numFound":0}}')
170-
171-
found=$(echo "$response" | jq -r '.response.numFound' 2>/dev/null || echo "0")
207+
echo "" >> $GITHUB_STEP_SUMMARY
208+
echo "Version check summary: Found $version_found_count out of ${#core_artifacts[@]} core artifacts" >> $GITHUB_STEP_SUMMARY
172209
173-
if [[ "$found" -gt 0 ]]; then
210+
# If any core artifact exists, consider version as published
211+
if [[ "$version_found_count" -gt 0 ]]; then
174212
should_publish="false"
213+
version_exists_on_central="true"
175214
echo "Version already exists - Maven Central already has version $version, skipping publish" >> $GITHUB_STEP_SUMMARY
176215
else
177216
should_publish="true"
217+
version_exists_on_central="false"
178218
echo "Version does not exist - Maven Central does not have version $version, will publish" >> $GITHUB_STEP_SUMMARY
179219
fi
180220
fi
181221
182222
echo "should-publish=$should_publish" >> $GITHUB_OUTPUT
223+
echo "version-exists-on-central=$version_exists_on_central" >> $GITHUB_OUTPUT
183224
184225
echo "" >> $GITHUB_STEP_SUMMARY
185226
echo "### Publishing Decision Result" >> $GITHUB_STEP_SUMMARY
@@ -191,7 +232,12 @@ jobs:
191232
echo "Publishing decision: Continue publish - this version does not exist on Maven Central" >> $GITHUB_STEP_SUMMARY
192233
fi
193234
else
194-
echo "Publishing decision: Skip publish - this version already exists on Maven Central" >> $GITHUB_STEP_SUMMARY
235+
if [[ "$version_exists_on_central" == "true" ]]; then
236+
echo "Publishing decision: Skip publish - this version already exists on Maven Central" >> $GITHUB_STEP_SUMMARY
237+
echo "GitHub Release will still be created for existing Maven Central version" >> $GITHUB_STEP_SUMMARY
238+
else
239+
echo "Publishing decision: Skip publish - unknown reason" >> $GITHUB_STEP_SUMMARY
240+
fi
195241
fi
196242
echo "" >> $GITHUB_STEP_SUMMARY
197243
echo "**Trigger method:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
@@ -203,12 +249,27 @@ jobs:
203249
echo "" >> $GITHUB_STEP_SUMMARY
204250
echo "| Check Item | Status |" >> $GITHUB_STEP_SUMMARY
205251
echo "|------------|--------|" >> $GITHUB_STEP_SUMMARY
206-
echo "| Version format validation | Pass |" >> $GITHUB_STEP_SUMMARY
207-
echo "| Maven Central version check | ${{ steps.version-info.outputs.should-publish == 'true' && 'Not published' || 'Already exists' }} |" >> $GITHUB_STEP_SUMMARY
252+
echo "| Version format validation | ✅ Pass |" >> $GITHUB_STEP_SUMMARY
253+
254+
if [[ "${{ steps.version-info.outputs.version-exists-on-central }}" == "true" ]]; then
255+
echo "| Maven Central version check | 📦 Already exists |" >> $GITHUB_STEP_SUMMARY
256+
elif [[ "${{ steps.version-info.outputs.should-publish }}" == "true" ]]; then
257+
echo "| Maven Central version check | ✅ Not published |" >> $GITHUB_STEP_SUMMARY
258+
else
259+
echo "| Maven Central version check | ❓ Unknown |" >> $GITHUB_STEP_SUMMARY
260+
fi
261+
208262
echo "" >> $GITHUB_STEP_SUMMARY
209263
echo "**Version:** ${{ steps.version-info.outputs.version }}" >> $GITHUB_STEP_SUMMARY
210264
echo "**Type:** ${{ steps.version-info.outputs.is-snapshot == 'true' && 'Snapshot version' || 'Stable version' }}" >> $GITHUB_STEP_SUMMARY
211-
echo "**Publishing status:** ${{ steps.version-info.outputs.should-publish == 'true' && 'Will publish' || 'Skip publish' }}" >> $GITHUB_STEP_SUMMARY
265+
266+
if [[ "${{ steps.version-info.outputs.should-publish }}" == "true" ]]; then
267+
echo "**Publishing status:** 🚀 Will publish to Maven Central" >> $GITHUB_STEP_SUMMARY
268+
elif [[ "${{ steps.version-info.outputs.version-exists-on-central }}" == "true" ]]; then
269+
echo "**Publishing status:** ⏭️ Skip publish (already exists), will create GitHub Release" >> $GITHUB_STEP_SUMMARY
270+
else
271+
echo "**Publishing status:** ⏸️ Skip publish" >> $GITHUB_STEP_SUMMARY
272+
fi
212273
213274
publish:
214275
name: Publish to Maven Central
@@ -383,7 +444,12 @@ jobs:
383444
create-github-release:
384445
name: Create GitHub Release
385446
needs: [ pre-publish-validation, publish ]
386-
if: github.event.inputs.dry_run != 'true' && needs.pre-publish-validation.outputs.is-snapshot == 'false'
447+
if: |
448+
github.event.inputs.dry_run != 'true' &&
449+
needs.pre-publish-validation.outputs.is-snapshot == 'false' &&
450+
(needs.publish.result == 'success' ||
451+
needs.publish.result == 'skipped' ||
452+
needs.pre-publish-validation.outputs.version-exists-on-central == 'true')
387453
runs-on: ubuntu-latest
388454
timeout-minutes: 10
389455
permissions:
@@ -399,6 +465,8 @@ jobs:
399465
id: release-notes
400466
run: |
401467
version="${{ needs.pre-publish-validation.outputs.version }}"
468+
version_exists="${{ needs.pre-publish-validation.outputs.version-exists-on-central }}"
469+
publish_status="${{ needs.publish.result }}"
402470
403471
cat > release_notes.md << 'EOF'
404472
## Release ${{ needs.pre-publish-validation.outputs.version }}
@@ -419,6 +487,20 @@ jobs:
419487
</dependency>
420488
```
421489
490+
### Release Status
491+
492+
EOF
493+
494+
if [[ "$publish_status" == "success" ]]; then
495+
echo "✅ **New Release**: This version was just published to Maven Central." >> release_notes.md
496+
elif [[ "$version_exists" == "true" ]]; then
497+
echo "📦 **Existing Release**: This version already exists on Maven Central. Creating GitHub Release for reference." >> release_notes.md
498+
else
499+
echo "🔄 **Release**: This version is available on Maven Central." >> release_notes.md
500+
fi
501+
502+
cat >> release_notes.md << 'EOF'
503+
422504
### Links
423505
424506
- [Maven Central Search](https://search.maven.org/search?q=g:io.github.truenine%20AND%20v:${{ needs.pre-publish-validation.outputs.version }})
@@ -430,7 +512,7 @@ jobs:
430512
**Full Changelog**: https://github.com/TrueNine/compose-server/compare/v${{ needs.pre-publish-validation.outputs.version }}...HEAD
431513
EOF
432514
433-
echo "Generated release notes for version $version"
515+
echo "Generated release notes for version $version (publish_status: $publish_status, version_exists: $version_exists)"
434516
435517
- name: Create GitHub Release
436518
uses: softprops/action-gh-release@v2
@@ -455,7 +537,11 @@ jobs:
455537
post-publish-verification:
456538
name: Post-publish Verification
457539
needs: [ pre-publish-validation, publish, create-github-release ]
458-
if: github.event.inputs.dry_run != 'true' && always() && needs.publish.result == 'success'
540+
if: |
541+
github.event.inputs.dry_run != 'true' &&
542+
always() &&
543+
(needs.publish.result == 'success' ||
544+
needs.pre-publish-validation.outputs.version-exists-on-central == 'true')
459545
runs-on: ubuntu-latest
460546
timeout-minutes: 15
461547

@@ -467,19 +553,35 @@ jobs:
467553
468554
- name: Generate verification report
469555
run: |
556+
version="${{ needs.pre-publish-validation.outputs.version }}"
557+
publish_result="${{ needs.publish.result }}"
558+
version_exists="${{ needs.pre-publish-validation.outputs.version-exists-on-central }}"
559+
470560
echo "## Publication Verification Report" >> $GITHUB_STEP_SUMMARY
471561
echo "" >> $GITHUB_STEP_SUMMARY
472-
echo "**Version:** ${{ needs.pre-publish-validation.outputs.version }}" >> $GITHUB_STEP_SUMMARY
562+
echo "**Version:** $version" >> $GITHUB_STEP_SUMMARY
473563
echo "" >> $GITHUB_STEP_SUMMARY
474564
echo "### Publication Status" >> $GITHUB_STEP_SUMMARY
475565
echo "" >> $GITHUB_STEP_SUMMARY
476-
echo "- Publication task completed" >> $GITHUB_STEP_SUMMARY
477-
echo "- Maven Central sync may take several hours" >> $GITHUB_STEP_SUMMARY
478-
echo "- Recommend manual verification in 4-6 hours" >> $GITHUB_STEP_SUMMARY
566+
567+
if [[ "$publish_result" == "success" ]]; then
568+
echo "- ✅ Publication task completed successfully" >> $GITHUB_STEP_SUMMARY
569+
echo "- 🔄 Maven Central sync may take several hours" >> $GITHUB_STEP_SUMMARY
570+
echo "- 📝 Recommend manual verification in 4-6 hours" >> $GITHUB_STEP_SUMMARY
571+
elif [[ "$version_exists" == "true" ]]; then
572+
echo "- 📦 Version already exists on Maven Central" >> $GITHUB_STEP_SUMMARY
573+
echo "- ⏭️ Publication was skipped (no need to republish)" >> $GITHUB_STEP_SUMMARY
574+
echo "- 🏷️ GitHub Release created for existing version" >> $GITHUB_STEP_SUMMARY
575+
else
576+
echo "- ⚠️ Publication was skipped" >> $GITHUB_STEP_SUMMARY
577+
echo "- 🔍 Check workflow logs for details" >> $GITHUB_STEP_SUMMARY
578+
fi
579+
479580
echo "" >> $GITHUB_STEP_SUMMARY
480581
echo "### Related Links" >> $GITHUB_STEP_SUMMARY
481582
echo "" >> $GITHUB_STEP_SUMMARY
482-
echo "- [Maven Central Search](https://search.maven.org/search?q=g:io.github.truenine)" >> $GITHUB_STEP_SUMMARY
583+
echo "- [Maven Central Search](https://search.maven.org/search?q=g:io.github.truenine%20AND%20v:$version)" >> $GITHUB_STEP_SUMMARY
584+
echo "- [Maven Central - All Versions](https://search.maven.org/search?q=g:io.github.truenine)" >> $GITHUB_STEP_SUMMARY
483585
echo "- [Sonatype Repository](https://oss.sonatype.org/)" >> $GITHUB_STEP_SUMMARY
484586
485587
if [[ "${{ needs.create-github-release.result }}" == "success" ]]; then
@@ -586,11 +688,13 @@ jobs:
586688
echo "" >> $GITHUB_STEP_SUMMARY
587689
588690
if [[ "${{ needs.publish.result }}" == "success" ]]; then
589-
echo "Publication successful! New version has been successfully published to Maven Central" >> $GITHUB_STEP_SUMMARY
691+
echo "✅ **Publication successful!** New version has been successfully published to Maven Central" >> $GITHUB_STEP_SUMMARY
692+
elif [[ "${{ needs.pre-publish-validation.outputs.version-exists-on-central }}" == "true" ]]; then
693+
echo "📦 **Publication skipped** - this version already exists on Maven Central. GitHub Release created for reference." >> $GITHUB_STEP_SUMMARY
590694
elif [[ "${{ needs.publish.result }}" == "skipped" ]]; then
591-
echo "Publication skipped - this version already exists on Maven Central" >> $GITHUB_STEP_SUMMARY
695+
echo "⏭️ **Publication skipped** - check pre-publish validation for details" >> $GITHUB_STEP_SUMMARY
592696
elif [[ "${{ needs.publish.result }}" == "failure" ]]; then
593-
echo "Publication failed - please check error logs and retry" >> $GITHUB_STEP_SUMMARY
697+
echo "❌ **Publication failed** - please check error logs and retry" >> $GITHUB_STEP_SUMMARY
594698
else
595-
echo "Workflow in progress - please wait for completion" >> $GITHUB_STEP_SUMMARY
699+
echo "🔄 **Workflow in progress** - please wait for completion" >> $GITHUB_STEP_SUMMARY
596700
fi

0 commit comments

Comments
 (0)