Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve #8 by polling to maven central #13

Merged
merged 12 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=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 <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,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
Expand All @@ -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 }}
36 changes: 32 additions & 4 deletions .github/workflows/scalabuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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: |
Expand All @@ -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)

Expand All @@ -74,4 +96,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_2.13 --bundle-version ${{ env.MAJOR_MINOR_VERSION }}${{ github.run_number }}
Loading