From 12c49ed9704fefe87243f9a841ec967831339335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Andreasik?= Date: Wed, 18 Jun 2025 19:29:05 +0200 Subject: [PATCH] ci(snapshot): add snapshot workflow --- .github/workflows/ci.yml | 42 +++- .github/workflows/develop-snapshots.yml | 283 ++++++++++++++++++++++++ examples/example-simple-java/pom.xml | 26 ++- pom.xml | 60 +++-- 4 files changed, 390 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/develop-snapshots.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e80f78..79f6326 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -263,12 +263,9 @@ jobs: exit 1 fi - - name: Check if version exists + - name: Check if version exists in GitHub Packages run: | - VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT - + VERSION=${{ steps.version.outputs.version }} # Check if version already exists in GitHub Packages if gh api /orgs/logdash-io/packages/maven/io.logdash.logdash/versions --jq '.[] | .name' | grep -q "^$VERSION$"; then echo "::warning::Version $VERSION already exists in GitHub Packages" @@ -346,6 +343,21 @@ jobs: exit 1 fi + - name: Check if version exists on Maven Central + run: | + VERSION=${{ steps.version.outputs.version }} + # Check if version exists on Maven Central using search API + SEARCH_RESULT=$(curl -s "https://search.maven.org/solrsearch/select?q=g:io.logdash+AND+a:logdash+AND+v:$VERSION&rows=1&wt=json") + COUNT=$(echo "$SEARCH_RESULT" | jq -r '.response.numFound') + + if [[ "$COUNT" != "0" ]]; then + echo "::error::Version $VERSION already exists on Maven Central" + echo "Cannot redeploy existing version to Maven Central" + exit 1 + else + echo "✅ Version $VERSION is available for Maven Central release" + fi + - name: Build and Deploy to Maven Central run: | mvn clean deploy -B --no-transfer-progress \ @@ -356,12 +368,24 @@ jobs: CENTRAL_TOKEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }} CENTRAL_TOKEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }} GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} + + - name: Verify Maven Central Deployment + run: | + VERSION=${{ steps.version.outputs.version }} + # Check if artifact appears in Central Portal (deployment confirmation) + if curl -s -f "https://central.sonatype.com/api/internal/browse/component?namespace=io.logdash&name=logdash&version=$VERSION" > /dev/null; then + echo "✅ Deployment confirmed via Central Portal API" + else + echo "⚠️ Not yet visible via Central Portal API (may take time to propagate)" + fi - name: Notify Maven Central Success run: | echo "✅ Successfully deployed logdash:${{ steps.version.outputs.version }} to Maven Central" echo "📦 Will be available at: https://central.sonatype.com/artifact/io.logdash/logdash/${{ steps.version.outputs.version }}" echo "🌐 Maven Central: https://search.maven.org/artifact/io.logdash/logdash/${{ steps.version.outputs.version }}" + echo "⏱️ Note: It may take up to 2 hours for the artifact to be searchable via Maven Central" create-github-release: name: Create GitHub Release @@ -469,6 +493,14 @@ jobs: _See below for full release notes and change log._ + - name: Deployment Summary + run: | + echo "📋 Deployment Status Summary:" + echo "✅ GitHub Packages: ${{ needs.github-release.result }}" + echo "✅ Maven Central: ${{ needs.maven-central-release.result }}" + echo "📦 Version: ${{ steps.version.outputs.version }}" + echo "🔗 Maven Central: https://central.sonatype.com/artifact/io.logdash/logdash/${{ steps.version.outputs.version }}" + notification: name: Notification runs-on: ubuntu-latest diff --git a/.github/workflows/develop-snapshots.yml b/.github/workflows/develop-snapshots.yml new file mode 100644 index 0000000..d80fa41 --- /dev/null +++ b/.github/workflows/develop-snapshots.yml @@ -0,0 +1,283 @@ +name: Develop Branch Snapshots + +on: + push: + branches: [ develop ] + schedule: + - cron: '0 2 * * *' + workflow_dispatch: + +env: + JAVA_VERSION: '17' + JAVA_DISTRIBUTION: 'temurin' + +jobs: + validate-develop: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/develop' + timeout-minutes: 15 + outputs: + snapshot-version: ${{ steps.version.outputs.snapshot-version }} + + steps: + - name: Checkout develop + uses: actions/checkout@v4 + with: + ref: develop + fetch-depth: 0 + + - name: Setup JDK ${{ env.JAVA_VERSION }} + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.JAVA_DISTRIBUTION }} + + - name: Cache Maven dependencies + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-develop-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven-develop- + ${{ runner.os }}-maven- + + - name: Verify snapshot version + id: version + run: | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) + if [[ ! $VERSION =~ .*-SNAPSHOT$ ]]; then + echo "❌ Error: Develop branch must have SNAPSHOT version, found: $VERSION" + exit 1 + fi + echo "✅ Snapshot version verified: $VERSION" + echo "snapshot-version=$VERSION" >> $GITHUB_OUTPUT + + - name: Run quick validation + run: | + mvn clean validate compile -B --no-transfer-progress \ + -DskipTests=true \ + -Dspotless.check.skip=true + + maven-central-snapshot: + runs-on: ubuntu-latest + needs: validate-develop + timeout-minutes: 25 + if: github.ref == 'refs/heads/develop' + + steps: + - name: Checkout develop + uses: actions/checkout@v4 + with: + ref: develop + fetch-depth: 0 + + - name: Setup JDK ${{ env.JAVA_VERSION }} + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.JAVA_DISTRIBUTION }} + + - name: Cache Maven dependencies + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-develop-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven-develop- + ${{ runner.os }}-maven- + + - name: Configure Maven Central Snapshots + uses: whelk-io/maven-settings-xml-action@v22 + with: + servers: | + [ + { + "id": "central", + "username": "${{ secrets.CENTRAL_TOKEN_USERNAME }}", + "password": "${{ secrets.CENTRAL_TOKEN_PASSWORD }}" + } + ] + + - name: Display snapshot version + run: | + echo "📦 Deploying snapshot version: ${{ needs.validate-develop.outputs.snapshot-version }}" + + - name: Run comprehensive tests + run: | + mvn clean verify -B --no-transfer-progress \ + -Dmaven.test.failure.ignore=false \ + -Dfailsafe.rerunFailingTestsCount=2 + + - name: Deploy to Maven Central Snapshots + run: | + mvn deploy -B --no-transfer-progress \ + -Pmaven-central-release \ + -DskipTests=true \ + -Dcentral.autoPublish=true + env: + SONATYPE_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }} + + - name: Verify Maven Central snapshot deployment + run: | + VERSION="${{ needs.validate-develop.outputs.snapshot-version }}" + echo "⏳ Waiting for snapshot propagation..." + sleep 10 + + # Check if snapshot metadata is available + METADATA_URL="https://central.sonatype.com/repository/maven-snapshots/io/logdash/logdash/$VERSION/maven-metadata.xml" + if curl -s -f "$METADATA_URL" > /dev/null; then + echo "✅ Snapshot metadata confirmed at Maven Central" + else + echo "⚠️ Snapshot metadata not yet available (may take time to propagate)" + fi + + - name: Display deployment info + run: | + VERSION="${{ needs.validate-develop.outputs.snapshot-version }}" + echo "✅ Successfully deployed $VERSION to Maven Central Snapshots" + echo "📦 Available at: https://central.sonatype.com/repository/maven-snapshots/io/logdash/logdash/$VERSION/" + echo "" + echo "🔍 Maven dependency:" + echo "" + echo " io.logdash" + echo " logdash" + echo " $VERSION" + echo "" + echo "" + echo "🔍 Gradle dependency:" + echo "implementation 'io.logdash:logdash:$VERSION'" + + - name: Notify deployment status + if: failure() + run: | + VERSION="${{ needs.validate-develop.outputs.snapshot-version }}" + echo "❌ Snapshot deployment failed for version $VERSION" + echo "Check logs above for deployment errors" + + github-packages-snapshot: + runs-on: ubuntu-latest + needs: validate-develop + timeout-minutes: 15 + if: github.ref == 'refs/heads/develop' + + permissions: + contents: read + packages: write + + steps: + - name: Checkout develop + uses: actions/checkout@v4 + with: + ref: develop + + - name: Setup JDK ${{ env.JAVA_VERSION }} + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.JAVA_DISTRIBUTION }} + + - name: Cache Maven dependencies + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-develop-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven-develop- + ${{ runner.os }}-maven- + + - name: Configure Maven Settings for GitHub Packages + uses: whelk-io/maven-settings-xml-action@v22 + with: + servers: | + [ + { + "id": "github", + "username": "${env.GITHUB_ACTOR}", + "password": "${env.GITHUB_TOKEN}" + } + ] + + - name: Deploy to GitHub Packages (Backup) + run: | + mvn deploy -B --no-transfer-progress \ + -Pgithub-release \ + -DperformRelease=true \ + -DskipTests=true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Verify GitHub Packages deployment + run: | + VERSION="${{ needs.validate-develop.outputs.snapshot-version }}" + echo "✅ Backup snapshot deployed to GitHub Packages: $VERSION" + echo "📦 Available at: https://github.com/logdash-io/java-sdk/packages" + + verify-deployments: + runs-on: ubuntu-latest + needs: [ maven-central-snapshot, github-packages-snapshot ] + timeout-minutes: 10 + if: github.ref == 'refs/heads/develop' + + steps: + - name: Final verification + run: | + VERSION="${{ needs.validate-develop.outputs.snapshot-version }}" + echo "🔍 Final verification for snapshot: $VERSION" + + # Wait a bit more for propagation + echo "⏳ Waiting for complete propagation..." + sleep 10 + + # Check Maven Central snapshots + METADATA_URL="https://central.sonatype.com/repository/maven-snapshots/io/logdash/logdash/$VERSION/maven-metadata.xml" + if curl -s -f "$METADATA_URL" > /dev/null; then + echo "✅ Maven Central snapshot confirmed and accessible" + else + echo "⚠️ Maven Central snapshot metadata not accessible yet" + fi + + echo "" + echo "📋 Deployment Summary:" + echo "🏗️ Maven Central Snapshots: ${{ needs.maven-central-snapshot.result }}" + echo "📦 GitHub Packages: ${{ needs.github-packages-snapshot.result }}" + echo "🔢 Version: $VERSION" + echo "🌐 Repository: https://central.sonatype.com/repository/maven-snapshots/" + + notification: + runs-on: ubuntu-latest + needs: [ validate-develop, maven-central-snapshot, github-packages-snapshot, verify-deployments ] + if: always() && github.ref == 'refs/heads/develop' + + steps: + - name: Workflow status summary + run: | + VERSION="${{ needs.validate-develop.outputs.snapshot-version }}" + + echo "📊 Develop Branch Snapshot Workflow Summary" + echo "=============================================" + echo "🔢 Version: $VERSION" + echo "📅 Triggered: ${{ github.event_name }}" + echo "" + echo "Job Results:" + echo "✓ Validation: ${{ needs.validate-develop.result }}" + echo "✓ Maven Central: ${{ needs.maven-central-snapshot.result }}" + echo "✓ GitHub Packages: ${{ needs.github-packages-snapshot.result }}" + echo "✓ Verification: ${{ needs.verify-deployments.result }}" + echo "" + + # Check overall success + if [[ "${{ needs.validate-develop.result }}" == "success" && + "${{ needs.maven-central-snapshot.result }}" == "success" && + "${{ needs.github-packages-snapshot.result }}" == "success" ]]; then + echo "🎉 All snapshot deployments completed successfully!" + echo "📦 $VERSION is now available for testing" + else + echo "⚠️ Some deployments may have failed. Check individual job results above." + fi + + echo "" + echo "🔗 Quick Access:" + echo "- Maven Central: https://central.sonatype.com/repository/maven-snapshots/io/logdash/logdash/$VERSION/" + echo "- GitHub Packages: https://github.com/logdash-io/java-sdk/packages" + echo "- Workflow: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ No newline at end of file diff --git a/examples/example-simple-java/pom.xml b/examples/example-simple-java/pom.xml index 73501d8..e3474c8 100644 --- a/examples/example-simple-java/pom.xml +++ b/examples/example-simple-java/pom.xml @@ -16,16 +16,17 @@ UTF-8 21 - 0.2.0-SNAPSHOT 3.12.1 3.1.1 + + 0.2.0-SNAPSHOT io.logdash logdash - ${logdash-sdk.version} + ${logdash.version} @@ -53,4 +54,25 @@ + + + + snapshot-repo + + + logdash.version + *-SNAPSHOT + + + + + + true + + github-snapshots + https://maven.pkg.github.com/logdash-io/java-sdk + + + + diff --git a/pom.xml b/pom.xml index 443ee42..8124c77 100644 --- a/pom.xml +++ b/pom.xml @@ -35,19 +35,6 @@ https://github.com/logdash-io/java-sdk - - - github - GitHub Packages - https://maven.pkg.github.com/logdash-io/java-sdk - - - github - GitHub Packages - https://maven.pkg.github.com/logdash-io/java-sdk - - - 17 ${java.version} @@ -483,6 +470,29 @@ + + local-dev + + true + + + false + false + + + + + org.apache.maven.plugins + maven-deploy-plugin + ${maven-deploy-plugin.version} + + true + + + + + + github-release @@ -492,6 +502,18 @@ true + + + github + GitHub Packages + https://maven.pkg.github.com/logdash-io/java-sdk + + + github + GitHub Packages + https://maven.pkg.github.com/logdash-io/java-sdk + + @@ -501,6 +523,7 @@ ${maven-deploy-plugin.version} true + false @@ -519,7 +542,7 @@ central Central Repository Snapshots - https://central.sonatype.com/api/v1/publisher + https://central.sonatype.com/repository/maven-snapshots/ @@ -563,6 +586,15 @@ + + + org.apache.maven.plugins + maven-deploy-plugin + ${maven-deploy-plugin.version} + + false + +