|
7 | 7 | types: [created]
|
8 | 8 |
|
9 | 9 | jobs:
|
10 |
| - publish: |
| 10 | + build: |
11 | 11 | runs-on: ubuntu-latest
|
12 | 12 |
|
13 | 13 | steps:
|
14 | 14 | - uses: actions/checkout@v3
|
15 |
| - |
16 |
| - - name: Set up JDK 11 |
| 15 | + |
| 16 | + - name: Set up JDK 17 |
17 | 17 | uses: actions/setup-java@v3
|
18 | 18 | with:
|
19 |
| - java-version: '11' |
| 19 | + java-version: '17' |
20 | 20 | distribution: 'temurin'
|
21 |
| - cache: 'maven' |
22 |
| - server-id: ossrh |
23 |
| - server-username: ${{ secrets.OSSRH_USERNAME }} |
24 |
| - server-password: ${{ secrets.OSSRH_TOKEN }} |
25 |
| - gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} |
26 |
| - gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} |
27 |
| - settings-path: ${{ github.workspace }} |
28 |
| - |
29 |
| - - name: Set Version |
30 |
| - id: set_version |
31 |
| - uses: actions/github-script@v4 |
32 |
| - if: github.event_name == 'release' |
33 |
| - with: |
34 |
| - script: | |
35 |
| - const noRef = context.ref.replace('refs/tags/', '') |
36 |
| - const noPrefix = noRef.replace('v', '') |
37 |
| - core.setOutput('version', noPrefix) |
38 |
| -
|
39 |
| - - name: Build with Maven |
40 |
| - run: mvn -B package --file pom.xml |
41 |
| - |
42 |
| - - name: Run tests |
43 |
| - run: mvn -B test --file pom.xml |
44 |
| - |
45 |
| - - name: Check code style |
46 |
| - run: mvn -B checkstyle:check --file pom.xml |
47 |
| - |
48 |
| - - name: Generate Javadoc |
49 |
| - run: mvn -B javadoc:javadoc --file pom.xml |
50 |
| - |
51 |
| - - name: Publish to Maven Central |
52 |
| - run: | |
53 |
| - if [ "${{ github.event_name }}" == "release" ]; then |
54 |
| - mvn --batch-mode versions:set -DnewVersion=${{ steps.set_version.outputs.version }} |
55 |
| - fi |
56 |
| - mvn --batch-mode deploy -P release |
57 |
| - env: |
58 |
| - MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} |
59 |
| - MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} |
60 |
| - MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
| 21 | + cache: maven |
61 | 22 |
|
62 |
| - - name: Wait for Maven Central Sync |
63 |
| - if: github.event_name == 'release' |
| 23 | + - name: Import GPG key |
64 | 24 | run: |
|
65 |
| - echo "Waiting for artifacts to sync to Maven Central..." |
66 |
| - # Wait for up to 30 minutes (180 * 10 seconds) |
67 |
| - for i in {1..180}; do |
68 |
| - STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://repo1.maven.org/maven2/com/notificationapi/notificationapi-java-server-sdk/${{ steps.set_version.outputs.version }}/) |
69 |
| - if [ $STATUS -eq 200 ]; then |
70 |
| - echo "✅ Artifacts found in Maven Central!" |
71 |
| - break |
72 |
| - fi |
73 |
| - echo "Attempt $i: Artifacts not yet available (status: $STATUS). Waiting 10 seconds..." |
74 |
| - sleep 10 |
75 |
| - done |
76 |
| - if [ $STATUS -ne 200 ]; then |
77 |
| - echo "❌ Timeout waiting for artifacts to appear in Maven Central" |
78 |
| - exit 1 |
79 |
| - fi |
| 25 | + # Setup GPG directory |
| 26 | + mkdir -p ~/.gnupg |
| 27 | + chmod 700 ~/.gnupg |
| 28 | + |
| 29 | + # Write key to file |
| 30 | + echo "${{ secrets.GPG_PRIVATE_KEY }}" > ~/private.key |
| 31 | + |
| 32 | + # Import the key |
| 33 | + gpg --batch --import ~/private.key |
| 34 | + |
| 35 | + # Clean up |
| 36 | + rm ~/private.key |
| 37 | + |
| 38 | + # Extract key ID from the imported key |
| 39 | + GPG_KEY_ID=$(gpg --list-secret-keys --keyid-format LONG | grep sec | awk '{print $2}' | cut -d'/' -f2) |
| 40 | + echo "Imported GPG key ID: $GPG_KEY_ID" |
| 41 | + echo "GPG_KEY_ID=$GPG_KEY_ID" >> $GITHUB_ENV |
80 | 42 |
|
81 |
| - - name: Verify Maven Central Artifacts |
82 |
| - if: github.event_name == 'release' |
| 43 | + - name: Build and Publish with Maven |
| 44 | + env: |
| 45 | + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} |
| 46 | + OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} |
| 47 | + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
83 | 48 | run: |
|
84 |
| - VERSION=${{ steps.set_version.outputs.version }} |
85 |
| - BASE_URL="https://repo1.maven.org/maven2/com/notificationapi/notificationapi-java-server-sdk/$VERSION/notificationapi-java-server-sdk-$VERSION" |
| 49 | + # Create settings.xml file |
| 50 | + mkdir -p ~/.m2 |
| 51 | + cat > ~/.m2/settings.xml << EOF |
| 52 | + <?xml version="1.0" encoding="UTF-8"?> |
| 53 | + <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" |
| 54 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 55 | + xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> |
| 56 | + <servers> |
| 57 | + <server> |
| 58 | + <id>central</id> |
| 59 | + <username>\${env.OSSRH_USERNAME}</username> |
| 60 | + <password>\${env.OSSRH_TOKEN}</password> |
| 61 | + </server> |
| 62 | + <server> |
| 63 | + <id>gpg.passphrase</id> |
| 64 | + <passphrase>\${env.GPG_PASSPHRASE}</passphrase> |
| 65 | + </server> |
| 66 | + </servers> |
| 67 | + <profiles> |
| 68 | + <profile> |
| 69 | + <id>gpg</id> |
| 70 | + <properties> |
| 71 | + <gpg.keyname>\${env.GPG_KEY_ID}</gpg.keyname> |
| 72 | + <gpg.passphrase>\${env.GPG_PASSPHRASE}</gpg.passphrase> |
| 73 | + <gpg.executable>gpg</gpg.executable> |
| 74 | + </properties> |
| 75 | + </profile> |
| 76 | + <profile> |
| 77 | + <id>central</id> |
| 78 | + <activation> |
| 79 | + <activeByDefault>true</activeByDefault> |
| 80 | + </activation> |
| 81 | + <properties> |
| 82 | + <central.username>\${env.OSSRH_USERNAME}</central.username> |
| 83 | + <central.password>\${env.OSSRH_TOKEN}</central.password> |
| 84 | + </properties> |
| 85 | + </profile> |
| 86 | + </profiles> |
| 87 | + <activeProfiles> |
| 88 | + <activeProfile>gpg</activeProfile> |
| 89 | + <activeProfile>central</activeProfile> |
| 90 | + </activeProfiles> |
| 91 | + </settings> |
| 92 | + EOF |
86 | 93 |
|
87 |
| - # List of expected files |
88 |
| - FILES=(".jar" ".jar.asc" ".pom" ".pom.asc" "-javadoc.jar" "-javadoc.jar.asc" "-sources.jar" "-sources.jar.asc") |
| 94 | + # Debug GPG configuration |
| 95 | + echo "Using GPG key ID: $GPG_KEY_ID" |
| 96 | + gpg --list-keys $GPG_KEY_ID |
89 | 97 |
|
90 |
| - echo "Verifying all artifacts for version $VERSION..." |
91 |
| - for FILE in "${FILES[@]}"; do |
92 |
| - URL="$BASE_URL$FILE" |
93 |
| - HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" $URL) |
94 |
| - if [ $HTTP_CODE -eq 200 ]; then |
95 |
| - echo "✅ Found $FILE" |
96 |
| - else |
97 |
| - echo "❌ Missing $FILE (HTTP $HTTP_CODE)" |
98 |
| - exit 1 |
99 |
| - fi |
100 |
| - done |
101 |
| - echo "✅ All required artifacts verified in Maven Central!" |
102 |
| -
|
| 98 | + # Set environment variables and run Maven with debug for GPG |
| 99 | + export OSSRH_USERNAME=${{ secrets.OSSRH_USERNAME }} |
| 100 | + export OSSRH_TOKEN="${{ secrets.OSSRH_TOKEN }}" |
| 101 | + export GPG_PASSPHRASE=${{ secrets.GPG_PASSPHRASE }} |
| 102 | + |
| 103 | + mvn clean deploy -Dgpg.keyname=$GPG_KEY_ID -Dgpg.passphrase=$GPG_PASSPHRASE -Dcentral.username=$OSSRH_USERNAME -Dcentral.password=$OSSRH_TOKEN --settings ~/.m2/settings.xml |
0 commit comments