Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 2 additions & 81 deletions .github/workflows/gradle-publish-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
uses: gradle/actions/setup-gradle@v3
with:
build-root-directory: play-validations
arguments: memory-footprint:jar -Dmemory-footprint.git_hash=${{ env.git_hash }}
arguments: memory-footprint:memory-footprint-cli:jar -Dmemory-footprint.git_hash=${{ env.git_hash }}
- name: Build wff-validator
uses: gradle/actions/setup-gradle@v3
with:
Expand All @@ -67,85 +67,6 @@ jobs:
files: |
memory-footprint_LICENSE.txt
wff-validator_LICENSE.txt
**/memory-footprint.jar
**/memory-footprint-cli/**/memory-footprint.jar
**/wff-validator.jar
**/wff-xsd.zip

publish_packages:
runs-on: ubuntu-latest
needs: build_memory_footprint
env:
GH_TOKEN: ${{ github.token }}
strategy:
matrix:
jar_file: [wff-validator.jar, memory-footprint.jar]
steps:
- name: Install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install gh
- name: Download asset
run: |
gh release download --repo "$GITHUB_REPOSITORY" --pattern ${{ matrix.jar_file }}
- name: Get JAR version
id: get_version
run: |
VERSION=$(unzip -p ${{ matrix.jar_file }} META-INF/MANIFEST.MF | grep "^Version: " | cut -d' ' -f2)
if [[ -z "$VERSION" ]]; then
echo "::error file=${{ matrix.jar_file }}::Could not determine version from JAR's Manifest file"
exit 1
fi
echo "::set-output name=version::$VERSION"
- name: Determine final version
id: final_version
run: |
VERSION="${{ steps.get_version.outputs.version }}"
if ${{ inputs.release_name == 'latest' }}; then
VERSION="$VERSION-SNAPSHOT"
fi
echo "::set-output name=final_version::$VERSION"
- name: Determine artifact ID
id: artifact_id
run: |
FILE_NAME="${{ matrix.jar_file }}"
FILE_NAME_WITHOUT_EXTENSION="${FILE_NAME%.*}"
echo "::set-output name=artifact_id::$FILE_NAME_WITHOUT_EXTENSION"
- name: Check if Maven package already exists
id: check_exists
run: |
VERSION="${{ steps.final_version.outputs.final_version }}"
ARTIFACT_ID=${{ steps.artifact_id.outputs.artifact_id }}

METADATA_URL="https://maven.pkg.github.com/google/watchface/com.google.watchface/${ARTIFACT_ID}/${VERSION}/maven-metadata.xml"

if ${{ inputs.release_name == 'latest' }}; then
# SNAPSHOT version should always publish
echo "::set-output name=should_publish::true"
elif curl -s -f -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$METADATA_URL" | grep -q "^200$"; then
# Don't republish existing non-SNAPSHOT versions
echo "Maven package with version $VERSION already exists."
else
echo "Maven package with version $VERSION does not exist."
echo "::set-output name=should_publish::true"
fi
- name: create settings.xml
if: steps.check_exists.outputs.should_publish == 'true'
run: |
mkdir -p ~/.m2
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
shell: bash
env:
GITHUB_PATH: ~/.m2/
- name: Publish to GitHub Packages
if: steps.check_exists.outputs.should_publish == 'true'
run: |
mvn deploy:deploy-file \
-DgroupId=com.google.watchface \
-DartifactId=${{ steps.artifact_id.outputs.artifact_id }} \
-Dversion=${{ steps.final_version.outputs.final_version }} \
-Dpackaging=jar \
-Dfile=${{ matrix.jar_file }} \
-Durl=https://maven.pkg.github.com/google/watchface \
-DrepositoryId=github -s ~/.m2/settings.xml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38 changes: 38 additions & 0 deletions .github/workflows/gradle-publish-libs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

on:
pull_request:
branches: ["main"]

permissions:
contents: write
packages: write

jobs:
publish_libraries:
runs-on: ubuntu-latest
env:
GITHUB_PACKAGES_URL: "https://maven.pkg.github.com/google/watchface"
GITHUB_PACKAGES_USER: "x-oauth-basic"
GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout project
uses: actions/checkout@v3
with:
ref: ${{ inputs.release_git_sha }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "corretto"
architecture: "x64"
- name: Publish Memory Footprint
uses: gradle/actions/setup-gradle@v3
with:
build-root-directory: play-validations
arguments: memory-footprint:publishAllPublicationsToGithubPackagesRepository
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
uses: gradle/actions/setup-gradle@v3
with:
build-root-directory: play-validations
arguments: memory-footprint:jar -Dmemory-footprint.git_hash=${{ env.git_hash }}
arguments: memory-footprint:memory-footprint-cli:jar -Dmemory-footprint.git_hash=${{ env.git_hash }}
- name: Test memory-footprint
uses: gradle/actions/setup-gradle@v3
with:
Expand Down
71 changes: 26 additions & 45 deletions play-validations/memory-footprint/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,34 @@
* limitations under the License.
*/
plugins {
id 'java'
id 'java-library'
id 'maven-publish'
id 'org.jetbrains.kotlin.jvm' version "2.0.21"
}

def baseVersion = "1.5.1"
version = "1.6.0-SNAPSHOT"
group = 'com.google.watchface'

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
if (System.getenv("GITHUB_PACKAGES_URL") != null) {
maven {
name = "GithubPackages"
url = System.getenv("GITHUB_PACKAGES_URL")
credentials {
username = System.getenv("GITHUB_PACKAGES_USER")
password = System.getenv("GITHUB_PACKAGES_TOKEN")
}
}
}
}
}

