Skip to content

Commit cdde1c0

Browse files
committed
ci: modify module extraction
- Replace xmllint call with script step to extract modules using Node script
1 parent fcea902 commit cdde1c0

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

.github/workflows/classroom-autograding.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,34 @@ jobs:
3838
java-version: '21'
3939
cache: maven
4040

41+
- uses: actions/setup-node@v3
42+
with:
43+
node-version: '20'
44+
- run: npm install xml2js
45+
46+
- name: Extract modules from pom.xml
47+
id: extract-modules
48+
uses: actions/github-script@v7
49+
with:
50+
script: |
51+
const fs = require('fs');
52+
const xml2js = require('xml2js');
53+
54+
const pomXml = fs.readFileSync('${{ env.STUDENT_REPO_PATH }}/pom.xml', 'utf8');
55+
const parser = new xml2js.Parser();
56+
const result = await parser.parseStringPromise(pomXml);
57+
const modules = result.project.modules[0].module || [];
58+
59+
core.setOutput('modules', modules.join(' '));
60+
61+
return modules.join(' ');
62+
4163
- name: Run tests
4264
id: test
4365
run: |
4466
cd ${{ env.STUDENT_REPO_PATH }}
4567
chmod +x mvnw
46-
# Extract module names from pom.xml
47-
MODULES=$(xmllint --xpath "//modules/module/text()" pom.xml)
48-
for dir in $MODULES; do
68+
for dir in ${{ steps.extract-modules.outputs.modules }}; do
4969
if [ -d "$dir" ]; then
5070
echo "Running tests for $dir..."
5171
./mvnw test -B --projects $dir || true

0 commit comments

Comments
 (0)