Skip to content

Commit

Permalink
add polling to maven central
Browse files Browse the repository at this point in the history
  • Loading branch information
tvichiansakd committed Sep 19, 2024
1 parent 3a4d9f0 commit e7170f1
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
65 changes: 65 additions & 0 deletions .github/tools/check_publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash
SECONDS=0

# Config
INTERVAL=10
TIMEOUT=600

# Validate SONATYPE credentials
if [ -z "$SONATYPE_USERNAME" ] || [ -z "$SONATYPE_PASSWORD" ]; then
echo "SONATYPE_USERNAME and SONATYPE_PASSWORD environment variables must be set"
exit 1
fi
AUTH_TOKEN=$(echo "$SONATYPE_USERNAME:$SONATYPE_PASSWORD" | base64)

# Initialize variables
NAMESPACE=""
BUNDLE_NAME=""
BUNDLE_VERSION=""

# Parse command-line arguments
while [ $# -gt 0 ]; do
case "$1" in
--namespace)
NAMESPACE="$2"
shift 2
;;
--bundle-name)
BUNDLE_NAME="$2"
shift 2
;;
--bundle-version)
BUNDLE_VERSION="$2"
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done

# Validate required arguments
if [ -z "$NAMESPACE" ] || [ -z "$BUNDLE_NAME" ] || [ -z "$BUNDLE_VERSION" ]; then
echo "Usage: $0 --namespace <namespace> --bundle-name <bundle_name> --bundle-version <bundle_version>"
exit 1
fi

URL="https://central.sonatype.com/api/v1/publisher/published?namespace=$NAMESPACE&name=$BUNDLE_NAME&version=$BUNDLE_VERSION"

while [ $SECONDS -lt $TIMEOUT ]; do
RESPONSE=$(curl --header "Authorization: Bearer ${AUTH_TOKEN}" -s $URL)
echo $RESPONSE
if echo "$RESPONSE" | grep -q '"published":true'; then
echo "Successfully Published!"
exit 0
else
echo "Published is not true yet. Checking again in $INTERVAL seconds."
fi
sleep $INTERVAL
done

if [ $SECONDS -ge $TIMEOUT ]; then
echo "Timeout reached. Exiting after $TIMEOUT seconds."
fi
exit 1
10 changes: 9 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Java CI with gradle and JReleaser
name: Java CI

on:
push:
Expand Down Expand Up @@ -92,6 +92,8 @@ jobs:
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.OSSRH_USERNAME }}
JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.OSSRH_TOKEN }}
with:
arguments: full-release | true
- name: JReleaser release output
if: always()
uses: actions/upload-artifact@v4
Expand All @@ -100,3 +102,9 @@ jobs:
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties
- name: Verify Published Artifact
env:
SONATYPE_USERNAME: ${{ secrets.OSSRH_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
working-directory: .github/tools
run: sh check_publish.sh --namespace io.agodadev --bundle-name testmetrics --bundle-version ${{ env.MAJOR_MINOR_VERSION }}${{ github.run_number }}
16 changes: 14 additions & 2 deletions .github/workflows/scalabuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ jobs:
gpg --batch --pinentry-mode=loopback --yes --passphrase $GPG_PASSPHRASE --output $HOME/.sbt/gpg/secring.asc --export-secret-key --armor
sbt +publishSigned
cd $BUNDLE_PATH && zip -r ${GITHUB_WORKSPACE}/bundle.zip .
release:
name: Release
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Publish to Maven Central
env:
SONATYPE_USERNAME: ${{ secrets.OSSRH_USERNAME }}
Expand All @@ -60,7 +66,7 @@ jobs:
exit 1
fi
echo "Found bundle file: $BUNDLE_FILE"
AUTH_TOKEN=$(echo -n "$SONATYPE_USERNAME:$SONATYPE_PASSWORD" | base64)
RESPONSE=$(curl --fail --location "https://central.sonatype.com/api/v1/publisher/upload?publishingType=${PUBLISH_TYPE_PARAMS}" \
--header "Authorization: Basic ${AUTH_TOKEN}" \
Expand All @@ -74,4 +80,10 @@ jobs:
else
echo "Failed to publish to Maven Central. HTTP status code: $RESPONSE"
exit 1
fi
fi
- name: Verify Published Artifacts
env:
SONATYPE_USERNAME: ${{ secrets.OSSRH_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
working-directory: .github/tools
run: sh check_publish.sh --namespace io.agodadev --bundle-name scala-test-metrics --bundle-version ${{ env.MAJOR_MINOR_VERSION }}${{ github.run_number }}

0 comments on commit e7170f1

Please sign in to comment.