-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (80 loc) · 2.88 KB
/
test-java.yml
File metadata and controls
87 lines (80 loc) · 2.88 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
name: Test Java Frameworks
on:
push:
branches: [main]
# No paths filter on pull_request — required status checks need this workflow to
# always trigger so the aggregator can report. find-projects below narrows the
# matrix to only projects whose subtree changed, so docs-only / other-framework
# PRs produce an empty matrix → test job skipped → aggregator passes via
# `result == 'skipped'`.
pull_request:
schedule:
- cron: "0 8 * * 1"
workflow_dispatch:
permissions:
contents: read
# Needed by find-projects' `gh api .../pulls/N/files` call.
pull-requests: read
jobs:
find-projects:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.find.outputs.matrix }}
steps:
- uses: actions/checkout@v6
# Default shallow checkout — we only need the working tree for `find`
# below, not git history. The PR's changed files come from gh api.
- id: find
env:
EVENT_NAME: ${{ github.event_name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
WORKFLOW_FILE: .github/workflows/test-java.yml
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
ALL=$(find samples -name "pom.xml" -not -path "*/target/*" -not -path "*/node_modules/*" -exec dirname {} \; 2>/dev/null | sort)
if [ "$EVENT_NAME" = "pull_request" ]; then
CHANGED=$(gh api --paginate "/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/files" --jq '.[].filename' 2>/dev/null || echo "")
if printf '%s\n' "$CHANGED" | grep -qFx "$WORKFLOW_FILE"; then
FILTERED="$ALL"
else
FILTERED=$(while IFS= read -r proj; do
[ -z "$proj" ] && continue
if printf '%s\n' "$CHANGED" | grep -q "^${proj}/"; then
echo "$proj"
fi
done <<< "$ALL")
fi
else
FILTERED="$ALL"
fi
MATRIX=$(printf '%s\n' "$FILTERED" | jq -R -s -c 'split("\n") | map(select(. != ""))')
echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
test:
needs: find-projects
if: ${{ needs.find-projects.outputs.matrix != '[]' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.find-projects.outputs.matrix) }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-java@v5
with:
distribution: "temurin"
java-version: "21"
cache: "maven"
- name: Build and test
working-directory: ${{ matrix.project }}
run: mvn -B verify
# Stable aggregator for branch protection.
all-tests-passed:
name: Java tests passed
needs: test
if: always()
runs-on: ubuntu-latest
steps:
- name: Verify test matrix succeeded
if: needs.test.result != 'success' && needs.test.result != 'skipped'
run: exit 1