dependencies {
implementation 'com.twelvemonkeys.imageio:imageio-webp:3.9.4'
Expand All @@ -30,8 +53,8 @@ dependencies {
implementation 'com.github.xgouchet:AXML:v1.0.1'
implementation("com.android.tools.build:aapt2-proto:8.7.3-12006047")
implementation("com.google.protobuf:protobuf-java:4.29.3")
implementation project(':validator')

testImplementation project(":validator")
testImplementation 'junit:junit:4.13.2'
testImplementation 'com.google.truth:truth:1.4.4'
testImplementation 'com.google.jimfs:jimfs:1.3.0'
Expand All @@ -50,48 +73,6 @@ compileTestKotlin {
kotlinOptions.jvmTarget = "17"
}

configurations {
executableJar {
canBeConsumed = true
canBeResolved = false
attributes {
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, 'executableJar'))
}
}
}

jar {
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)

exclude("META-INF/*.RSA", "META-INF/*.DSA", "META-INF/*.SF", "META-INF/maven/**")

manifest {
attributes "Main-Class": "com.google.wear.watchface.dfx.memory.ResourceMemoryEvaluator"
// Use `gradle :memory-footprint:jar -Dmemory-footprint.git_hash=$(git rev-parse --short HEAD)` to store
// the current build's hash in the manifest file.
if (System.getProperty("memory-footprint.git_hash")) {
attributes "Git-Hash": System.getProperty("memory-footprint.git_hash")
}
attributes "Version": baseVersion
}

from {
configurations.runtimeClasspath.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}

artifacts {
executableJar(jar)
}

afterEvaluate {
tasks.named("jar") {
dependsOn(":validator:jar")
}
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
113 changes: 113 additions & 0 deletions play-validations/memory-footprint/memory-footprint-cli/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version "2.0.21"
}

def baseVersion = "1.5.1"

dependencies {
implementation project(":memory-footprint")
implementation project(':validator')
implementation 'com.google.code.gson:gson:2.11.0'
implementation 'com.google.guava:guava:33.3.1-jre'

testImplementation 'junit:junit:4.13.2'
testImplementation 'com.google.truth:truth:1.4.4'
testImplementation 'com.google.jimfs:jimfs:1.3.0'
}

compileJava {
sourceCompatibility = '17'
targetCompatibility = '17'
}

compileKotlin {
kotlinOptions.jvmTarget = "17"
}

compileTestKotlin {
kotlinOptions.jvmTarget = "17"
}

configurations {
executableJar {
canBeConsumed = true
canBeResolved = false
attributes {
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, 'executableJar'))
}
}
}

jar {
// Keep the resulting jar name the same as before the module structure changes,
// so that the release permalink is consistent
archiveBaseName = 'memory-footprint'
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)

exclude("META-INF/*.RSA", "META-INF/*.DSA", "META-INF/*.SF", "META-INF/maven/**")

manifest {
attributes "Main-Class": "com.google.wear.watchface.dfx.memory.ResourceMemoryEvaluator"
// Use `gradle :memory-footprint:jar -Dmemory-footprint.git_hash=$(git rev-parse --short HEAD)` to store
// the current build's hash in the manifest file.
if (System.getProperty("memory-footprint.git_hash")) {
attributes "Git-Hash": System.getProperty("memory-footprint.git_hash")
}
attributes "Version": baseVersion
}

from {
configurations.runtimeClasspath.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}

artifacts {
executableJar(jar)
}

afterEvaluate {
tasks.named("jar") {
dependsOn(":validator:jar", ":memory-footprint:jar")
}
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

test {
testLogging {
outputs.upToDateWhen { false }
events "passed", "skipped", "failed"
showStandardStreams = true
exceptionFormat = "full"
}

// build the artifacts needed for the ResourceMemoryEvaluatorTest.GoldenTest
dependsOn(
":memory-footprint:test-samples:sample-wf:bundleRelease",
":memory-footprint:test-samples:sample-wf:assembleRelease",
":memory-footprint:test-samples:sample-wf:unpackBundle",
":memory-footprint:test-samples:sample-wf:resDirectory",
":memory-footprint:test-samples:sample-wf:zipApk"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -125,9 +124,9 @@ static List<MemoryFootprint> evaluateMemoryFootprint(EvaluationSettings evaluati
return watchFaceData.getWatchFaceDocuments().stream()
.map(
watchFaceDocument ->
evaluateWatchFaceForLayout(
watchFaceData.getResourceDetailsMap(),
WatchFaceLayoutEvaluator.evaluate(
watchFaceDocument,
watchFaceData.getResourceDetailsMap(),
evaluationSettings))
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -158,21 +157,14 @@ public static List<MemoryFootprint> evaluateMemoryFootprintOrThrow(
return watchFaceData.getWatchFaceDocuments().stream()
.map(
watchFaceDocument ->
evaluateWatchFaceForLayout(
watchFaceData.getResourceDetailsMap(),
WatchFaceLayoutEvaluator.evaluate(
watchFaceDocument,
watchFaceData.getResourceDetailsMap(),
evaluationSettings))
.collect(Collectors.toList());
}
}

static MemoryFootprint evaluateWatchFaceForLayout(
Map<String, DrawableResourceDetails> resourceMemoryMap,
Document currentLayout,
EvaluationSettings settings) {
return WatchFaceLayoutEvaluator.evaluate(currentLayout, resourceMemoryMap, settings);
}

/**
* Returns format version as specified in the evaluation settings or from Android Manifest file.
*/
Expand Down
Loading
Loading