Skip to content

Commit 6024e81

Browse files
authored
Merge pull request #3 from notificationapi-com/XCJnCBZS/3159-create-a-java-sdk
Update POM file for NotificationAPI Java Server SDK to include project metadata, change license to Apache 2.0, and configure distribution management for Maven Central. Modify README for clarity and update GitHub Actions workflow to publish to Maven Central with GPG signing support.
2 parents 68cd089 + bda2043 commit 6024e81

File tree

12 files changed

+366
-137
lines changed

12 files changed

+366
-137
lines changed

.github/workflows/publish.yml

Lines changed: 85 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,84 +3,101 @@ name: Publish Package
33
on:
44
push:
55
branches: [ main ]
6+
release:
7+
types: [created]
68

79
jobs:
8-
publish:
10+
build:
911
runs-on: ubuntu-latest
1012

1113
steps:
1214
- uses: actions/checkout@v3
13-
14-
- name: Set up JDK 11
15+
16+
- name: Set up JDK 17
1517
uses: actions/setup-java@v3
1618
with:
17-
java-version: '11'
19+
java-version: '17'
1820
distribution: 'temurin'
19-
cache: 'maven'
20-
server-id: github
21-
settings-path: ${{ github.workspace }}
21+
cache: maven
2222

23-
- name: Notify Build Start
24-
uses: 8398a7/action-slack@v3
25-
with:
26-
status: custom
27-
fields: repo,message,commit,workflow
28-
custom_payload: |
29-
{
30-
"text": "🚀 Starting build and publish for notificationapi-java-server-sdk",
31-
"attachments": [{
32-
"color": "good",
33-
"fields": [
34-
{
35-
"title": "Repository",
36-
"value": "{repo}",
37-
"short": true
38-
},
39-
{
40-
"title": "Commit",
41-
"value": "{commit}",
42-
"short": true
43-
}
44-
]
45-
}]
46-
}
47-
env:
48-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
23+
- name: Import GPG key
24+
run: |
25+
# Setup GPG directory
26+
mkdir -p ~/.gnupg
27+
chmod 700 ~/.gnupg
5028
51-
- name: Build with Maven
52-
run: mvn -B package --file pom.xml
53-
54-
- name: Run tests
55-
run: mvn -B test --file pom.xml
56-
57-
- name: Check code style
58-
run: mvn -B checkstyle:check --file pom.xml
59-
60-
- name: Generate Javadoc
61-
run: mvn -B javadoc:javadoc --file pom.xml
62-
63-
- name: Publish to GitHub Packages
64-
run: mvn --batch-mode deploy
65-
env:
66-
GITHUB_TOKEN: ${{ secrets.PACKAGES_TOKEN }}
67-
68-
- name: Notify Success
69-
if: success()
70-
uses: 8398a7/action-slack@v3
71-
with:
72-
status: ${{ job.status }}
73-
fields: repo,message,commit,workflow,took
74-
env:
75-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_SUCCESS_WEBHOOK_URL }}
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
7742
78-
- name: Notify Failure
79-
if: failure()
80-
uses: 8398a7/action-slack@v3
81-
with:
82-
status: ${{ job.status }}
83-
fields: repo,message,commit,workflow,took
43+
- name: Build and Publish with Maven
8444
env:
85-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_FAILED_WEBHOOK_URL }}
45+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
46+
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
47+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
48+
run: |
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
93+
94+
# Debug GPG configuration
95+
echo "Using GPG key ID: $GPG_KEY_ID"
96+
gpg --list-keys $GPG_KEY_ID
97+
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

.github/workflows/pull-request.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ jobs:
2020
java-version: ${{ matrix.java }}
2121
distribution: 'temurin'
2222
cache: 'maven'
23+
server-id: central
24+
server-username: ${{ secrets.OSSRH_USERNAME }}
25+
server-password: ${{ secrets.OSSRH_TOKEN }}
26+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
27+
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}
28+
settings-path: ${{ github.workspace }}
2329

2430
- name: Build with Maven
2531
run: mvn -B package --file pom.xml
@@ -31,4 +37,5 @@ jobs:
3137
run: mvn -B checkstyle:check --file pom.xml
3238

