Add steps in the ci workflow to build and test local artifacts.

Also:

- cache more bazel files to speed up executation
- use java version as part of the cache key since it is part of the input bazel uses
- fix maven_gen_artfiacts for libries that export other libries

PiperOrigin-RevId: 426955192
This commit is contained in:
Guice Team
2022-02-07 10:35:41 -08:00
committed by Guice Team
parent d83603377b
commit c118f26385
9 changed files with 106 additions and 12 deletions
+32
View File
@@ -0,0 +1,32 @@
name: 'Bazel Build'
description: 'Builds artifacts and creates local snapshots maven artifacts.'
runs:
using: "composite"
steps:
- name: 'Set up JDK'
uses: actions/setup-java@v2
with:
distribution: ${{ env.USE_JAVA_DISTRIBUTION }}
java-version: ${{ env.USE_JAVA_VERSION }}
- name: 'Check out repository'
uses: actions/checkout@v2
- name: 'Cache Bazel files'
uses: actions/cache@v2
with:
path: ~/.cache/bazel
key: ${{ runner.os }}-bazel-build-${{ hashFiles('**/WORKSPACE') }}
restore-keys: |
${{ runner.os }}-bazel-build-
- name: 'Bazel build'
# Cross compile for Java 8, see http://openjdk.java.net/jeps/247
run: bazel build --javacopt="--release 8" //...
shell: bash
- name: 'Install local snapshot'
run: ./util/install-local-snapshot.sh
shell: bash
- name: 'Upload local snapshot for local mvn artifiact tests'
uses: actions/upload-artifact@v2
with:
name: local-snapshot
path: ~/.m2/repository/com/google/inject
+6 -6
View File
@@ -8,14 +8,14 @@ runs:
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
distribution: 'zulu'
- name: 'Cache bazel external dependencies'
distribution: ${{ env.USE_JAVA_DISTRIBUTION }}
- name: 'Cache bazel files'
uses: actions/cache@v2
with:
path: ~/.cache/bazel/*/*/external
key: ${{ runner.os }}-bazel-test-${{ hashFiles('**/WORKSPACE') }}
path: ~/.cache/bazel
key: ${{ runner.os }}-java-${{matrix.java}}-bazel-test-${{ hashFiles('**/WORKSPACE') }}
restore-keys: |
${{ runner.os }}-bazel-test-
${{ runner.os }}-java-${{matrix.java}}-bazel-test-
- name: Bazel test
run: bazel test //... --test_output=errors
shell: bash
shell: bash
@@ -0,0 +1,32 @@
name: 'Local Artifact Tests'
description: 'Runs local tests on the installed Guice LOCAL-SNAPSHOT artifacts.'
runs:
using: "composite"
steps:
- name: 'Set up JDK'
uses: actions/setup-java@v2
with:
distribution: ${{ env.USE_JAVA_DISTRIBUTION }}
java-version: ${{ env.USE_JAVA_VERSION }}
- name: 'Cache Maven files'
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-artifact-tests-${{ hashFiles('examples/**/pom.xml') }}
restore-keys: |
${{ runner.os }}-artifact-tests-
- name: 'Delete any stale artifacts from cache'
run: rm -rf ~/.m2/repository/com/google/inject
shell: bash
- name: 'Download local snapshot for tests'
uses: actions/download-artifact@v2
with:
name: local-snapshot
path: ~/.m2/repository/com/google/inject
- name: 'Maven Java local tests'
run: mvn -f examples/guice-demo/pom.xml verify -Dguice.version=LOCAL-SNAPSHOT --fail-at-end
shell: bash
- name: 'Clean up Maven cache'
run: rm -rf ~/.m2/repository/com/google/inject
shell: bash
+1 -1
View File
@@ -8,7 +8,7 @@ runs:
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
distribution: 'zulu'
distribution: ${{ env.USE_JAVA_DISTRIBUTION }}
- name: 'Cache local Maven repository'
uses: actions/cache@v2
with:
+3 -2
View File
@@ -7,8 +7,8 @@ runs:
- name: Setup JDK
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'zulu'
distribution: ${{ env.USE_JAVA_DISTRIBUTION }}
java-version: ${{ env.USE_JAVA_VERSION }}
server-id: google-snapshots
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
@@ -27,3 +27,4 @@ runs:
- name: Publish Snapshot
run: mvn clean deploy -DskipTests=true -Dmaven.javadoc.skip=true
shell: bash
+19 -2
View File
@@ -3,6 +3,8 @@
name: continuous-integration
env:
USE_BAZEL_VERSION: '4.2.2'
USE_JAVA_DISTRIBUTION: 'zulu'
USE_JAVA_VERSION: '11'
on:
push:
@@ -48,9 +50,24 @@ jobs:
- uses: actions/checkout@v2
- uses: ./.github/actions/bazel-test
bazel-build:
runs-on: ubuntu-latest
name: Bazel Build
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/bazel-build
local-artifact-tests:
runs-on: ubuntu-latest
needs: [bazel-build]
name: Local Artifact Tests
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/local-artifact-tests
publish:
runs-on: ubuntu-latest
needs: [test, bazel-test]
needs: [test, bazel-test, bazel-build, local-artifact-tests]
if: github.event_name == 'push' && github.repository == 'google/guice' && github.ref == 'refs/heads/master'
name: Publish Javadoc and Snapshot
@@ -60,4 +77,4 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
+4
View File
@@ -95,5 +95,9 @@ gen_maven_artifact(
artifact_id = "guice",
artifact_name = "Google Guice - Core Library",
artifact_target = ":inject",
artifact_target_libs = [
":annotations",
":implemented_by",
],
javadoc_srcs = [":javadoc-srcs"],
)
@@ -25,6 +25,10 @@ gen_maven_artifact(
artifact_id = "guice-testlib",
artifact_name = "Google Guice - Extensions - TestLib",
artifact_target = ":testlib",
artifact_target_libs = [
"//extensions/testlib/src/com/google/inject/testing/fieldbinder",
"//extensions/testlib/src/com/google/inject/testing/throwingproviders",
],
is_extension = True,
javadoc_srcs = [
"//extensions/testlib/src/com/google/inject/testing/fieldbinder:javadoc-srcs",
+5 -1
View File
@@ -25,6 +25,7 @@ def gen_maven_artifact(
artifact_target,
javadoc_srcs,
packaging = "jar",
artifact_target_libs = [],
is_extension = False):
"""Generates files required for a maven artifact.
@@ -33,6 +34,8 @@ def gen_maven_artifact(
artifact_name: The name of the generated artifcat in maven, e.g. "Google Guice Core Library".
artifact_id: The id of the generated artifact in maven, e.g. "guice".
artifact_target: The target containing the actual maven target.
artifact_target_libs: The list of dependencies that should be packaged together with artifact_target,
corresponding to the list of targets exported by artifact_target.
javadoc_srcs: Source files used to generate the Javadoc maven artifact.
packaging: The packaging used for the artifact, default is "jar".
is_extension: Whether the maven artifact is a Guice extension or not.
@@ -43,7 +46,8 @@ def gen_maven_artifact(
if is_extension:
group_id = "com.google.inject.extensions"
artifact_targets = [artifact_target]
# TODO: get artifact_target_libs from bazel and remove the need to pass this in explictly.
artifact_targets = [artifact_target] + artifact_target_libs
pom_file(
name = "pom",