From 0e29c1fe6474a00baca932d0bd013dfacf60f332 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Tue, 24 Nov 2026 09:05:10 -0400 Subject: [PATCH] ci: create GitHub release after publishing to Maven Central --- .github/workflows/publish-android.yml | 34 +++++++++++++++++++++++++-- scripts/publish-android.sh | 6 +++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-android.yml b/.github/workflows/publish-android.yml index 708fa17..aefa093 100644 --- a/.github/workflows/publish-android.yml +++ b/.github/workflows/publish-android.yml @@ -6,7 +6,7 @@ jobs: publish-android: runs-on: ubuntu-latest permissions: - contents: read + contents: write packages: write steps: - uses: actions/checkout@v4 @@ -31,5 +31,35 @@ jobs: EOF echo "local.properties file has been created successfully." - name: Run publish script + id: publish working-directory: ./scripts - run: ./publish-android.sh \ No newline at end of file + run: ./publish-android.sh + - name: Create GitHub release + # Only when this run actually published a new version, and only from a release branch + if: steps.publish.outputs.published == 'true' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/next') + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ steps.publish.outputs.version }} + run: | + if gh release view "$VERSION" > /dev/null 2>&1; then + echo "Release $VERSION already exists, skipping." + exit 0 + fi + + # Release notes: the matching CHANGELOG.md section, falling back to generated notes + awk -v v="$VERSION" ' + /^## / { if (found) exit; h=$0; sub(/^## \[?v?/, "", h); sub(/\].*$/, "", h); sub(/ .*$/, "", h); if (h == v) { found=1; next } } + found { print } + ' CHANGELOG.md > release-notes.md 2>/dev/null || true + + args=(--target "$GITHUB_SHA" --title "$VERSION") + if [[ -s release-notes.md ]] && grep -q '[^[:space:]]' release-notes.md; then + args+=(--notes-file release-notes.md) + else + args+=(--generate-notes) + fi + if [[ "$VERSION" == *-* ]]; then + args+=(--prerelease) + fi + + gh release create "$VERSION" "${args[@]}" diff --git a/scripts/publish-android.sh b/scripts/publish-android.sh index 74d37d3..df23019 100755 --- a/scripts/publish-android.sh +++ b/scripts/publish-android.sh @@ -29,6 +29,12 @@ else if grep --quiet "BUILD SUCCESSFUL" $LOG_OUTPUT; then printf %"s\n" "Success: Published to MavenCentral." + + # Let the workflow know a new version was published (used to create the GitHub release) + if [[ -n "$GITHUB_OUTPUT" ]]; then + echo "published=true" >> "$GITHUB_OUTPUT" + echo "version=$THE_VERSION" >> "$GITHUB_OUTPUT" + fi else printf %"s\n" "Error publishing, check $LOG_OUTPUT for more info! Manually review and release from the Central Portal may be necessary https://central.sonatype.com/publishing/deployments/" cat $LOG_OUTPUT