diff --git a/.github/tools/check_publish.sh b/.github/tools/check_publish.sh new file mode 100644 index 0000000..b08808e --- /dev/null +++ b/.github/tools/check_publish.sh @@ -0,0 +1,65 @@ +#!/bin/bash +SECONDS=0 + +# Config +INTERVAL=30 +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 --bundle-name --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 \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f529d32..01d9374 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Java CI with gradle and JReleaser +name: Java CI on: push: @@ -92,6 +92,7 @@ jobs: JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.OSSRH_USERNAME }} JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.OSSRH_TOKEN }} + continue-on-error: true - name: JReleaser release output if: always() uses: actions/upload-artifact@v4 @@ -100,3 +101,10 @@ jobs: path: | out/jreleaser/trace.log out/jreleaser/output.properties + continue-on-error: true + - 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 }} diff --git a/.github/workflows/scalabuild.yml b/.github/workflows/scalabuild.yml index 751a79a..f26a2b8 100644 --- a/.github/workflows/scalabuild.yml +++ b/.github/workflows/scalabuild.yml @@ -31,6 +31,27 @@ jobs: - name: Build project working-directory: scalatest-listener run: sbt +compile + release: + name: Release + needs: build + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: "11" + distribution: "adopt" + - name: Cache sbt + uses: actions/cache@v2 + with: + path: | + ~/.sbt + ~/.ivy2/cache + ~/.coursier/cache/v1 + ~/.cache/coursier/v1 + key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt') }} - name: Prepare and Sign Artifact env: GPG_PRIVATE_KEY: ${{ secrets.GPG_SECRET_KEY }} @@ -44,13 +65,14 @@ jobs: echo "$GPG_PUBLIC_KEY" | gpg --import --batch mkdir -p $HOME/.sbt/gpg gpg --batch --pinentry-mode=loopback --yes --passphrase $GPG_PASSPHRASE --output $HOME/.sbt/gpg/secring.asc --export-secret-key --armor - sbt +publishSigned + sbt +compile +publishSigned cd $BUNDLE_PATH && zip -r ${GITHUB_WORKSPACE}/bundle.zip . - name: Publish to Maven Central env: SONATYPE_USERNAME: ${{ secrets.OSSRH_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.OSSRH_TOKEN }} PUBLISH_TYPE_PARAMS: AUTOMATIC + BUNDLE_VERSION_NUMBER: ${{ env.MAJOR_MINOR_VERSION }}${{ github.run_number }} BUNDLE_NAME: io.agodadev.scala-test-metrics working-directory: scalatest-listener run: | @@ -60,12 +82,12 @@ 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}" \ --form "bundle=@${BUNDLE_FILE}" \ - --form "name=${BUNDLE_NAME}" \ + --form "name=${BUNDLE_NAME}_${BUNDLE_VERSION_NUMBER}" \ --write-out "%{http_code}" \ --silent --output /dev/null) @@ -74,4 +96,10 @@ jobs: else echo "Failed to publish to Maven Central. HTTP status code: $RESPONSE" exit 1 - fi \ No newline at end of file + 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_2.13 --bundle-version ${{ env.MAJOR_MINOR_VERSION }}${{ github.run_number }}