Skip to content

Commit 9f8dce8

Browse files
lassoanjcfr
authored andcommitted
ENH: Add more automatic tests
Move filename checks from bash script executed by CircleCI to Python script executed by GitHub actions for consistency and to be able to run on Windows. Moved the unstable pre-commit json file schema check to the other extension validation checks. Added tests: - check that the extension description file name matches the project name in the CMakeLists.txt file - check that the extension can be git cloned - check that a license file can be found in the extension's repository - check that extension category is in the allowed list - check that the extension icon and screenshot URLs are valid image files Show repository URL, CMakeLists.txt, license file in a report in the pull request. This makes quick review of extension submissions a bit easier.
1 parent 86803a9 commit 9f8dce8

File tree

8 files changed

+750
-148
lines changed

8 files changed

+750
-148
lines changed

.circleci/config.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
name: Extension Validation
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- 5.*
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
validate-extensions:
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 30
18+
steps:
19+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20+
with:
21+
fetch-depth: 0 # Fetch full history for git diff
22+
23+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
24+
with:
25+
python-version: "3.12"
26+
27+
- name: Configure git
28+
run: |
29+
git config --global user.email "[email protected]"
30+
git config --global user.name "GitHub Action"
31+
32+
- name: Install dependencies
33+
run: |
34+
python -m pip install --upgrade pip
35+
echo "Installing dependencies from requirements.txt:"
36+
cat scripts/requirements.txt
37+
pip install -r scripts/requirements.txt
38+
echo "Verifying installed packages:"
39+
pip list | grep -E "(jsonschema|requests)"
40+
41+
- name: Run repository structure validation
42+
id: structure-validation
43+
continue-on-error: true
44+
run: |
45+
mkdir -p /tmp/validation-reports
46+
python scripts/check_repository_structure.py \
47+
> /tmp/validation-reports/repository-structure-report.md
48+
49+
- name: Get changed files
50+
run: |
51+
echo "Event: ${{ github.event_name }}"
52+
mkdir -p /tmp/validation-reports
53+
if [ "${{ github.event_name }}" = "pull_request" ]; then
54+
# For pull requests, compare against the base branch
55+
BASE_REF="${{ github.event.pull_request.base.ref }}"
56+
echo "Base ref: $BASE_REF"
57+
git diff --name-only "origin/$BASE_REF"...HEAD > /tmp/validation-reports/changed_files.txt 2>/dev/null
58+
else
59+
# For pushes, compare against the previous commit or get all JSON files if it's the first commit
60+
git diff --name-only HEAD~1 HEAD > /tmp/validation-reports/changed_files.txt 2>/dev/null
61+
fi
62+
echo "Changed JSON files:"
63+
cat /tmp/validation-reports/changed_files.txt
64+
65+
- name: Run extension validation
66+
id: extension-validation
67+
continue-on-error: true
68+
run: |
69+
mkdir -p /tmp/validation-reports
70+
python scripts/check_description_files.py \
71+
$(cat /tmp/validation-reports/changed_files.txt | tr '\n' ' ') \
72+
> /tmp/validation-reports/extension-validation-report.md
73+
74+
- name: Combine validation reports and display summary
75+
if: always()
76+
run: |
77+
mkdir -p /tmp/validation-reports
78+
if [ -f /tmp/validation-reports/repository-structure-report.md ]; then
79+
cat /tmp/validation-reports/repository-structure-report.md >> /tmp/validation-reports/validation-report.md
80+
else
81+
echo "❌ Repository structure validation report not generated" >> /tmp/validation-reports/validation-report.md
82+
fi
83+
echo "" >> /tmp/validation-reports/validation-report.md
84+
if [ -f /tmp/validation-reports/extension-validation-report.md ]; then
85+
cat /tmp/validation-reports/extension-validation-report.md >> /tmp/validation-reports/validation-report.md
86+
else
87+
echo "❌ Extension validation report not generated" >> /tmp/validation-reports/validation-report.md
88+
fi
89+
if [ -f /tmp/validation-reports/validation-report.md ]; then
90+
cat /tmp/validation-reports/validation-report.md >> $GITHUB_STEP_SUMMARY
91+
else
92+
echo "❌ Validation report not generated" >> $GITHUB_STEP_SUMMARY
93+
fi
94+
95+
- name: Upload validation reports
96+
if: always()
97+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
98+
with:
99+
name: validation-reports
100+
path: |
101+
/tmp/validation-reports/validation-report.md
102+
/tmp/validation-reports/repository-structure-report.md
103+
/tmp/validation-reports/extension-validation-report.md
104+
/tmp/validation-reports/changed_files.txt
105+
retention-days: 30
106+
107+
- name: Comment PR with report
108+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && always()
109+
uses: actions/github-script@e69ef5462fd455e02edcaf4dd7708eda96b9eda0 # v7.0.1
110+
with:
111+
script: |
112+
const fs = require('fs');
113+
114+
// Check if validation report exists
115+
if (!fs.existsSync('/tmp/validation-reports/validation-report.md')) {
116+
console.log('Validation report not found');
117+
return;
118+
}
119+
120+
const report = fs.readFileSync('/tmp/validation-reports/validation-report.md', 'utf8');
121+
122+
// Find existing comment using the HTML comment marker
123+
const { data: comments } = await github.rest.issues.listComments({
124+
owner: context.repo.owner,
125+
repo: context.repo.repo,
126+
issue_number: context.issue.number,
127+
});
128+
129+
const botComment = comments.find(comment =>
130+
comment.body.includes('<!-- extension-validation-report -->')
131+
);
132+
133+
const commentBody = '<!-- extension-validation-report -->\n' +
134+
'# Extension Validation Report\n\n' +
135+
report + '\n\n' +
136+
'***\n' +
137+
'*This report was automatically generated by the Extension Validation workflow and it is updated automatically when files are modified.*';
138+
139+
if (botComment) {
140+
console.log('Updating existing comment with ID:', botComment.id);
141+
// Update existing comment
142+
await github.rest.issues.updateComment({
143+
owner: context.repo.owner,
144+
repo: context.repo.repo,
145+
comment_id: botComment.id,
146+
body: commentBody
147+
});
148+
} else {
149+
console.log('Creating new comment');
150+
// Create new comment
151+
await github.rest.issues.createComment({
152+
owner: context.repo.owner,
153+
repo: context.repo.repo,
154+
issue_number: context.issue.number,
155+
body: commentBody
156+
});
157+
}
158+
159+
- name: Check validation results
160+
if: always()
161+
run: |
162+
echo "Checking validation results..."
163+
STRUCTURE_RESULT="${{ steps.structure-validation.outcome }}"
164+
EXTENSION_RESULT="${{ steps.extension-validation.outcome }}"
165+
166+
echo "Repository structure validation: $STRUCTURE_RESULT"
167+
echo "Extension validation: $EXTENSION_RESULT"
168+
169+
if [ "$STRUCTURE_RESULT" != "success" ] || [ "$EXTENSION_RESULT" != "success" ]; then
170+
echo "❌ One or more validation steps failed"
171+
exit 1
172+
else
173+
echo "✅ All validation steps passed"
174+
fi

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ jobs:
1919
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2020
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
2121
with:
22-
python-version: "3.9"
22+
python-version: "3.12"
2323
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1

.pre-commit-config.yaml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,3 @@ repos:
2727
hooks:
2828
- id: forbid-tabs
2929
- id: remove-tabs
30-
31-
- repo: https://github.com/python-jsonschema/check-jsonschema
32-
rev: "0.33.0"
33-
hooks:
34-
- id: check-jsonschema
35-
files: ^[^/]*\.json$
36-
args:
37-
[
38-
"--schemafile",
39-
"https://raw.githubusercontent.com/Slicer/Slicer/main/Schemas/slicer-extension-catalog-entry-schema-v1.0.1.json",
40-
]
41-
- id: check-dependabot
42-
- id: check-github-workflows

0 commit comments

Comments
 (0)