Repository navigation
146 lines (140 loc) · 6.1 KB
/
Copy pathjava.yml
File metadata and controls
146 lines (140 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: java
# Builds the Java package (packages/java: JNA over inkvec-ffi's C ABI) using the per-platform
# native libraries the "bindings" workflow already builds (job c-library), rather than
# rebuilding them here: it runs after that workflow finishes on main or a v* tag, downloads
# its c-* artifacts, and unpacks each platform's shared library into the jar under JNA's
# resource prefix (win32-x86-64/, linux-x86-64/, linux-aarch64/, darwin-x86-64/,
# darwin-aarch64/), so the assembled jar needs no native build step for a consumer.
#
# Tested on linux, windows and macos against that assembled jar (no jna.library.path
# override: this is the same jar a consumer would get). It is not published anywhere: the
# Java binding is built from this repository by whoever wants it (`packages/java/README.md`),
# so this workflow builds and tests the jar and attaches it to the run, and that is all.
#
# There was a publish-to-Maven-Central job here. It never ran and never could: this
# workflow is triggered by `workflow_run`, whose `github.ref` is the default branch even
# when the run it followed was a tag, so its `startsWith(github.ref, 'refs/tags/v')` guard
# was false every time. Publishing to Central also needs a verified namespace, which the
# placeholder group id `com.logolabs` is not. Neither is worth carrying for a package
# nobody has asked to consume from a registry.
#
# NOT verified by running this workflow -- no CI has executed it. Locally verified instead:
# `cargo build --release -p inkvec-ffi` + `mvn test` on Windows x64 with JDK 22, and a
# `--release 8` compile, per packages/java/README.md.
on:
workflow_run:
workflows: [bindings]
types: [completed]
workflow_dispatch:
inputs:
run_id:
description: >-
Run id of the "bindings" workflow to pull the C libraries from. Defaults to the
triggering run when this is itself triggered by that workflow finishing.
required: false
permissions:
contents: read
concurrency:
group: java-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}
jobs:
assemble:
name: assemble the jar
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- uses: actions/setup-python@v7
with:
python-version: "3.11"
- name: generated files are current (InkvecOptions.java, the README table, pom.xml's version)
run: |
python bindings/codegen/generate.py --check
python packages/java/build.py --check
- uses: actions/setup-java@v6
with:
distribution: temurin
java-version: "17"
- name: download the C libraries the bindings workflow built
uses: actions/download-artifact@v8
with:
pattern: c-*
path: c-libs
run-id: ${{ github.event.workflow_run.id || inputs.run_id || github.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: unpack each platform's shared library into its JNA resource prefix
shell: bash
run: |
set -euo pipefail
unpack() { # unpack <c-library artifact dir name> <jna resource prefix>
local archive work
archive=$(find "c-libs/$1" -maxdepth 1 -type f \( -name '*.tar.gz' -o -name '*.zip' \) | head -1)
[ -n "$archive" ] || { echo "no archive found for $1"; return 1; }
work=$(mktemp -d)
case "$archive" in
*.tar.gz) tar -xzf "$archive" -C "$work" ;;
*.zip) unzip -q "$archive" -d "$work" ;;
esac
local staged dest
staged=$(find "$work" -maxdepth 1 -mindepth 1 -type d | head -1)
dest="packages/java/src/main/resources/$2"
mkdir -p "$dest"
cp "$staged"/lib/inkvec_ffi.dll "$dest"/ 2>/dev/null || true
cp "$staged"/lib/libinkvec_ffi.so "$dest"/ 2>/dev/null || true
cp "$staged"/lib/libinkvec_ffi.dylib "$dest"/ 2>/dev/null || true
rm -rf "$work"
}
unpack c-windows-x64 win32-x86-64
unpack c-linux-x64 linux-x86-64
unpack c-linux-arm64 linux-aarch64
unpack c-macos-arm64 darwin-aarch64
unpack c-macos-x64 darwin-x86-64
find packages/java/src/main/resources -type f
- run: mvn -q -f packages/java/pom.xml -DskipTests package
- uses: actions/upload-artifact@v7
with:
name: java-package
path: packages/java/target/*.jar
if-no-files-found: error
test:
name: test (${{ matrix.os }})
needs: assemble
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- uses: actions/setup-java@v6
with:
distribution: temurin
java-version: "17"
- uses: actions/download-artifact@v8
with:
name: java-package
path: packages/java/target
- name: test against the assembled jar's bundled native library
working-directory: packages/java
shell: bash
# This exercises exactly what a consumer gets: the assembled jar on the classpath
# and JNA's own extraction of the per-platform resource bundled inside it -- no
# jna.library.path anywhere.
#
# The jar is found rather than named: this line used to carry a hard-coded
# `inkvec-0.1.4.jar`, which every version bump turns into a path that does not
# exist.
run: |
set -euo pipefail
shopt -s nullglob
jars=(target/inkvec-[0-9]*.jar)
if [[ ${#jars[@]} -ne 1 ]]; then
echo "::error::expected exactly one assembled jar in packages/java/target, found ${#jars[@]}"
ls -la target || true
exit 1
fi
mvn -q test "-Dinkvec.bundledJar=$PWD/${jars[0]}"