Build CI #2030
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build CI | |
on: | |
push: | |
branches: [ master ] | |
workflow_dispatch: {} | |
pull_request: | |
branches: [ master ] | |
schedule: | |
# Daily at 12pm UTC | |
- cron: '0 12 * * *' | |
jobs: | |
# Build the compiler jar file from the submodule | |
build-compiler: | |
name: Build Compiler | |
runs-on: ubuntu-latest | |
env: | |
COMPILER_NIGHTLY: ${{ github.event_name == 'schedule' }} | |
FORCE_COLOR: '1' | |
steps: | |
- name: Setup Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: adopt-hotspot | |
java-version: 21 | |
java-package: jdk | |
architecture: x64 | |
- name: Setup Bazelisk | |
uses: bazel-contrib/[email protected] | |
with: | |
# Avoid downloading Bazel every time. | |
bazelisk-cache: true | |
# Store build cache per workflow. | |
disk-cache: ${{ github.workflow }} | |
# Share repository cache between workflows. | |
repository-cache: true | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Fetch submodule tags | |
working-directory: compiler | |
run: git fetch --tags https://github.com/google/closure-compiler.git | |
- name: Update compiler submodule to master if nightly build | |
if: ${{ env.COMPILER_NIGHTLY == 'true' }} | |
working-directory: compiler | |
run: | | |
git checkout master | |
git pull https://github.com/google/closure-compiler.git master | |
git log -1 | cat | |
- name: Get yarn cache directory path | |
run: echo "yarn_cache_dir=$(yarn cache dir)" >> $GITHUB_ENV | |
- name: Yarn and maven cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
${{ env.yarn_cache_dir }} | |
~/.m2/repository | |
key: ${{ runner.os }}-yarn-mvn-java11-${{ hashFiles('**/yarn.lock', '**/pom.xml') }} | |
- name: Install packages | |
run: yarn install --colors=always | |
- name: Build jar | |
# unset ANDROID_HOME to prevent bazel from trying to use the Android SDK | |
run: unset ANDROID_HOME && ./build-scripts/build_compiler.js | |
- name: Tests | |
run: node_modules/.bin/mocha --colors | |
- name: Upload contrib folder | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Contrib folder | |
path: compiler/contrib | |
- name: Upload compiler jar | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Compiler.jar | |
path: packages/google-closure-compiler-java/compiler.jar | |
# Build the native image on Linux | |
# The runner image determines GLIBC compatibility and should not be changed without | |
# understanding the impact. See https://github.com/google/closure-compiler-npm/issues/280 | |
build-linux: | |
name: Build Linux Native Image | |
needs: build-compiler | |
runs-on: ubuntu-20.04 | |
env: | |
NODE_VERSION: '18.x' | |
FORCE_COLOR: '1' | |
steps: | |
- name: Setup Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: adopt-hotspot | |
java-version: 21 | |
java-package: jdk | |
architecture: x64 | |
- uses: actions/checkout@v4 | |
- name: Use Node.js ${{ env.NODE_VERSION }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- uses: graalvm/setup-graalvm@v1 | |
with: | |
java-version: 21 | |
distribution: 'graalvm-community' | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
native-image-job-reports: 'true' | |
- name: Setup upx | |
run: | | |
UPX_VERSION=3.96 | |
curl --fail --show-error --location --remote-name "https://github.com/upx/upx/releases/download/v$UPX_VERSION/upx-$UPX_VERSION-amd64_linux.tar.xz" | |
tar -xf upx-$UPX_VERSION-amd64_linux.tar.xz | |
mv ./upx-$UPX_VERSION-amd64_linux/upx /usr/local/bin/upx | |
- name: Download compiler jar | |
uses: actions/download-artifact@v4 | |
with: | |
name: Compiler.jar | |
path: packages/google-closure-compiler-java/ | |
- name: Download contrib folder | |
uses: actions/download-artifact@v4 | |
with: | |
name: Contrib folder | |
path: packages/google-closure-compiler/contrib | |
- name: Get yarn cache directory path | |
run: echo "yarn_cache_dir=$(yarn cache dir)" >> $GITHUB_ENV | |
- name: Cache yarn | |
uses: actions/cache@v4 | |
id: yarn-cache | |
with: | |
path: ${{ env.yarn_cache_dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install packages | |
run: yarn install --colors=always | |
- name: Build image | |
working-directory: packages/google-closure-compiler-linux | |
run: | | |
cp ../google-closure-compiler-java/compiler.jar compiler.jar | |
yarn run build | |
upx compiler | |
- name: Tests | |
run: yarn workspaces run test --colors | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Linux image | |
path: packages/google-closure-compiler-linux/compiler | |
# Build the native image on MacOS | |
build-macos: | |
name: Build MacOS Native Image | |
needs: build-compiler | |
runs-on: macos-latest | |
env: | |
NODE_VERSION: '20.x' | |
FORCE_COLOR: '1' | |
steps: | |
- name: Setup Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: adopt-hotspot | |
java-version: 21 | |
java-package: jdk | |
architecture: x64 | |
- uses: actions/checkout@v4 | |
- name: Use Node.js ${{ env.NODE_VERSION }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- uses: graalvm/setup-graalvm@v1 | |
with: | |
java-version: 21 | |
distribution: 'graalvm-community' | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
native-image-job-reports: 'true' | |
# # See https://github.com/google/closure-compiler-npm/issues/265 | |
# - name: Install upx | |
# run: brew install upx | |
- name: Download compiler jar | |
uses: actions/download-artifact@v4 | |
with: | |
name: Compiler.jar | |
path: packages/google-closure-compiler-java/ | |
- name: Download contrib folder | |
uses: actions/download-artifact@v4 | |
with: | |
name: Contrib folder | |
path: packages/google-closure-compiler/contrib | |
- name: Get yarn cache directory path | |
run: echo "yarn_cache_dir=$(yarn cache dir)" >> $GITHUB_ENV | |
- name: Cache yarn | |
uses: actions/cache@v4 | |
id: yarn-cache | |
with: | |
path: ${{ env.yarn_cache_dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install packages | |
run: yarn install --colors=always | |
- name: Build image | |
working-directory: packages/google-closure-compiler-osx | |
run: | | |
cp ../google-closure-compiler-java/compiler.jar compiler.jar | |
yarn run build | |
# upx compiler | |
- name: Tests | |
run: yarn workspaces run test --colors | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: MacOS image | |
path: packages/google-closure-compiler-osx/compiler | |
# Build the native image on Windows | |
build-windows: | |
name: Build Windows Native Image | |
needs: build-compiler | |
runs-on: windows-latest | |
env: | |
NODE_VERSION: '20.x' | |
FORCE_COLOR: '1' | |
steps: | |
- name: Setup Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: adopt-hotspot | |
java-version: 21 | |
java-package: jdk | |
architecture: x64 | |
- uses: actions/checkout@v4 | |
- name: Use Node.js ${{ env.NODE_VERSION }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- uses: graalvm/setup-graalvm@v1 | |
with: | |
java-version: 21 | |
distribution: 'graalvm-community' | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
native-image-job-reports: 'true' | |
- name: Download compiler jar | |
uses: actions/download-artifact@v4 | |
with: | |
name: Compiler.jar | |
path: packages/google-closure-compiler-java/ | |
- name: Download contrib folder | |
uses: actions/download-artifact@v4 | |
with: | |
name: Contrib folder | |
path: packages/google-closure-compiler/contrib | |
- name: Get yarn cache directory path | |
# See https://stackoverflow.com/a/66737579/1211524 | |
run: echo "yarn_cache_dir=$(yarn cache dir)" >> $env:GITHUB_ENV | |
- name: Cache yarn | |
uses: actions/cache@v4 | |
id: yarn-cache | |
with: | |
path: ${{ env.yarn_cache_dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install packages | |
run: yarn install --colors=always | |
- name: Build image | |
working-directory: packages/google-closure-compiler-windows | |
run: | | |
cp ../google-closure-compiler-java/compiler.jar compiler.jar | |
yarn run build | |
- name: Tests | |
shell: cmd | |
run: | | |
echo "Running Tests" | |
yarn workspaces run test --colors | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Windows image | |
path: packages/google-closure-compiler-windows/compiler.exe | |
# Publish the packages if needed | |
publish-packages: | |
name: Publish Packages | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'schedule' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} | |
env: | |
NODE_VERSION: '20.x' | |
COMPILER_NIGHTLY: ${{ github.event_name == 'schedule' }} | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_AUTH_TOKEN }} | |
FORCE_COLOR: '1' | |
needs: | |
- build-linux | |
- build-macos | |
- build-windows | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js ${{ env.NODE_VERSION }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
registry-url: https://registry.npmjs.org/ | |
- name: Download compiler jar | |
uses: actions/download-artifact@v4 | |
with: | |
name: Compiler.jar | |
path: packages/google-closure-compiler-java/ | |
- name: Download Linux image | |
uses: actions/download-artifact@v4 | |
with: | |
name: Linux image | |
path: packages/google-closure-compiler-linux/ | |
- name: Download MacOS image | |
uses: actions/download-artifact@v4 | |
with: | |
name: MacOS image | |
path: packages/google-closure-compiler-osx/ | |
- name: Download Windows image | |
uses: actions/download-artifact@v4 | |
with: | |
name: Windows image | |
path: packages/google-closure-compiler-windows/ | |
- name: Download contrib folder | |
uses: actions/download-artifact@v4 | |
with: | |
name: Contrib folder | |
path: packages/google-closure-compiler/contrib | |
- name: Mark binaries executable | |
run: | | |
chmod 755 packages/google-closure-compiler-linux/compiler | |
chmod 755 packages/google-closure-compiler-osx/compiler | |
chmod 755 packages/google-closure-compiler-windows/compiler.exe | |
- name: Get yarn cache directory path | |
run: echo "yarn_cache_dir=$(yarn cache dir)" >> $GITHUB_ENV | |
- name: Cache yarn | |
uses: actions/cache@v4 | |
id: yarn-cache | |
with: | |
path: ${{ env.yarn_cache_dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install packages | |
run: yarn install --colors=always | |
- name: Prepare for publish | |
run: ./build-scripts/add-os-restrictions.js | |
- name: Create the nightly version | |
if: ${{ env.COMPILER_NIGHTLY == 'true' }} | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "Github Bot" | |
./build-scripts/create-nightly-version.js | |
- name: Configure yarn | |
run: yarn config set registry https://registry.npmjs.org/ | |
- name: Publish packages to npm | |
run: yarn publish-packages |