Skip to content

Commit 2b194b9

Browse files
authored
fix: update workflow and publish to maven central (#65)
1 parent 76504cb commit 2b194b9

File tree

2 files changed

+110
-43
lines changed

2 files changed

+110
-43
lines changed

.github/workflows/maven-build.yml

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,36 @@ jobs:
1313
COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_TOKEN: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_TOKEN }}
1414
COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PASSPHRASE: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PASSPHRASE }}
1515
GITHUB_TOKEN: ${{ github.token }}
16+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
1617
MARKDOWN2HTML_MAVEN_PLUGIN_FAIL_ON_ERROR: true
1718
steps:
18-
- name: Checkout
19+
- name: 📄 Checkout the repository
1920
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
21+
with:
22+
fetch-depth: 0
2023
- name: Set up JDK and Maven
21-
uses: actions/setup-java@2dfa2011c5b2a0f1489bf9e433881c92c1631f88 # v4
24+
uses: actions/setup-java@2dfa2011c5b2a0f1489bf9e433881c92c1631f88 # v4
2225
with:
2326
distribution: adopt
2427
java-version: 17
2528
gpg-private-key: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PRIVATE_KEY }}
26-
- name: Prepare Cache
29+
- name: 📝 Get the project version
30+
id: project_version
31+
run: echo "project_version=$(mvn help:evaluate -Dexpression=project.version
32+
-q -DforceStdout)" >> $GITHUB_OUTPUT
33+
- name: 📝 Store cache key
34+
id: cache_key
35+
run: echo "cache_key=${{ runner.os }}-mvn-${{ hashFiles('**/pom.xml') }}-${{
36+
github.sha }}" >> $GITHUB_OUTPUT
37+
- name: 💾 Prepare cache using cache key
2738
id: prepare-cache
2839
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
2940
with:
3041
path: |
3142
/home/runner/.m2
3243
/home/runner/work
33-
key: ${{ runner.os }}-mvn-${{ hashFiles('**/pom.xml') }}
34-
- name: Generate settings.xml
44+
key: ${{ steps.cache_key.outputs.cache_key }}
45+
- name: 🔘 Generate settings.xml for Maven
3546
uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22
3647
with:
3748
repositories: >
@@ -78,23 +89,15 @@ jobs:
7889
}
7990
}
8091
]
81-
- name: Print settings.xml
92+
- name: 🔘 Print settings.xml
8293
run: cat /home/runner/.m2/settings.xml
83-
- name: Build with Maven
84-
run: mvn --batch-mode clean package
85-
- name: Store project version
86-
id: project_version
87-
run: echo "project_version=$(mvn help:evaluate -Dexpression=project.version
88-
-q -DforceStdout)" >> $GITHUB_OUTPUT
89-
- name: Store cache key
90-
id: cache_key
91-
run: echo "cache_key=${{ runner.os }}-mvn-${{ hashFiles('**/pom.xml') }}"
92-
>> $GITHUB_OUTPUT
94+
- name: 📦 Build with Maven
95+
run: mvn --batch-mode clean package # sonar:sonar
9396
outputs:
9497
project_version: ${{ steps.project_version.outputs.project_version }}
9598
cache_key: ${{ steps.cache_key.outputs.cache_key }}
9699

97-
# deploy to Maven Central
100+
# Deploy release to Maven Central
98101
deploy-maven-central:
99102
needs: build
100103
runs-on: ubuntu-latest
@@ -106,21 +109,21 @@ jobs:
106109
COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_TOKEN: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_TOKEN }}
107110
COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PASSPHRASE: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PASSPHRASE }}
108111
steps:
109-
- name: Set up JDK and Maven
110-
uses: actions/setup-java@2dfa2011c5b2a0f1489bf9e433881c92c1631f88 # v4
112+
- name: 🧱 Set up JDK and Maven
113+
uses: actions/setup-java@2dfa2011c5b2a0f1489bf9e433881c92c1631f88 # v4
111114
with:
112115
distribution: adopt
113116
java-version: 17
114117
gpg-private-key: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PRIVATE_KEY }}
115-
- name: Restore Cache
118+
- name: 💾 Restore cache using cache key
116119
id: restore-cache
117120
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
118121
with:
119122
path: |
120123
/home/runner/.m2
121124
/home/runner/work
122125
key: ${{ needs.build.outputs.cache_key }}
123-
- name: Publish to Maven Central
126+
- name: 📦 Deploy artifacts to Maven Central
124127
run: mvn --batch-mode -Dmaven.test.skip=true deploy -P gpg-sign -P nexus-staging
125128

