Skip to content

Commit

Permalink
Build native binary in CI (fixes #894)
Browse files Browse the repository at this point in the history
This uses a container to simplify GraalVM installation.
  • Loading branch information
vorburger committed Feb 9, 2024
1 parent 19c0577 commit 0373cd8
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -72,6 +72,8 @@ jobs:
- name: 'Test'
shell: bash
run: ./mvnw test -B
- name: 'Native'
run: ./build-natives.sh

publish_snapshot:
name: 'Publish snapshot'
Expand Down
22 changes: 20 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -53,17 +67,21 @@ 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/[email protected]
with:
draft: true
name: ${{ github.event.input.version }}
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ out/
eclipse_plugin/lib/

.mvn/wrapper/maven-wrapper.jar
.cache
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,17 @@ 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.

## 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
Expand Down
30 changes: 30 additions & 0 deletions build-natives.sh
Original file line number Diff line number Diff line change
@@ -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...
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.13</version>
<version>0.10.0</version>
<extensions>true</extensions>
<executions>
<execution>
Expand Down

0 comments on commit 0373cd8

Please sign in to comment.