forked from codenameone/CodenameOne
-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (69 loc) · 2.46 KB
/
java-snippet-validation.yml
File metadata and controls
79 lines (69 loc) · 2.46 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
name: Java snippet validation
permissions:
contents: read
on:
pull_request:
paths:
- 'scripts/extract-javadoc-java-snippets.sh'
- 'scripts/java-snippet-to-playground-uri.sh'
- 'scripts/validate-extracted-javadoc-snippets.sh'
- 'scripts/java-snippet-validation-exclusions.jsonl'
- '.github/workflows/java-snippet-validation.yml'
jobs:
validate-snippets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Ensure workflow runs only for script-only changes
id: changes
shell: bash
run: |
set -euo pipefail
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
base="${{ github.event.pull_request.base.sha }}"
head="${{ github.event.pull_request.head.sha }}"
else
base="${{ github.event.before }}"
head="${{ github.sha }}"
fi
mapfile -t changed < <(git diff --name-only "$base" "$head")
if [[ ${#changed[@]} -eq 0 ]]; then
echo "run=true" >> "$GITHUB_OUTPUT"
exit 0
fi
allowed=(
"scripts/extract-javadoc-java-snippets.sh"
"scripts/java-snippet-to-playground-uri.sh"
"scripts/validate-extracted-javadoc-snippets.sh"
"scripts/java-snippet-validation-exclusions.jsonl"
".github/workflows/java-snippet-validation.yml"
)
only_allowed=true
for file in "${changed[@]}"; do
ok=false
for allow in "${allowed[@]}"; do
if [[ "$file" == "$allow" ]]; then
ok=true
break
fi
done
if [[ "$ok" == false ]]; then
only_allowed=false
break
fi
done
echo "Changed files:"; printf ' - %s\n' "${changed[@]}"
echo "run=$only_allowed" >> "$GITHUB_OUTPUT"
- name: Skip because non-script files changed
if: steps.changes.outputs.run != 'true'
run: echo "Skipping snippet validation because additional files changed."
- name: Validate extracted Java snippets
if: steps.changes.outputs.run == 'true'
shell: bash
run: |
set -euo pipefail
tmp_jsonl="$(mktemp)"
scripts/extract-javadoc-java-snippets.sh CodenameOne/src > "$tmp_jsonl"
scripts/validate-extracted-javadoc-snippets.sh "$tmp_jsonl"