Skip to content

Commit

Permalink
Enable a basic GitHub Actions CI workflow.
Browse files Browse the repository at this point in the history
This workflow should replicate the build and test coverage of the existing Travis CI setup.

PiperOrigin-RevId: 330639268
  • Loading branch information
nreid260 authored and Copybara-Service committed Sep 9, 2020
1 parent f530de7 commit 76946c5
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .bazelrc
Expand Up @@ -2,11 +2,11 @@
#
# Copied from https://github.com/google/j2cl/blob/master/.bazelrc since Bazel
# doesn't support referring to .bazelrc from different workspaces.

build --watchfs

build --spawn_strategy=local
build --strategy=J2cl=worker
build --strategy=Closure=worker
build --experimental_persistent_javac

# Setting for running in remote CI
build --color=yes
51 changes: 51 additions & 0 deletions .github/ci_support/test_closure-compiler-npm.sh
@@ -0,0 +1,51 @@
#!/bin/bash

# Copyright 2020 Google Inc. All Rights Reserved
#
# 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.

# Download and test closure-compiler-npm using the compiler from this commit.
#
# Requirements:
# - PWD = closure-compiler-npm repo root
#
# Params:
# 1. File name of compiler_unshaded_deploy.jar
function main() {
local compiler_jar="$1"

# Download all NPM deps to "node_modules".
yarn install

# Copy the version of the compiler built as a pre-requisite of this script
# into closure-compiler-npm. The NPM repo normally builds the compiler itself,
# and puts the binary in these locations, so we're superceeding that here.
#
# Make sure to copy after yarn install so that the files don't get cleaned up.
#
# TODO(nickreid): This should be done using scripts from inside the NPM repo
cp "${compiler_jar}" "packages/google-closure-compiler-java/compiler.jar"
cp "${compiler_jar}" "packages/google-closure-compiler-osx/compiler.jar"
cp "${compiler_jar}" "packages/google-closure-compiler-linux/compiler.jar"
cp "${compiler_jar}" "packages/google-closure-compiler-windows/compiler.jar"

# Run all the tests inside closure-compiler-npm. This will use the version
# of the compiler we just copied into it.
#
# The NPM repo is divided into multiple Yarn workspaces: one for each
# variant of the compiler, including the Graal native builds.
yarn workspaces run build
yarn workspaces run test
}

main "$@"
120 changes: 120 additions & 0 deletions .github/workflows/ci.yaml
@@ -0,0 +1,120 @@
# Copyright 2020 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
#
# https://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.

# Format reference: https://docs.github.com/en/actions/reference

name: Compiler CI

# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#on
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
# Daily at 12pm UTC
- cron: '0 12 * * *'

env:
VERSION_NODEJS: '10.21.0'
UNSYMLINK_DIR: bazel-bin-unsymlink

# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobs
jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Setup Java
# https://github.com/marketplace/actions/setup-java-jdk
uses: actions/setup-java@v1
with:
java-version: '11'
java-package: jdk
architecture: x64

- name: Setup Bazel
# https://github.com/marketplace/actions/actions-setup-bazel
uses: jwlawson/actions-setup-bazel@v1
with:
bazel-version: '2.2.0'

# Clone closure-compiler repo from the commit under test into current directory.
- name: Checkout Current closure-compiler Commit
# https://github.com/marketplace/actions/checkout
uses: actions/checkout@v2

- name: Build
run: bazel build //:all

- name: Unit Tests
run: bazel test //:all

- name: Unsymlink Bazel Artifacts
# upload-artifact doesn't support paths with symlinks
run: |
mkdir -p ${{ env.UNSYMLINK_DIR }}
cp -t ${{ env.UNSYMLINK_DIR }} bazel-bin/compiler_unshaded_deploy.jar
# Share the following files with other jobs in this workflow. They can be grabbed using ID
# `unshaded_compiler`. This is made possible by uploading the files to GitHub controlled
# storage.
- name: Share Unshaded Compiler
# https://github.com/marketplace/actions/upload-a-build-artifact
uses: actions/upload-artifact@v2
with:
name: unshaded_compiler
path: ${{ env.UNSYMLINK_DIR }}/compiler_unshaded_deploy.jar
if-no-files-found: error

