From 0373cd8ab9bdcb80cab6bb2f5016f0881c90651a Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Fri, 9 Feb 2024 18:20:02 +0100 Subject: [PATCH] Build native binary in CI (fixes #894) This uses a container to simplify GraalVM installation. --- .github/workflows/ci.yml | 4 +++- .github/workflows/release.yml | 22 ++++++++++++++++++++-- .gitignore | 1 + Dockerfile | 22 ++++++++++++++++++++++ README.md | 5 ++++- build-natives.sh | 30 ++++++++++++++++++++++++++++++ core/pom.xml | 2 +- 7 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 Dockerfile create mode 100755 build-natives.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebfa66709..ae64332b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -# Copyright 2020 The Error Prone Authors. +# Copyright 2020-2024 The Google Java Format Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -72,6 +72,8 @@ jobs: - name: 'Test' shell: bash run: ./mvnw test -B + - name: 'Native' + run: ./build-natives.sh publish_snapshot: name: 'Publish snapshot' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2752e1307..3b002aea9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,17 @@ +# Copyright 2020-2024 The Google Java Format Authors +# +# 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. + name: Release google-java-format on: @@ -53,11 +67,15 @@ jobs: run: ./mvnw --no-transfer-progress -pl 'eclipse_plugin' verify gpg:sign -DskipTests=true -Dgpg.passphrase="${{ secrets.GPG_PASSPHRASE }}" + - name: Build Native binaries with GraalVM in a Container + run: + ./build-natives.sh + - name: Push tag run: | git push origin "v${{ github.event.inputs.version }}" - - name: Add Jars to Release Entry + - name: Add JARs to Release Entry uses: softprops/action-gh-release@v0.1.14 with: draft: true @@ -65,5 +83,5 @@ jobs: tag_name: "v${{ github.event.inputs.version }}" target_commitish: ${{ env.TARGET_COMMITISH }} files: | - core/target/google-java-format-*.jar + core/target/google-java-format* eclipse_plugin/target/google-java-format-eclipse-plugin-*.jar diff --git a/.gitignore b/.gitignore index 29168c0fb..c9e2cf0b9 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ out/ eclipse_plugin/lib/ .mvn/wrapper/maven-wrapper.jar +.cache diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..4892c33cb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright 2015-2024 The Google Java Format Authors +# +# 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. + +FROM ghcr.io/graalvm/native-image-community:21 +WORKDIR /build/ +ADD . /build/ + +RUN ./mvnw -Pnative -DskipTests package -pl core -am diff --git a/README.md b/README.md index 4ba915102..bea9027c7 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,9 @@ Your starting point should be the instance methods of ./mvnw install ``` +The _native_ binaries can be built with `./build-natives.sh` and will be +available as `.cache/container-target/google-java-format` (requires Docker). + ## Contributing Please see [the contributors guide](CONTRIBUTING.md) for details. @@ -161,7 +164,7 @@ Please see [the contributors guide](CONTRIBUTING.md) for details. ## License ```text -Copyright 2015 Google Inc. +Copyright 2015-2024 Google Inc. 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 diff --git a/build-natives.sh b/build-natives.sh new file mode 100755 index 000000000..cc46503b9 --- /dev/null +++ b/build-natives.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright 2015-2024 Google Inc. +# +# 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. + +set -euox pipefail + +M2_VOLUME="$PWD"/.cache/container-m2 +OUTPUT="$PWD"/.cache/container-target +mkdir -p "$M2_VOLUME" "$OUTPUT" + +docker build -v "$M2_VOLUME":/root/.m2:Z -v "$OUTPUT":/build/core/target:Z --rm . + +mdkir core/target +cp .cache/container-target/google-java-format core/target/ +core/target/google-java-format + +# TODO This only builds a Linux ABI Native Binary so far - later also build a Win/Mac one... diff --git a/core/pom.xml b/core/pom.xml index d1363fed1..60add52d1 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -282,7 +282,7 @@ org.graalvm.buildtools native-maven-plugin - 0.9.13 + 0.10.0 true