Skip to content

Commit 321a3f5

Browse files
authored
upload artifacts (#124)
Change the build process to upload native shared objects during the Github Actions process, and to add an option for downloading them again when building the library (rather than building them locally.) This will be used to release the library from machines that do not support the exact cross-compilation strategies used in Github Actions workflows.
1 parent ca72433 commit 321a3f5

File tree

5 files changed

+203
-22
lines changed

5 files changed

+203
-22
lines changed

.github/workflows/tests.yml

+68-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ jobs:
4545
- name: Format check for C
4646
run: git diff --exit-code
4747

48+
- uses: actions/upload-artifact@v3
49+
name: Upload artifacts
50+
if: ${{ matrix.java-version == 8 }}
51+
with:
52+
name: docker-built-shared-objects
53+
path: |
54+
src/main/resources/*/*.so
55+
src/main/resources/*/*.dll
56+
if-no-files-found: error
57+
4858
tests-new-dockcross:
4959
name: Dockcross ${{ matrix.dockcross-tag }} Java ${{ matrix.java-version }} ${{ matrix.os }}
5060
runs-on: ${{ matrix.os }}
@@ -54,7 +64,7 @@ jobs:
5464
os: [ubuntu-latest]
5565
java-distribution: [adopt]
5666
java-version: [17]
57-
dockcross-tag: ["20220906-e88a3ce"]
67+
dockcross-tag: ["20220906-e88a3ce", "20230116-670f7f7"]
5868

5969
steps:
6070
- uses: actions/[email protected]
@@ -109,6 +119,14 @@ jobs:
109119
- name: Tests
110120
run: mvn -B -V clean test site
111121

122+
- uses: actions/upload-artifact@v3
123+
name: Upload Mac OS Artifacts
124+
if: ${{ matrix.os == 'macos-latest' && matrix.java-version == 8 }}
125+
with:
126+
name: macos-built-shared-objects
127+
path: src/main/resources/*/*.dylib
128+
if-no-files-found: error
129+
112130
tests-coverage:
113131
name: Java (Coverage) ${{ matrix.java-version }} ${{ matrix.os }}
114132
runs-on: ${{ matrix.os }}
@@ -143,3 +161,52 @@ jobs:
143161
env:
144162
CI_NAME: github
145163
COVERALLS_SECRET: ${{ secrets.GITHUB_TOKEN }}
164+
165+
tests-use-built-artifacts:
166+
name: Java (Built Artifacts) ${{ matrix.java-version }} ${{ matrix.os }}
167+
needs:
168+
- tests
169+
- tests-no-docker
170+
runs-on: ${{ matrix.os }}
171+
172+
strategy:
173+
matrix:
174+
os: [ubuntu-latest]
175+
java-distribution: [adopt]
176+
java-version: [8]
177+
178+
steps:
179+
- uses: actions/[email protected]
180+
with:
181+
submodules: recursive
182+
183+
- uses: actions/setup-java@v2
184+
with:
185+
distribution: "${{ matrix.java-distribution }}"
186+
java-version: "${{ matrix.java-version }}"
187+
188+
- uses: actions/cache@v2
189+
id: maven-cache
190+
with:
191+
path: ~/.m2/
192+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
193+
restore-keys: |
194+
${{ runner.os }}-maven-
195+
196+
- name: Download Docker binaries
197+
uses: actions/download-artifact@v3
198+
with:
199+
name: docker-built-shared-objects
200+
path: src/main/resources/
201+
202+
- name: Download Mac binaries
203+
uses: actions/download-artifact@v3
204+
with:
205+
name: macos-built-shared-objects
206+
path: src/main/resources/
207+
208+
- name: Download and test
209+
run: |
210+
mvn clean test -Dh3.github.artifacts.use=true -Dh3.github.artifacts.by_run=true
211+
env:
212+
GH_TOKEN: ${{ github.token }}

docs/releasing.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ Release builds should only be run on Mac OSX with Docker. This is needed so that
88

99
1. Ensure you are on branch `master` and that the library is building correctly.
1010
2. Update [CHANGELOG.md](../CHANGELOG.md) to have the correct date and new version number, update [README.md](../README.md) to have the correct version numbers, and commit.
11-
3. `mvn release:prepare` Use the new version number when prompted.
12-
4. `mvn release:perform`
11+
3. `mvn release:prepare -Dh3.github.artifacts.use=true` Use the new version number when prompted.
12+
4. `mvn release:perform -Dh3.github.artifacts.use=true`
1313
5. If this looks good, close and release the build in [Sonatype Nexus Manager](https://oss.sonatype.org/).
1414
6. Update `CHANGELOG.md` to have an Unreleased section, and commit. The release is now done and development can resume from this point.
1515

1616
## Troubleshooting
1717

18+
### Dependencies for `pull-from-github.sh`
19+
20+
* You should install the [Github CLI](https://cli.github.com) and authenticate with it first. You may need to use a personal access token (classic) with workflows scope.
21+
* `jq`
22+
1823
### gpg: signing failed: Inappropriate ioctl for device
1924

2025
Per [StackOverflow](https://stackoverflow.com/questions/57591432/gpg-signing-failed-inappropriate-ioctl-for-device-on-macos-with-maven), run the following before `mvn release:perform`:

pom.xml

+13-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<groupId>com.uber</groupId>
1919
<artifactId>h3</artifactId>
2020
<packaging>jar</packaging>
21-
<version>4.0.3-SNAPSHOT</version>
21+
<version>4.1.0</version>
2222
<name>h3</name>
2323
<url>https://github.com/uber/h3-java</url>
2424
<description>Java bindings for H3, a hierarchical hexagonal geospatial indexing system.</description>
@@ -40,7 +40,7 @@
4040
<connection>scm:git:git://github.com/uber/h3-java.git</connection>
4141
<developerConnection>scm:git:ssh://[email protected]/uber/h3-java.git</developerConnection>
4242
<url>http://github.com/uber/h3-java/tree/master</url>
43-
<tag>HEAD</tag>
43+
<tag>v4.1.0</tag>
4444
</scm>
4545

4646
<developers>
@@ -72,6 +72,8 @@
7272
<h3.use.docker>true</h3.use.docker>
7373
<h3.system.prune>false</h3.system.prune>
7474
<h3.dockcross.tag>20210624-de7b1b0</h3.dockcross.tag>
75+
<h3.github.artifacts.use>false</h3.github.artifacts.use>
76+
<h3.github.artifacts.by_run />
7577
<!-- Used for passing additional arguments to surefire when using JaCoCo -->
7678
<h3.additional.argLine />
7779

@@ -112,7 +114,7 @@
112114
<plugin>
113115
<groupId>org.codehaus.mojo</groupId>
114116
<artifactId>exec-maven-plugin</artifactId>
115-
<version>1.1.1</version>
117+
<version>3.1.0</version>
116118
<executions>
117119
<execution>
118120
<!-- Override when building on Windows to use PowerShell & MSVC -->
@@ -127,7 +129,7 @@
127129
<argument>-ExecutionPolicy</argument>
128130
<argument>Bypass</argument>
129131
<argument>-File</argument>
130-
<argument>${basedir}/src/main/c/h3-java/build-h3-windows.ps1</argument>
132+
<argument>${project.basedir}/src/main/c/h3-java/build-h3-windows.ps1</argument>
131133
<argument>${h3.git.remote}</argument>
132134
<argument>${h3.git.reference}</argument>
133135
</arguments>
@@ -203,7 +205,7 @@
203205
</goals>
204206
<configuration>
205207
<files>
206-
<file>${basedir}/h3version.properties</file>
208+
<file>${project.basedir}/h3version.properties</file>
207209
</files>
208210
</configuration>
209211
</execution>
@@ -223,7 +225,7 @@
223225

224226
<!-- Generate the native header file -->
225227
<arg>-h</arg>
226-
<arg>${basedir}/src/main/c/h3-java/src</arg>
228+
<arg>${project.basedir}/src/main/c/h3-java/src</arg>
227229
</compilerArgs>
228230
</configuration>
229231
</plugin>
@@ -250,7 +252,7 @@
250252
<plugin>
251253
<groupId>org.codehaus.mojo</groupId>
252254
<artifactId>exec-maven-plugin</artifactId>
253-
<version>1.1.1</version>
255+
<version>3.1.0</version>
254256
<executions>
255257
<execution>
256258
<id>build-h3-c</id>
@@ -261,13 +263,15 @@
261263
<goal>exec</goal>
262264
</goals>
263265
<configuration>
264-
<executable>${basedir}/src/main/c/h3-java/build-h3.sh</executable>
266+
<executable>${project.basedir}/src/main/c/h3-java/build-h3.sh</executable>
265267
<arguments>
266268
<argument>${h3.git.remote}</argument>
267269
<argument>${h3.git.reference}</argument>
268270
<argument>${h3.use.docker}</argument>
269271
<argument>${h3.system.prune}</argument>
270272
<argument>${h3.dockcross.tag}</argument>
273+
<argument>${h3.github.artifacts.use}</argument>
274+
<argument>${h3.github.artifacts.by_run}</argument>
271275
</arguments>
272276
</configuration>
273277
</execution>
@@ -288,7 +292,7 @@
288292
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
289293
<resources>
290294
<resource>
291-
<directory>${basedir}/src/main/resources</directory>
295+
<directory>${project.basedir}/src/main/resources</directory>
292296
<filtering>false</filtering>
293297
</resource>
294298
</resources>

src/main/c/h3-java/build-h3.sh

+27-10
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@
1515
# limitations under the License.
1616
#
1717

18-
# Arguments: [git-remote] [git-ref] [use-docker] [remove-images]
19-
# git-remote - The git remote to pull from. An existing cloned repository
20-
# will not be deleted if a new remote is specified.
21-
# git-ref - Specific git ref of H3 to build.
22-
# use-docker - "true" to perform cross compilation via Docker, "false" to
23-
# skip that step.
24-
# system-prune - If use-docker is true and this argument is true, Docker
25-
# system prune will be run after each step
26-
# (i.e. for disk space constrained environments like CI)
27-
# dockcross-tag - Tag name for dockcross
18+
# Arguments: [git-remote] [git-ref] [use-docker] [remove-images] [github-artifacts] [github-artifacts-ref]
19+
# git-remote - The git remote to pull from. An existing cloned repository
20+
# will not be deleted if a new remote is specified.
21+
# git-ref - Specific git ref of H3 to build.
22+
# use-docker - "true" to perform cross compilation via Docker, "false" to
23+
# skip that step.
24+
# system-prune - If use-docker is true and this argument is true, Docker
25+
# system prune will be run after each step
26+
# (i.e. for disk space constrained environments like CI)
27+
# dockcross-tag - Tag name for dockcross
28+
# github-artifacts - When set, all build artifacts are retrieved from Github
29+
# Actions artifacts rather than built locally (overrides
30+
# all other settings.)
31+
# github-artifacts-run - When set, assume the artifacts have already been
32+
# downloaded.
2833
#
2934
# This script downloads H3, builds H3 and the H3-Java native library, and
3035
# cross compiles via Docker.
@@ -39,6 +44,13 @@ GIT_REVISION=$2
3944
USE_DOCKER=$3
4045
SYSTEM_PRUNE=$4
4146
DOCKCROSS_TAG=$5
47+
GITHUB_ARTIFACTS=$6
48+
GITHUB_ARTIFACTS_RUN=$7
49+
50+
if $GITHUB_ARTIFACTS; then
51+
src/main/c/h3-java/pull-from-github.sh "$GITHUB_ARTIFACTS_RUN"
52+
# The build of the library below is still needed for the binding-functions file
53+
fi
4254

4355
echo Downloading H3 from "$GIT_REMOTE"
4456

@@ -90,6 +102,11 @@ cp h3-java-build/build/binding-functions .
90102

91103
popd # target
92104

105+
if $GITHUB_ARTIFACTS; then
106+
# Nothing more is needed than the binding-functions to stop now.
107+
exit 0
108+
fi
109+
93110
# Copy the built artifact for this platform.
94111
case "$(uname -sm)" in
95112
"Linux x86_64") LIBRARY_DIR=linux-x64 ;;
+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2023 Uber Technologies, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
# Retrieves built artifacts from Github. The purpose of this script is
19+
# to enable deployment from any system, regardless of whether it can
20+
# run the particular cross compiling steps needed to build native shared
21+
# objects. Some of the native shared objects require particular Docker
22+
# setups, or indeed running on Mac OS, which is difficult to maintain.
23+
#
24+
# You must install the Github CLI and authenticate with a personal access
25+
# token (classic) with workflows scope to use this. https://cli.github.com/
26+
# This script also requires `jq`.
27+
#
28+
# This script expects to be run from the project's base directory (where
29+
# pom.xml is) as part of the Maven build process.
30+
31+
set -eox pipefail
32+
33+
GITHUB_ARTIFACTS_RUN=$1
34+
35+
EXTRACT_TO=src/main/resources
36+
37+
if [ -z "$GITHUB_ARTIFACTS_RUN" ]; then
38+
mkdir -p target
39+
pushd target
40+
41+
ARTIFACTS_LIST=$(gh api \
42+
-H "Accept: application/vnd.github+json" \
43+
/repos/{owner}/{repo}/actions/artifacts)
44+
45+
echo "downloading artifacts for run $GITHUB_ARTIFACTS_RUN"
46+
TO_DOWNLOAD=$(echo "$ARTIFACTS_LIST" \
47+
| jq ".artifacts[] | select(.workflow_run.id == \"$GITHUB_ARTIFACTS_RUN\")")
48+
49+
echo $TO_DOWNLOAD | jq -c '.' | while read artifactline; do
50+
ARTIFACT_NAME=$(echo $artifactline | jq -r .name)
51+
ARTIFACT_ID=$(echo $artifactline | jq .id)
52+
echo "Downloading $ARTIFACT_NAME: $ARTIFACT_ID"
53+
gh api "/repos/{owner}/{repo}/actions/artifacts/$ARTIFACT_ID/zip" > "$ARTIFACT_NAME.zip"
54+
unzip -o "$ARTIFACT_NAME.zip" -d "../$EXTRACT_TO"
55+
done
56+
57+
popd
58+
fi
59+
60+
echo Checking that expected images are present:
61+
62+
for image in android-arm android-arm64 linux-arm64 linux-armv5 linux-armv7 linux-s390x \
63+
linux-ppc64le linux-x64 linux-x86; do
64+
if [ -f "$EXTRACT_TO/$image/libh3-java.so" ]; then
65+
echo "$image" exists
66+
else
67+
echo "$image" missing!
68+
exit 1
69+
fi
70+
done
71+
72+
for image in darwin-x64 darwin-arm64; do
73+
if [ -f "$EXTRACT_TO/$image/libh3-java.dylib" ]; then
74+
echo "$image" exists
75+
else
76+
echo "$image" missing!
77+
exit 1
78+
fi
79+
done
80+
81+
for image in windows-x64 windows-x86; do
82+
if [ -f "$EXTRACT_TO/$image/libh3-java.dll" ]; then
83+
echo "$image" exists
84+
else
85+
echo "$image" missing!
86+
exit 1
87+
fi
88+
done

0 commit comments

Comments
 (0)