Skip to content

Commit 1380074

Browse files
authored
Add workflow to publish packages to GitHub maven repo (#329)
1 parent 164c940 commit 1380074

3 files changed

Lines changed: 117 additions & 30 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Publish package to GitHub Packages
2+
on: workflow_dispatch
3+
jobs:
4+
publish:
5+
runs-on: ubuntu-latest
6+
permissions:
7+
contents: read
8+
packages: write
9+
steps:
10+
- uses: actions/checkout@v5
11+
- uses: actions/setup-java@v4
12+
with:
13+
java-version: '17'
14+
distribution: 'temurin'
15+
- name: Setup Gradle
16+
uses: gradle/actions/setup-gradle@017a9effdb900e5b5b2fddfb590a105619dca3c3 # v4.4.2
17+
18+
- name: Publish package
19+
run: ./gradlew publish
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,45 @@ You can also go to this [Demo Page](http://opensensorhub.github.io/osh-js/latest
2727

2828
This other [Technical Page](http://sensiasoft.net:8181/demo.html) contains example SWE service calls for you to see the standard compliant XML and data that OSH generates.
2929

30+
If using a build system, binaries for osh-core are stored in GitHub Packages. Use the following repository setup to resolve dependencies:
31+
32+
### Gradle
33+
34+
```groovy
35+
//build.gradle
36+
repositories {
37+
maven {
38+
url = uri("https://maven.pkg.github.com/opensensorhub/osh-core")
39+
credentials {
40+
username = System.getenv("GITHUB_ACTOR")
41+
password = System.getenv("GITHUB_TOKEN")
42+
}
43+
}
44+
}
45+
```
46+
### Maven
47+
```xml
48+
<!--pom.xml-->
49+
<repositories>
50+
<repository>
51+
<id>osh-core</id>
52+
<name>osh-core</name>
53+
<url>https://maven.pkg.github.com/opensensorhub/osh-core</url>
54+
</repository>
55+
</repositories>
56+
```
57+
```xml
58+
<!--~/.m2/settings.xml-->
59+
<servers>
60+
<server>
61+
<id>osh-core</id>
62+
<username>${env.GITHUB_ACTOR}</username>
63+
<password>${env.GITHUB_TOKEN}</password>
64+
</server>
65+
</servers>
66+
```
67+
Where environment variables `GITHUB_ACTOR` and `GITHUB_TOKEN` are your GitHub username and PAT respectively.<br>
68+
[Instructions on how to generate PATs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
3069

3170
## Building
3271

common.gradle

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ buildscript {
1414
}
1515
}
1616

17-
18-
allprojects {
17+
18+
allprojects {
1919
group = 'org.sensorhub'
2020

2121
repositories {
22-
maven { url "https://repo.maven.apache.org/maven2" }
22+
mavenCentral()
2323
}
2424

2525
// set build number to HEAD SHA-1
2626
def stdout = new ByteArrayOutputStream()
2727
exec {
28-
commandLine('git','rev-parse','--short','HEAD')
29-
standardOutput = stdout
30-
// hide errors and don't throw exception if not a git repo
31-
errorOutput = new ByteArrayOutputStream()
32-
ignoreExitValue = true
28+
commandLine('git', 'rev-parse', '--short', 'HEAD')
29+
standardOutput = stdout
30+
// hide errors and don't throw exception if not a git repo
31+
errorOutput = new ByteArrayOutputStream()
32+
ignoreExitValue = true
3333
}
3434
ext.buildNumber = "$stdout".trim()
3535

@@ -64,15 +64,15 @@ subprojects {
6464
eclipse {
6565
classpath {
6666
downloadJavadoc = true
67-
file.whenMerged {
67+
file.whenMerged {
6868
entries.each {
6969
if (it.hasProperty('exported'))
7070
it.exported = true
7171
}
7272
}
7373
}
7474
}
75-
75+
7676
// custom dependency configurations for embedding jars in OSGi bundle
7777
configurations {
7878
embeddedApi
@@ -82,13 +82,13 @@ subprojects {
8282
api.extendsFrom(embeddedApi)
8383
implementation.extendsFrom(embeddedImpl)
8484
}
85-
85+
8686
// default test dependencies
8787
dependencies {
8888
testImplementation 'junit:junit:4.13'
8989
testImplementation 'xmlunit:xmlunit:1.6'
9090
}
91-
91+
9292
// print test names
9393
test {
9494
testLogging {
@@ -118,8 +118,8 @@ subprojects {
118118
ext.getPackagesFromJar = { jarFile, packageSet ->
119119
//println jarFile
120120
FileSystems.newFileSystem(jarFile.toPath(), ClassLoader.getSystemClassLoader()).withCloseable { fs ->
121-
def rootDir = fs.getPath('/')
122-
getPackagesFromDir(rootDir, packageSet)
121+
def rootDir = fs.getPath('/')
122+
getPackagesFromDir(rootDir, packageSet)
123123
}
124124
}
125125

@@ -141,24 +141,26 @@ subprojects {
141141
// of the manifest files
142142
if (rootDir.relativize(dir).toString().contains('\\')) {
143143
packageSet.add(rootDir.relativize(dir).toString()
144-
.replace('\\', '.') + '.*')
144+
.replace('\\', '.') + '.*')
145145
} else {
146146
packageSet.add(rootDir.relativize(dir).toString()
147-
.replace('/', '.') + '.*')
147+
.replace('/', '.') + '.*')
148148
}
149149
}
150150
}
151151
}
152152

153153
// help method to automatically find osgi activator class
154154
ext.findActivator = {
155-
for (def classDir: sourceSets.main.output.classesDirs) {
155+
for (def classDir : sourceSets.main.output.classesDirs) {
156156
def rootDir = classDir.toPath()
157157
def activatorClass = Files.walk(rootDir)
158158
.filter { it.toString().endsWith('Activator.class') }
159-
.map { rootDir.relativize(it).toString()
160-
.replace(java.io.File.separatorChar, (char)'.')
161-
.replaceAll('.class$', '') }
159+
.map {
160+
rootDir.relativize(it).toString()
161+
.replace(java.io.File.separatorChar, (char) '.')
162+
.replaceAll('.class$', '')
163+
}
162164
.findAny()
163165
.orElse(null)
164166
if (activatorClass)
@@ -176,10 +178,10 @@ subprojects {
176178

177179
// ignore some common errors
178180
attributes '-fixupmessages': 'Classes found in the wrong directory; is:=ignore,' +
179-
'Unused Import-Package instructions; is:=ignore,' +
180-
'The default package \'.\' is not permitted by the Import-Package syntax; is:=ignore,' +
181-
'Unused Export-Package instructions; is:=ignore,'
182-
181+
'Unused Import-Package instructions; is:=ignore,' +
182+
'The default package \'.\' is not permitted by the Import-Package syntax; is:=ignore,' +
183+
'Unused Export-Package instructions; is:=ignore,'
184+
183185
// disable DS annotation processing
184186
if (!attributes['-dsannotations'])
185187
attributes '-dsannotations': '!*'
@@ -292,9 +294,23 @@ subprojects {
292294

293295
assemble.dependsOn osgi
294296

297+
tasks.register('prePublish') {
298+
if (System.getenv("GITHUB_ACTOR") == null) {
299+
throw new Exception("Environment variable GITHUB_ACTOR not set. Please set to your github username.")
300+
}
301+
302+
if (System.getenv("GITHUB_TOKEN") == null) {
303+
throw new Exception("Environment variable GITHUB_TOKEN not set. Please generate and set to your personal access token: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens")
304+
}
305+
}
306+
307+
tasks.named('publish') { // This is a lifecycle task that runs all publish tasks
308+
dependsOn 'prePublish'
309+
}
310+
295311
// do stuff at the end in case subprojects add extra info
296312
afterEvaluate { project ->
297-
313+
298314
// set defaults for some OSGi manifest entries
299315
project.osgi {
300316
manifest {
@@ -320,9 +336,10 @@ subprojects {
320336
from project.osgi.manifest
321337
}
322338
}
323-
339+
324340
// maven artifact content
325341
project.publishing {
342+
326343
publications {
327344
mavenJava(MavenPublication) {
328345
from components.java
@@ -352,20 +369,30 @@ subprojects {
352369
} >> project.pom)
353370
}
354371
}
355-
}
372+
}
373+
repositories {
374+
maven {
375+
name = "GitHubPackages"
376+
url = "https://maven.pkg.github.com/opensensorhub/osh-core"
377+
credentials {
378+
username = System.getenv("GITHUB_ACTOR")
379+
password = System.getenv("GITHUB_TOKEN")
380+
}
381+
}
382+
}
356383
}
357384
}
358-
385+
359386
// disable jar task if no source is included
360387
if (!new File(project.projectDir, 'src').exists()) {
361-
tasks.osgi.enabled = false
388+
tasks.osgi.enabled = false
362389
tasks.jar.enabled = false
363390
}
364391

365392
// custom task to install in local maven repo
366393
task install
367394
install.dependsOn(build)
368-
install.dependsOn(publishToMavenLocal)
395+
install.dependsOn(publishToMavenLocal)
369396
}
370397

371398

0 commit comments

Comments
 (0)