Skip to content

Commit 294241a

Browse files
authored
Adds package publishing for watch face tools (#75)
1 parent 4bfe854 commit 294241a

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

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

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on:
1818

1919
permissions:
2020
contents: write
21+
packages: write
2122

2223
jobs:
2324
build_memory_footprint:
@@ -61,11 +62,90 @@ jobs:
6162
with:
6263
repo_token: "${{ secrets.GITHUB_TOKEN }}"
6364
automatic_release_tag: "${{ inputs.release_name }}"
64-
prerelease: true
65+
prerelease: false
6566
title: "Memory Footprint Build"
6667
files: |
6768
memory-footprint_LICENSE.txt
6869
wff-validator_LICENSE.txt
6970
**/memory-footprint.jar
7071
**/wff-validator.jar
7172
**/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 artefact ID
108+
id: artefact_id
109+
run: |
110+
FILE_NAME="${{ matrix.jar_file }}"
111+
FILE_NAME_WITHOUT_EXTENSION="${FILE_NAME%.*}"
112+
echo "::set-output name=artefact_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+
ARTEFACT_ID=${{ steps.artefact_id.outputs.artefact_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 -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$METADATA_URL"; 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.artefact_id.outputs.artefact_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 }}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313

1414
permissions:
1515
contents: write
16+
packages: write
1617

1718
jobs:
1819
call-publish-base:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ on:
2020

2121
permissions:
2222
contents: write
23+
packages: write
2324

2425
jobs:
2526
call-publish-base:

0 commit comments

Comments
 (0)