126129
# deploy to GitHub Packages
@@ -136,23 +139,22 @@ jobs:
136139
S3_SBB_POLARION_MAVEN_REPO_RW_SECRET_ACCESS_KEY: ${{ secrets.S3_SBB_POLARION_MAVEN_REPO_RW_SECRET_ACCESS_KEY }}
137140
GITHUB_TOKEN: ${{ github.token }}
138141
steps:
139-
- name: Set up JDK and Maven
140-
uses: actions/setup-java@2dfa2011c5b2a0f1489bf9e433881c92c1631f88 # v4
142+
- name: 🧱 Set up JDK and Maven
143+
uses: actions/setup-java@2dfa2011c5b2a0f1489bf9e433881c92c1631f88 # v4
141144
with:
142145
distribution: adopt
143146
java-version: 17
144-
- name: Cache
145-
id: cache
147+
- name: 💾 Restore cache using cache key
148+
id: restore-cache
146149
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
147150
with:
148151
path: |
149152
/home/runner/.m2
150153
/home/runner/work
151154
key: ${{ needs.build.outputs.cache_key }}
152-
- name: Publish to GitHub Packages
155+
- name: 📦 Deploy artifacts to GitHub Packages
153156
run: mvn --batch-mode -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dmaven.source.skip=true
154157
deploy -P deploy-github-packages
155-
- name: Upload assets
156-
run: cd ${{github.workspace}} && gh release upload v${{ needs.build.outputs.project_version }}
157-
target/*-${{ needs.build.outputs.project_version }}.jar
158-
shell: bash
158+
- name: 📦 Upload assets to GitHub Release
159+
run: |-
160+
gh release upload v${{ needs.build.outputs.project_version }} target/*-${{ needs.build.outputs.project_version }}.jar

pom.xml

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,44 @@
66
<artifactId>html5diff</artifactId>
77
<version>1.4.3-SNAPSHOT</version>
88

9+
<name>HTML5Diff</name>
10+
<description>Visual comparison of HTML in Java. Fork of DaisyDiff/DaisyDiff</description>
11+
<url>https://github.com/SchweizerischeBundesbahnen/html5diff</url>
12+
913
<licenses>
1014
<license>
1115
<name>Apache License Version 2.0, January 2004</name>
1216
<url>http://www.apache.org/licenses/</url>
1317
</license>
1418
</licenses>
1519

20+
<developers>
21+
<developer>
22+
<name>SBB Polarion Team</name>
23+
<email>[email protected]</email>
24+
<organization>SBB AG</organization>
25+
<organizationUrl>https://www.sbb.ch</organizationUrl>
26+
</developer>
27+
</developers>
28+
29+
<scm>
30+
<connection>scm:git:git://github.com/SchweizerischeBundesbahnen/html5diff.git</connection>
31+
<developerConnection>scm:git:ssh://github.com/SchweizerischeBundesbahnen/html5diff.git</developerConnection>
32+
<url>https://github.com/SchweizerischeBundesbahnen/html5diff/tree/main</url>
33+
</scm>
34+
35+
<issueManagement>
36+
<system>GitHub</system>
37+
<url>https://github.com/SchweizerischeBundesbahnen/html5diff/issues</url>
38+
</issueManagement>
39+
1640
<properties>
1741
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
42+
43+
<maven-gpg-plugin.version>3.2.5</maven-gpg-plugin.version>
44+
45+
<nexus-staging-maven-plugin.version>1.7.0</nexus-staging-maven-plugin.version>
46+
<nexus-staging-maven-plugin.autoReleaseAfterClose>true</nexus-staging-maven-plugin.autoReleaseAfterClose>
1847
</properties>
1948

2049
<dependencyManagement>
@@ -66,20 +95,29 @@
6695
</repository>
6796
</distributionManagement>
6897
</profile>
98+
6999
<profile>
70-
<id>repsyDeploy</id>
71-
<distributionManagement>
72-
<repository>
73-
<id>repsy</id>
74-
<name>repsy.io</name>
75-
<url>https://repo.repsy.io/mvn/sbb/sbb</url>
76-
</repository>
77-
<snapshotRepository>
78-
<id>repsy</id>
79-
<name>repsy.io</name>
80-
<url>https://repo.repsy.io/mvn/sbb/sbb</url>
81-
</snapshotRepository>
82-
</distributionManagement>
100+
<id>gpg-sign</id>
101+
<build>
102+
<plugins>
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-gpg-plugin</artifactId>
106+
</plugin>
107+
</plugins>
108+
</build>
109+
</profile>
110+
111+
<profile>
112+
<id>nexus-staging</id>
113+
<build>
114+
<plugins>
115+
<plugin>
116+
<groupId>org.sonatype.plugins</groupId>
117+
<artifactId>nexus-staging-maven-plugin</artifactId>
118+
</plugin>
119+
</plugins>
120+
</build>
83121
</profile>
84122
</profiles>
85123

@@ -106,6 +144,33 @@
106144
<artifactId>maven-jar-plugin</artifactId>
107145
<version>3.4.2</version>
108146
</plugin>
147+
148+
<plugin>
149+
<groupId>org.apache.maven.plugins</groupId>
150+
<artifactId>maven-gpg-plugin</artifactId>
151+
<version>${maven-gpg-plugin.version}</version>
152+
<executions>
153+
<execution>
154+
<id>sign-artifacts</id>
155+
<phase>verify</phase>
156+
<goals>
157+
<goal>sign</goal>
158+
</goals>
159+
</execution>
160+
</executions>
161+
</plugin>
162+
163+
<plugin>
164+
<groupId>org.sonatype.plugins</groupId>
165+
<artifactId>nexus-staging-maven-plugin</artifactId>
166+
<version>${nexus-staging-maven-plugin.version}</version>
167+
<extensions>true</extensions>
168+
<configuration>
169+
<serverId>ossrh</serverId>
170+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
171+
<autoReleaseAfterClose>${nexus-staging-maven-plugin.autoReleaseAfterClose}</autoReleaseAfterClose>
172+
</configuration>
173+
</plugin>
109174
</plugins>
110175
</pluginManagement>
111176

0 commit comments

Comments
 (0)