diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..13c1b26 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,22 @@ +name: Java CI with Maven + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + - name: Run tests with Maven + run: mvn clean verify --no-transfer-progress \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..3313304 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,93 @@ +name: Publish to Maven Central + +on: + workflow_run: + workflows: ["Java CI with Maven"] + types: + - completed + branches: [ "main" ] + +jobs: + publish: + runs-on: ubuntu-latest + if: github.repository == 'prefab-cloud/java-simple-sse-client' && github.event.workflow_run.conclusion == 'success' + + steps: + - name: "Checkout" + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + + - name: Extract version from pom.xml + id: extract_version + run: | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Current version: $VERSION" + + - name: Check if version exists in Maven Central + id: version_check + run: | + VERSION=${{ steps.extract_version.outputs.version }} + echo "Checking if version $VERSION exists in Maven Central..." + + # Check if version exists (non-snapshot versions only) + if [[ "$VERSION" != *-SNAPSHOT ]]; then + HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://repo1.maven.org/maven2/cloud/prefab/sse-handler/$VERSION/sse-handler-$VERSION.pom") + if [ "$HTTP_STATUS" = "200" ]; then + echo "Version $VERSION already exists in Maven Central" + echo "should_publish=false" >> $GITHUB_OUTPUT + else + echo "Version $VERSION does not exist in Maven Central" + echo "should_publish=true" >> $GITHUB_OUTPUT + fi + else + echo "Snapshot version detected, skipping publication" + echo "should_publish=false" >> $GITHUB_OUTPUT + fi + + - name: Import GPG key + if: steps.version_check.outputs.should_publish == 'true' + uses: crazy-max/ghaction-import-gpg@v6 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.GPG_PASSPHRASE }} + + - name: Configure Maven settings + if: steps.version_check.outputs.should_publish == 'true' + uses: s4u/maven-settings-action@v3.0.0 + with: + servers: | + [ + { + "id": "central", + "username": "${{ secrets.MAVEN_CENTRAL_USERNAME }}", + "password": "${{ secrets.MAVEN_CENTRAL_TOKEN }}" + } + ] + + - name: Publish to Maven Central + if: steps.version_check.outputs.should_publish == 'true' + env: + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + run: | + echo "Publishing version ${{ steps.extract_version.outputs.version }} to Maven Central..." + mvn clean deploy -P release --no-transfer-progress -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }} + + - name: Create GitHub Release + if: steps.version_check.outputs.should_publish == 'true' + uses: softprops/action-gh-release@v2 + with: + tag_name: v${{ steps.extract_version.outputs.version }} + name: Release v${{ steps.extract_version.outputs.version }} + generate_release_notes: true + prerelease: ${{ contains(steps.extract_version.outputs.version, 'RC') || contains(steps.extract_version.outputs.version, 'beta') || contains(steps.extract_version.outputs.version, 'alpha') }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 53eed4e..94f9c19 100644 --- a/pom.xml +++ b/pom.xml @@ -13,9 +13,13 @@ 1.0.1 jar + Prefab SSE Handler + A simple Server-Sent Events (SSE) client handler for Java applications + true true + true 3.23.1 4.2.0 5.9.1 @@ -114,14 +118,21 @@ + + org.sonatype.central + central-publishing-maven-plugin + 0.8.0 + + central + true + + org.sonatype.plugins nexus-staging-maven-plugin 1.6.13 - sonatype-nexus-staging - https://oss.sonatype.org/ - false + true @@ -146,22 +157,8 @@ - org.apache.maven.plugins - maven-gpg-plugin - 3.0.1 - - - sign-artifacts - - sign - - verify - - - - - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin true @@ -191,14 +188,28 @@ scm:git:git@github.com:prefab-cloud/java-simple-sse-client.git https://github.com/prefab-cloud/java-simple-sse-client - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - + + + + release + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.0.1 + + + sign-artifacts + + sign + + verify + + + + + + +