3339
- name: Generate Javadoc
34-
run: mvn -B javadoc:javadoc --file pom.xml
40+
run: mvn -B javadoc:javadoc --file pom.xml
41+

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Maven
2+
target/
3+
pom.xml.tag
4+
pom.xml.releaseBackup
5+
pom.xml.versionsBackup
6+
pom.xml.next
7+
release.properties
8+
dependency-reduced-pom.xml
9+
buildNumber.properties
10+
.mvn/timing.properties
11+
.mvn/wrapper/maven-wrapper.jar
12+
13+
# IDE files
14+
.idea/
15+
*.iml
16+
.vscode/
17+
.project
18+
.classpath
19+
.settings/
20+
21+
# Compiled files
22+
*.class
23+
*.jar
24+
*.war
25+
*.ear
26+
*.zip
27+
*.tar.gz
28+
*.rar
29+
30+
# Logs
31+
*.log
32+
33+
# OS specific
34+
.DS_Store
35+
Thumbs.db

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is the official Java Server SDK for [NotificationAPI](https://www.notificat
44

55
## Installation
66

7-
Add the following dependency to your `pom.xml` file:
7+
Add the following dependency to your project's `pom.xml`:
88

99
```xml
1010
<dependency>
@@ -82,7 +82,3 @@ try (NotificationApi api = new NotificationApi(clientId, clientSecret)) {
8282

8383
- Java 11 or later
8484
- Maven or Gradle build system
85-
86-
## License
87-
88-
This project is licensed under the MIT License - see the LICENSE file for details.

checkstyle.xml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
5+
6+
<module name="Checker">
7+
<property name="charset" value="UTF-8"/>
8+
<property name="severity" value="warning"/>
9+
<property name="fileExtensions" value="java"/>
10+
11+
<!-- Excludes all 'module-info.java' files -->
12+
<module name="BeforeExecutionExclusionFileFilter">
13+
<property name="fileNamePattern" value="module\-info\.java$"/>
14+
</module>
15+
16+
<!-- Checks for whitespace -->
17+
<module name="FileTabCharacter">
18+
<property name="eachLine" value="true"/>
19+
</module>
20+
21+
<module name="LineLength">
22+
<property name="max" value="120"/>
23+
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
24+
</module>
25+
26+
<module name="TreeWalker">
27+
<!-- Import checks -->
28+
<module name="AvoidStarImport"/>
29+
<module name="IllegalImport"/>
30+
<module name="RedundantImport"/>
31+
<module name="UnusedImports"/>
32+
33+
<!-- Checks for Naming Conventions -->
34+
<module name="ConstantName"/>
35+
<module name="LocalFinalVariableName"/>
36+
<module name="LocalVariableName"/>
37+
<module name="MemberName"/>
38+
<module name="MethodName"/>
39+
<module name="PackageName"/>
40+
<module name="ParameterName"/>
41+
<module name="StaticVariableName"/>
42+
<module name="TypeName"/>
43+
44+
<!-- Checks for Size Violations -->
45+
<module name="MethodLength"/>
46+
<module name="ParameterNumber"/>
47+
48+
<!-- Checks for whitespace -->
49+
<module name="EmptyForIteratorPad"/>
50+
<module name="GenericWhitespace"/>
51+
<module name="MethodParamPad"/>
52+
<module name="NoWhitespaceAfter"/>
53+
<module name="NoWhitespaceBefore"/>
54+
<module name="OperatorWrap"/>
55+
<module name="ParenPad"/>
56+
<module name="TypecastParenPad"/>
57+
<module name="WhitespaceAfter"/>
58+
<module name="WhitespaceAround"/>
59+
60+
<!-- Modifier Checks -->
61+
<module name="ModifierOrder"/>
62+
<module name="RedundantModifier"/>
63+
64+
<!-- Checks for blocks -->
65+
<module name="AvoidNestedBlocks"/>
66+
<module name="EmptyBlock"/>
67+
<module name="LeftCurly"/>
68+
<module name="NeedBraces"/>
69+
<module name="RightCurly"/>
70+
71+
<!-- Checks for common coding problems -->
72+
<module name="EmptyStatement"/>
73+
<module name="EqualsHashCode"/>
74+
<module name="IllegalInstantiation"/>
75+
<module name="InnerAssignment"/>
76+
<module name="MissingSwitchDefault"/>
77+
<module name="MultipleVariableDeclarations"/>
78+
<module name="SimplifyBooleanExpression"/>
79+
<module name="SimplifyBooleanReturn"/>
80+
81+
<!-- Checks for class design -->
82+
<module name="FinalClass"/>
83+
<module name="InterfaceIsType"/>
84+
<module name="VisibilityModifier"/>
85+
86+
<!-- Miscellaneous other checks -->
87+
<module name="ArrayTypeStyle"/>
88+
<module name="TodoComment"/>
89+
<module name="UpperEll"/>
90+
</module>
91+
</module>

0 commit comments

Comments
 (0)