Repository navigation
155 lines (134 loc) · 5.39 KB
/
Copy pathtoolchains.yml
File metadata and controls
155 lines (134 loc) · 5.39 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
147
148
149
150
151
152
153
154
155
name: Maven toolchains no unexpected growth (#534)
# Regression test for #534: invoking setup-java multiple times appended
# malformed / duplicated entries to ~/.m2/toolchains.xml. Each invocation with a
# distinct mvn-toolchain-id must add exactly one <toolchain> entry, keep a single
# <toolchains> root, and remain valid XML.
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
toolchains-growth-baseline:
name: 'BASELINE v5.4.0: toolchains.xml duplicates on re-run - ${{ matrix.os }}'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Set up JDK 21 (toolchain id jdk-21)
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0 (published)
with:
distribution: temurin
java-version: '21'
mvn-toolchain-id: jdk-21
- name: Set up JDK 17 (toolchain id jdk-17)
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0 (published)
with:
distribution: temurin
java-version: '17'
mvn-toolchain-id: jdk-17
- name: Set up JDK 11 (toolchain id jdk-11)
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0 (published)
with:
distribution: temurin
java-version: '11'
mvn-toolchain-id: jdk-11
- name: Re-run JDK 21 (same id jdk-21 - v5.4.0 duplicates it)
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0 (published)
with:
distribution: temurin
java-version: '21'
mvn-toolchain-id: jdk-21
- name: Show and assert the previous (buggy) behavior
shell: bash
run: |
set -euo pipefail
TC="$HOME/.m2/toolchains.xml"
test -f "$TC" || { echo "::error::toolchains.xml not found"; exit 1; }
cat "$TC"
echo "----"
total=$(grep -o "<toolchain>" "$TC" | wc -l | tr -d '[:space:]')
dup21=$(grep -o "<id>jdk-21</id>" "$TC" | wc -l | tr -d '[:space:]')
echo "<toolchain> entries: $total"
echo "jdk-21 occurrences: $dup21"
# v5.4.0 has no de-duplication, so the re-run of jdk-21 leaves it duplicated.
if [ "$dup21" -lt 2 ]; then
echo "::error::expected v5.4.0 to duplicate jdk-21 (>=2), got $dup21"
exit 1
fi
echo "OK (baseline): v5.4.0 duplicated jdk-21 (${dup21}x) - this is the bug fixed by #534"
toolchains-growth:
name: 'CURRENT: toolchains.xml stays consistent - ${{ matrix.os }}'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Set up JDK 21 (toolchain id jdk-21)
uses: actions/setup-java@0f481fcb613427c0f801b606911222b5b6f3083a # v5.5.0
with:
distribution: temurin
java-version: '21'
mvn-toolchain-id: jdk-21
- name: Set up JDK 17 (toolchain id jdk-17)
uses: actions/setup-java@0f481fcb613427c0f801b606911222b5b6f3083a # v5.5.0
with:
distribution: temurin
java-version: '17'
mvn-toolchain-id: jdk-17
- name: Set up JDK 11 (toolchain id jdk-11)
uses: actions/setup-java@0f481fcb613427c0f801b606911222b5b6f3083a # v5.5.0
with:
distribution: temurin
java-version: '11'
mvn-toolchain-id: jdk-11
- name: Re-run JDK 21 (same id jdk-21 must not duplicate)
uses: actions/setup-java@0f481fcb613427c0f801b606911222b5b6f3083a # v5.5.0
with:
distribution: temurin
java-version: '21'
mvn-toolchain-id: jdk-21
- name: Inspect and validate toolchains.xml
shell: bash
run: |
set -euo pipefail
TC="$HOME/.m2/toolchains.xml"
echo "Reading $TC"
test -f "$TC" || { echo "::error::toolchains.xml not found"; exit 1; }
cat "$TC"
echo "----"
count_tag() { grep -o "$1" "$TC" | wc -l | tr -d '[:space:]'; }
OPEN_ROOT=$(count_tag "<toolchains")
TOOLCHAINS=$(count_tag "<toolchain>")
echo "root <toolchains> occurrences: $OPEN_ROOT"
echo "<toolchain> entries: $TOOLCHAINS"
# Exactly one root element.
if [ "$OPEN_ROOT" -ne 1 ]; then
echo "::error::expected exactly 1 <toolchains> root, got $OPEN_ROOT"
exit 1
fi
# 3 distinct ids were used (jdk-21 twice must collapse) -> expect 3 entries.
if [ "$TOOLCHAINS" -ne 3 ]; then
echo "::error::expected 3 <toolchain> entries, got $TOOLCHAINS (unexpected growth/duplication)"
exit 1
fi
# Each id appears exactly once.
for id in jdk-21 jdk-17 jdk-11; do
n=$(grep -o "<id>$id</id>" "$TC" | wc -l | tr -d '[:space:]')
echo "id $id count: $n"
if [ "$n" -ne 1 ]; then
echo "::error::id $id appears $n times, expected 1"
exit 1
fi
done
# Well-formedness check when xmllint is available.
if command -v xmllint >/dev/null 2>&1; then
xmllint --noout "$TC"
echo "xmllint: well-formed"
fi
echo "OK: toolchains.xml is consistent"