test-closure-compiler-npm:
name: Make Sure closure-compiler-npm is Compatible with this Compiler Build
runs-on: ubuntu-latest
needs:
- build-and-test
steps:
- name: Setup Node.js
# https://github.com/marketplace/actions/setup-node-js-environment
uses: actions/setup-node@v1
with:
node-version: ${{ env.VERSION_NODEJS }}

# Clone closure-compiler-npm repo from master into the current directory.
- name: Checkout Current closure-compiler-npm Commit
# https://github.com/marketplace/actions/checkout
uses: actions/checkout@v2
with:
repository: google/closure-compiler-npm
ref: master

# Clone closure-compiler repo from the commit under test into the npm repo compiler
# submodule
- name: Checkout Current closure-compiler Commit
# https://github.com/marketplace/actions/checkout
uses: actions/checkout@v2
with:
path: compiler

# Grab the compiler binary that was shared from `build-and-test` and put the file into
# ./compiler/bazel-bin.
- name: Grab Unshaded Compiler
# https://github.com/marketplace/actions/download-a-build-artifact
uses: actions/download-artifact@v2
with:
name: unshaded_compiler
# Put the binary where bazel would have put it.
path: compiler/bazel-bin

- name: Test closure-compiler-npm
run: compiler/.github/ci_support/test_closure-compiler-npm.sh compiler/bazel-bin/compiler_unshaded_deploy.jar
17 changes: 9 additions & 8 deletions .gitignore
@@ -1,14 +1,15 @@
build/
dependency-reduced-pom.xml
TESTS-TestSuites.xml
junit*.properties
target/
*~
.checkstyle
.settings
.classpath
.project
.settings
/.metadata/
/bin
/yarn.lock
/node_modules
/.metadata/
/yarn.lock
TESTS-TestSuites.xml
bazel-*
build/
dependency-reduced-pom.xml
junit*.properties
target/
30 changes: 11 additions & 19 deletions sonatype_artifact_bundle.bzl
Expand Up @@ -38,24 +38,17 @@ Returns:
_SNAPSHOT = "1.0-SNAPSHOT"

def _sonatype_artifact_bundle(ctx):
# If there are missing defines, we choose to skip all actions for this target,
# rather than fail, so that:
# - `bazel test //:all` still works
# - defines can't be forgotten when intentionally building the bundle
#
# This way, only downstream actions that truly depend on the bundle are affected.

password = _warn_missing_define(ctx, "CLEARTEXT_GPG_PASSPHRASE")
if password == None:
return []

version = _warn_missing_define(ctx, "COMPILER_VERSION")
if version == None:
return []
elif version == _SNAPSHOT:
version = ctx.var.get("COMPILER_VERSION", _SNAPSHOT)
password = None

if version == _SNAPSHOT:
# SNAPSHOT versions don't need to be signed and can't be uploaded
# as a release, so there's no issue with a missing passphrase.
pass
elif not version.startswith("v") or not version[1:].isdigit():
fail("--define=COMPILER_VERSION was malformed; got '{0}'".format(version))
else:
password = _fail_missing_define(ctx, "CLEARTEXT_GPG_PASSPHRASE")

# 1. Rename the POM to have the mandatory base name "pom.xml"
# 2. Confirm the POM is for the right artifact
Expand Down Expand Up @@ -93,7 +86,7 @@ def _sonatype_artifact_bundle(ctx):
for suffix, file in jar_map.items()
if file
]
signatures = [_gpg_signature(ctx, password, f) for f in srcs]
signatures = [_gpg_signature(ctx, password, f) for f in srcs if password]
files_to_bundle = srcs + signatures

# Set all bundle files to be at the top level of the JAR.
Expand Down Expand Up @@ -173,9 +166,8 @@ def _copy_file(ctx, file, name):
def _declare_file(ctx, name):
return ctx.actions.declare_file("{0}/{1}".format(ctx.attr.name, name))

def _warn_missing_define(ctx, name):
def _fail_missing_define(ctx, name):
value = ctx.var.get(name, None)
if value == None:
# buildifier: disable=print
print(ctx.label, "--define={0} was not set; assuming target should be skipped.".format(name))
fail(ctx.label, "--define={0} was not set".format(name))
return value

0 comments on commit 76946c5

Please sign in to comment.