Skip to content

Commit b2b652b

Browse files
authored
Add repository indexing workflow (#931)
1 parent 8b86b8a commit b2b652b

1 file changed

Lines changed: 293 additions & 0 deletions

File tree

.github/workflows/repos.yaml

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
name: Repository indexing
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
15+
cancel-in-progress: true
16+
17+
env:
18+
NIX_DEVELOP: ${{ github.workspace }}#jdk21
19+
20+
defaults:
21+
run:
22+
shell: bash -eo pipefail -c "nix develop \"$NIX_DEVELOP\" --command bash -eo pipefail \"$1\"" -- {0}
23+
24+
jobs:
25+
build-cli:
26+
runs-on: ubuntu-latest
27+
name: Build scip-java CLI
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- uses: DeterminateSystems/nix-installer-action@v22
32+
with:
33+
summarize: false
34+
35+
- uses: DeterminateSystems/magic-nix-cache-action@v13
36+
37+
- name: Build distribution
38+
run: gradle :scip-java:installDist --no-daemon
39+
40+
- name: Package distribution
41+
run: tar -C scip-java/build/install -czf scip-java-dist.tgz scip-java
42+
43+
- uses: actions/upload-artifact@v4
44+
with:
45+
name: scip-java-dist
46+
path: scip-java-dist.tgz
47+
retention-days: 1
48+
49+
index-repo:
50+
runs-on: ubuntu-latest
51+
needs: build-cli
52+
name: ${{ matrix.name }}
53+
env:
54+
NIX_DEVELOP: ${{ github.workspace }}#jdk${{ matrix.java }}
55+
strategy:
56+
fail-fast: false
57+
matrix:
58+
include:
59+
- name: gradle-java11-pusher
60+
repository: pusher/pusher-http-java
61+
ref: 94f25a2848e5939cf27dafad8ed25aeaa2d83274
62+
directory: .
63+
build_tool: gradle
64+
build_command: ""
65+
java: 11
66+
bazel_version: ""
67+
covers: Gradle, Java project target 11, Java 11 runtime
68+
69+
- name: maven-java17-spring-boot
70+
repository: spring-guides/gs-spring-boot
71+
ref: 2ffad4f418c3052b534184228a45d062f566096f
72+
directory: complete
73+
build_tool: maven
74+
build_command: ""
75+
java: 17
76+
bazel_version: ""
77+
covers: Maven, Java project target 17, Java 17 runtime
78+
79+
- name: maven-java11-wagon-multimodule
80+
repository: apache/maven-wagon
81+
ref: 20b847446bb60f49af0428d592eadee774b5bff2
82+
directory: .
83+
build_tool: maven
84+
build_command: "-DskipTests compile"
85+
java: 11
86+
bazel_version: ""
87+
covers: Maven, multi-module Java, Java 11 runtime
88+
89+
- name: maven-kotlin-json-kotlin-maven
90+
repository: pwall567/json-kotlin-maven
91+
ref: 523f4fd624c3abca4a083c96be596d6f4799b705
92+
directory: .
93+
build_tool: scip
94+
build_command: ""
95+
java: 17
96+
bazel_version: ""
97+
scip_config: maven-kotlin
98+
expected_language: kotlin
99+
covers: Maven Kotlin project, manual SCIP config, Kotlin source, Java 17 runtime
100+
101+
- name: gradle-java21-readiness
102+
repository: ePages-de/spring-boot-readiness
103+
ref: 8a91762e723e5204c69339ebbfc2517a48a8651a
104+
directory: .
105+
build_tool: gradle
106+
build_command: "clean compileJava"
107+
java: 21
108+
bazel_version: ""
109+
covers: Gradle, Java project target 21, Java 21 runtime
110+
111+
- name: gradle-java11-mapstruct-lombok
112+
repository: mapstruct/mapstruct-examples
113+
ref: 3f9fd5ffe9e2272b6219a4216e842f8c009d1005
114+
directory: mapstruct-lombok
115+
build_tool: gradle
116+
build_command: "compileJava"
117+
java: 11
118+
bazel_version: ""
119+
covers: Gradle, Java annotation processors, Lombok, MapStruct, generated sources, Java 11 runtime
120+
121+
- name: gradle-kotlin-okio
122+
repository: square/okio
123+
ref: parent-3.16.0
124+
directory: .
125+
build_tool: gradle
126+
build_command: "-Dkjs=false -Dkwasm=false :okio:compileKotlinJvm"
127+
java: 17
128+
bazel_version: ""
129+
covers: Gradle, Kotlin, Kotlin 2.2.0
130+
131+
- name: gradle-kotlin-flowext
132+
repository: hoc081098/FlowExt
133+
ref: 7341f3853d670af0283258f57643a68ed273f8ac
134+
directory: .
135+
build_tool: gradle
136+
build_command: "compileKotlinJvm"
137+
java: 17
138+
bazel_version: ""
139+
expected_language: kotlin
140+
covers: Gradle, Kotlin multiplatform JVM target, Kotlin 2.2.0, Java 17 runtime
141+
142+
- name: gradle-mixed-okio-jmh
143+
repository: square/okio
144+
ref: parent-3.16.0
145+
directory: .
146+
build_tool: gradle
147+
build_command: "-Dkjs=false -Dkwasm=false :okio:jvm:jmh:jmhClasses"
148+
java: 21
149+
bazel_version: ""
150+
covers: Gradle, mixed Java/Kotlin, Java 21 runtime
151+
152+
- name: bazel-java-examples
153+
repository: bazelbuild/examples
154+
ref: dbf3399037ae65f901d46147804749fae1409ef2
155+
directory: java-tutorial
156+
build_tool: bazel
157+
build_command: "//:ProjectRunner"
158+
java: 21
159+
bazel_version: 7.6.1
160+
covers: Bazel, Java, Java 21 runtime
161+
steps:
162+
- uses: actions/checkout@v4
163+
164+
- uses: DeterminateSystems/nix-installer-action@v22
165+
with:
166+
summarize: false
167+
168+
- uses: DeterminateSystems/magic-nix-cache-action@v13
169+
170+
- uses: actions/download-artifact@v4
171+
with:
172+
name: scip-java-dist
173+
path: scip-java-dist
174+
175+
- name: Install scip-java CLI
176+
run: |
177+
mkdir -p "$RUNNER_TEMP/scip-java"
178+
tar -xzf scip-java-dist/scip-java-dist.tgz -C "$RUNNER_TEMP/scip-java"
179+
cli="$RUNNER_TEMP/scip-java/scip-java/bin/scip-java"
180+
chmod +x "$cli"
181+
"$cli" --help >/dev/null
182+
printf 'SCIP_JAVA_CLI=%s\n' "$cli" >> "$GITHUB_ENV"
183+
184+
- name: Clone repository
185+
env:
186+
REPOSITORY: ${{ matrix.repository }}
187+
REF: ${{ matrix.ref }}
188+
DIRECTORY: ${{ matrix.directory }}
189+
COVERS: ${{ matrix.covers }}
190+
run: |
191+
repo_dir="$RUNNER_TEMP/repos/${REPOSITORY//\//-}"
192+
mkdir -p "$(dirname "$repo_dir")"
193+
git init "$repo_dir"
194+
git -C "$repo_dir" remote add origin "https://github.com/$REPOSITORY.git"
195+
git -C "$repo_dir" fetch --depth=1 origin "$REF"
196+
git -C "$repo_dir" checkout --detach FETCH_HEAD
197+
git -C "$repo_dir" submodule update --init --recursive --depth 1
198+
199+
find "$repo_dir" -maxdepth 3 \( -name gradlew -o -name mvnw \) -type f -exec chmod +x {} +
200+
201+
workdir="$repo_dir/$DIRECTORY"
202+
test -d "$workdir"
203+
204+
echo "Covers: $COVERS"
205+
git -C "$repo_dir" rev-parse HEAD
206+
printf 'REPO_WORKDIR=%s\n' "$workdir" >> "$GITHUB_ENV"
207+
208+
- name: Run scip-java index
209+
env:
210+
BUILD_TOOL: ${{ matrix.build_tool }}
211+
BUILD_COMMAND: ${{ matrix.build_command }}
212+
BAZEL_VERSION: ${{ matrix.bazel_version }}
213+
SCIP_CONFIG: ${{ matrix.scip_config }}
214+
run: |
215+
cd "$REPO_WORKDIR"
216+
217+
if [[ "$SCIP_CONFIG" == "maven-kotlin" ]]; then
218+
mkdir -p target
219+
mvn --batch-mode -q dependency:build-classpath -Dmdep.outputFile=target/scip-java-classpath.txt
220+
jq -Rn '
221+
input
222+
| split(":")
223+
| map(select(length > 0))
224+
| {
225+
sourceFiles: ["src/main/kotlin"],
226+
classpath: .,
227+
javacOptions: ["-source", "1.8", "-target", "1.8"]
228+
}
229+
' < target/scip-java-classpath.txt > scip-java.json
230+
fi
231+
232+
index_args=(--build-tool="$BUILD_TOOL")
233+
if [[ "$BUILD_TOOL" == "bazel" ]]; then
234+
index_args+=(--bazel-scip-java-binary="$SCIP_JAVA_CLI" --bazel-overwrite-aspect-file)
235+
fi
236+
237+
if [[ -n "$BAZEL_VERSION" ]]; then
238+
export USE_BAZEL_VERSION="$BAZEL_VERSION"
239+
fi
240+
241+
if [[ -n "$BUILD_COMMAND" ]]; then
242+
# shellcheck disable=SC2206
243+
build_command=($BUILD_COMMAND)
244+
"$SCIP_JAVA_CLI" index "${index_args[@]}" -- "${build_command[@]}"
245+
else
246+
"$SCIP_JAVA_CLI" index "${index_args[@]}"
247+
fi
248+
249+
- name: Validate SCIP index data
250+
env:
251+
EXPECTED_LANGUAGE: ${{ matrix.expected_language }}
252+
run: |
253+
cd "$REPO_WORKDIR"
254+
255+
test -s index.scip
256+
du -h index.scip
257+
scip stats --from index.scip | tee index.stats.json
258+
259+
documents="$(jq -r '.documents' index.stats.json)"
260+
occurrences="$(jq -r '.occurrences' index.stats.json)"
261+
definitions="$(jq -r '.definitions' index.stats.json)"
262+
263+
if (( documents < 1 || occurrences < 1 || definitions < 1 )); then
264+
echo "SCIP index did not contain enough generated data: documents=$documents occurrences=$occurrences definitions=$definitions" >&2
265+
exit 1
266+
fi
267+
268+
scip print --json index.scip > index.print.json
269+
270+
source_documents=0
271+
while IFS= read -r path; do
272+
if [[ -f "$path" ]]; then
273+
source_documents=$((source_documents + 1))
274+
fi
275+
done < <(
276+
jq -r --arg expected_language "$EXPECTED_LANGUAGE" '
277+
.documents[]?
278+
| select((if $expected_language == "" then (.language == "java" or .language == "kotlin") else .language == $expected_language end)
279+
and ((.relative_path // .relativePath // "") | test(if $expected_language == "kotlin" then "\\.kt$" elif $expected_language == "java" then "\\.java$" else "\\.(java|kt)$" end))
280+
and ((.occurrences // []) | length > 0)
281+
and ((.symbols // []) | length > 0))
282+
| .relative_path // .relativePath
283+
' index.print.json
284+
)
285+
286+
if (( source_documents < 1 )); then
287+
if [[ -n "$EXPECTED_LANGUAGE" ]]; then
288+
echo "SCIP index did not contain any checked-out $EXPECTED_LANGUAGE source documents with occurrences and symbols" >&2
289+
else
290+
echo "SCIP index did not contain any checked-out Java/Kotlin source documents with occurrences and symbols" >&2
291+
fi
292+
exit 1
293+
fi

0 commit comments

Comments
 (0)