Skip to content

Commit a61ee45

Browse files
authored
Publish libraries with correct pom files (#90)
* Build validator library with correct POM * Configure the memory footprint for publishing * Modify build actions to build the executable jars. Publish libraries to gh artifactory
1 parent 2aa0482 commit a61ee45

File tree

5 files changed

+146
-116
lines changed

5 files changed

+146
-116
lines changed

.github/workflows/gradle-publish-base.yml

Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ jobs:
4343
uses: gradle/actions/setup-gradle@v3
4444
with:
4545
build-root-directory: play-validations
46-
arguments: memory-footprint:jar -Dmemory-footprint.git_hash=${{ env.git_hash }}
46+
arguments: memory-footprint:build -Dmemory-footprint.git_hash=${{ env.git_hash }}
4747
- name: Build wff-validator
4848
uses: gradle/actions/setup-gradle@v3
4949
with:
50-
build-root-directory: third_party/wff
51-
arguments: :specification:validator:build
50+
build-root-directory: play-validations
51+
arguments: validator:build
5252
- name: Copy LICENSE files
5353
run: |
5454
mv LICENSE.txt memory-footprint_LICENSE.txt
@@ -70,82 +70,3 @@ jobs:
7070
**/memory-footprint.jar
7171
**/wff-validator.jar
7272
**/wff-xsd.zip
73-
74-
publish_packages:
75-
runs-on: ubuntu-latest
76-
needs: build_memory_footprint
77-
env:
78-
GH_TOKEN: ${{ github.token }}
79-
strategy:
80-
matrix:
81-
jar_file: [wff-validator.jar, memory-footprint.jar]
82-
steps:
83-
- name: Install GitHub CLI
84-
run: |
85-
sudo apt-get update
86-
sudo apt-get install gh
87-
- name: Download asset
88-
run: |
89-
gh release download --repo "$GITHUB_REPOSITORY" --pattern ${{ matrix.jar_file }}
90-
- name: Get JAR version
91-
id: get_version
92-
run: |
93-
VERSION=$(unzip -p ${{ matrix.jar_file }} META-INF/MANIFEST.MF | grep "^Version: " | cut -d' ' -f2)
94-
if [[ -z "$VERSION" ]]; then
95-
echo "::error file=${{ matrix.jar_file }}::Could not determine version from JAR's Manifest file"
96-
exit 1
97-
fi
98-
echo "::set-output name=version::$VERSION"
99-
- name: Determine final version
100-
id: final_version
101-
run: |
102-
VERSION="${{ steps.get_version.outputs.version }}"
103-
if ${{ inputs.release_name == 'latest' }}; then
104-
VERSION="$VERSION-SNAPSHOT"
105-
fi
106-
echo "::set-output name=final_version::$VERSION"
107-
- name: Determine artifact ID
108-
id: artifact_id
109-
run: |
110-
FILE_NAME="${{ matrix.jar_file }}"
111-
FILE_NAME_WITHOUT_EXTENSION="${FILE_NAME%.*}"
112-
echo "::set-output name=artifact_id::$FILE_NAME_WITHOUT_EXTENSION"
113-
- name: Check if Maven package already exists
114-
id: check_exists
115-
run: |
116-
VERSION="${{ steps.final_version.outputs.final_version }}"
117-
ARTIFACT_ID=${{ steps.artifact_id.outputs.artifact_id }}
118-
119-
METADATA_URL="https://maven.pkg.github.com/google/watchface/com.google.watchface/${ARTIFACT_ID}/${VERSION}/maven-metadata.xml"
120-
121-
if ${{ inputs.release_name == 'latest' }}; then
122-
# SNAPSHOT version should always publish
123-
echo "::set-output name=should_publish::true"
124-
elif curl -s -f -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$METADATA_URL" | grep -q "^200$"; then
125-
# Don't republish existing non-SNAPSHOT versions
126-
echo "Maven package with version $VERSION already exists."
127-
else
128-
echo "Maven package with version $VERSION does not exist."
129-
echo "::set-output name=should_publish::true"
130-
fi
131-
- name: create settings.xml
132-
if: steps.check_exists.outputs.should_publish == 'true'
133-
run: |
134-
mkdir -p ~/.m2
135-
echo "<settings><servers><server><id>github</id><configuration><httpHeaders><property><name>Authorization</name><value>Bearer ${{ secrets.GITHUB_TOKEN }}</value></property></httpHeaders></configuration></server></servers></settings>" > ~/.m2/settings.xml
136-
shell: bash
137-
env:
138-
GITHUB_PATH: ~/.m2/
139-
- name: Publish to GitHub Packages
140-
if: steps.check_exists.outputs.should_publish == 'true'
141-
run: |
142-
mvn deploy:deploy-file \
143-
-DgroupId=com.google.watchface \
144-
-DartifactId=${{ steps.artifact_id.outputs.artifact_id }} \
145-
-Dversion=${{ steps.final_version.outputs.final_version }} \
146-
-Dpackaging=jar \
147-
-Dfile=${{ matrix.jar_file }} \
148-
-Durl=https://maven.pkg.github.com/google/watchface \
149-
-DrepositoryId=github -s ~/.m2/settings.xml
150-
env:
151-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
6+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
7+
8+
name: Publish Libraries
9+
10+
on:
11+
push:
12+
branches: ["main"]
13+
14+
permissions:
15+
contents: write
16+
packages: write
17+
18+
jobs:
19+
publish_libraries:
20+
runs-on: ubuntu-latest
21+
env:
22+
GITHUB_PACKAGES_URL: "https://maven.pkg.github.com/google/watchface"
23+
GITHUB_PACKAGES_USER: "x-oauth-basic"
24+
GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
steps:
26+
- name: Checkout project
27+
uses: actions/checkout@v3
28+
with:
29+
ref: ${{ inputs.release_git_sha }}
30+
- name: Set up JDK 17
31+
uses: actions/setup-java@v3
32+
with:
33+
java-version: "17"
34+
distribution: "corretto"
35+
architecture: "x64"
36+
- name: Build Memory Footprint
37+
uses: gradle/actions/setup-gradle@v3
38+
with:
39+
build-root-directory: play-validations
40+
arguments: memory-footprint:build
41+
- name: Build Validator
42+
uses: gradle/actions/setup-gradle@v3
43+
with:
44+
build-root-directory: play-validations
45+
arguments: validator:build
46+
- name: Publish Memory Footprint
47+
uses: gradle/actions/setup-gradle@v3
48+
with:
49+
build-root-directory: play-validations
50+
arguments: memory-footprint:publishAllPublicationsToGithubPackagesRepository
51+
- name: Publish WFF Validator
52+
uses: gradle/actions/setup-gradle@v3
53+
with:
54+
build-root-directory: play-validations
55+
arguments: validator:publishAllPublicationsToGithubPackagesRepository

play-validations/build.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,28 @@ allprojects { project ->
5151
}
5252
}
5353
}
54+
55+
def libModules = List.of("validator", "memory-footprint")
56+
subprojects { project ->
57+
if (project.name in libModules) {
58+
afterEvaluate {
59+
version = "1.6.0-SNAPSHOT"
60+
group = "com.google.watchface"
61+
publishing {
62+
repositories {
63+
mavenLocal()
64+
if (System.getenv("GITHUB_PACKAGES_URL") != null) {
65+
maven {
66+
name = "GithubPackages"
67+
url = System.getenv("GITHUB_PACKAGES_URL")
68+
credentials {
69+
username = System.getenv("GITHUB_PACKAGES_USER")
70+
password = System.getenv("GITHUB_PACKAGES_TOKEN")
71+
}
72+
}
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}

play-validations/memory-footprint/build.gradle

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
plugins {
1717
id 'java'
1818
id 'org.jetbrains.kotlin.jvm' version "2.0.21"
19+
id 'maven-publish'
1920
}
2021

2122
def baseVersion = "1.5.1"
@@ -50,40 +51,35 @@ compileTestKotlin {
5051
kotlinOptions.jvmTarget = "17"
5152
}
5253

53-
configurations {
54-
executableJar {
55-
canBeConsumed = true
56-
canBeResolved = false
57-
attributes {
58-
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, 'executableJar'))
59-
}
60-
}
61-
}
62-
63-
jar {
54+
tasks.register('executable-jar', Jar) {
55+
dependsOn("jar")
6456
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
65-
6657
exclude("META-INF/*.RSA", "META-INF/*.DSA", "META-INF/*.SF", "META-INF/maven/**")
6758

6859
manifest {
6960
attributes "Main-Class": "com.google.wear.watchface.dfx.memory.ResourceMemoryEvaluator"
70-
// Use `gradle :memory-footprint:jar -Dmemory-footprint.git_hash=$(git rev-parse --short HEAD)` to store
61+
// Use `gradle :memory-footprint:executable-jar -Dmemory-footprint.git_hash=$(git rev-parse --short HEAD)` to store
7162
// the current build's hash in the manifest file.
7263
if (System.getProperty("memory-footprint.git_hash")) {
7364
attributes "Git-Hash": System.getProperty("memory-footprint.git_hash")
7465
}
7566
attributes "Version": baseVersion
7667
}
77-
7868
from {
7969
configurations.runtimeClasspath.collect {
8070
it.isDirectory() ? it : zipTree(it)
8171
}
8272
}
73+
from sourceSets.main.output
74+
archiveVersion = ""
75+
archiveBaseName = "memory-footprint"
8376
}
8477

85-
artifacts {
86-
executableJar(jar)
78+
tasks.assemble.dependsOn 'executable-jar'
79+
80+
jar {
81+
// exclude the runner class, which is not needed in the library
82+
exclude 'com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluator.class'
8783
}
8884

8985
afterEvaluate {
@@ -114,3 +110,26 @@ test {
114110
"test-samples:sample-wf:zipApk"
115111
)
116112
}
113+
114+
publishing {
115+
publications {
116+
mavenJava(MavenPublication) {
117+
from components.java
118+
119+
// customize pom, removing the dependency to the validator library
120+
// which is not needed when publishing the library
121+
pom {
122+
withXml {
123+
def dependenciesNode = asNode().dependencies[0]
124+
if (dependenciesNode) {
125+
dependenciesNode.dependency.each { dependency ->
126+
if (dependency.artifactId.text() == 'validator') {
127+
dependency.parent().remove(dependency)
128+
}
129+
}
130+
}
131+
}
132+
}
133+
}
134+
}
135+
}

third_party/wff/specification/validator/build.gradle

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
apply plugin: 'java-library'
17-
18-
def baseVersion="1.5.1"
19-
def baseArchivesName="wff-validator"
17+
apply plugin: 'maven-publish'
2018

2119
dependencies {
2220
implementation 'xml-apis:xml-apis:1.4.01'
@@ -30,44 +28,56 @@ tasks.register("bundleDocs", Zip) {
3028
from '../documents/'
3129
include '**/*'
3230
archiveBaseName = "docs"
31+
archiveVersion = ""
3332
destinationDirectory = layout.buildDirectory.dir('libs')
3433
}
3534

3635
compileJava.dependsOn(bundleDocs)
3736

37+
// configure the library jar
3838
jar {
39+
// include the XSDs, which are used as resources
40+
from ('build/libs') {
41+
include 'docs.zip'
42+
}
43+
// exclude the runner class, which is not needed in the library jar
44+
exclude 'com/samsung/watchface/DWFValidationApplication.class'
45+
}
46+
47+
tasks.register('executable-jar', Jar) {
48+
dependsOn("jar")
3949
exclude("META-INF/maven/**")
4050

4151
from {
4252
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
4353
}
54+
from sourceSets.main.output
4455

45-
base.archivesName.set(baseArchivesName)
4656
from ('build/libs') {
4757
include 'docs.zip'
4858
}
4959

60+
archiveBaseName = "wff-validator"
61+
archiveVersion = ""
62+
5063
manifest {
5164
attributes 'Main-Class': 'com.samsung.watchface.DWFValidationApplication'
52-
attributes 'Version': baseVersion
65+
attributes 'Version': version
5366
}
5467
}
5568

56-
tasks.register('library-jar', Jar) {
57-
from sourceSets.main.output
58-
59-
archiveBaseName.set("${baseArchivesName}-library")
60-
archiveVersion.set(baseVersion)
61-
from ('build/libs') {
62-
include 'docs.zip'
63-
}
64-
65-
manifest {
66-
attributes 'Version': baseVersion
67-
}
68-
}
69+
tasks.assemble.dependsOn 'executable-jar'
6970

7071
java {
7172
sourceCompatibility = JavaVersion.VERSION_17
7273
targetCompatibility = JavaVersion.VERSION_17
7374
}
75+
76+
publishing {
77+
publications {
78+
mavenJava(MavenPublication) {
79+
artifactId 'wff-validator'
80+
from components.java
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)