Skip to content

Commit c0705b1

Browse files
committed
Add GitHub Actions workflow for running tests
Introduces a new workflow file to automate running tests on pull requests and manual triggers. The workflow sets up Python and Poetry, installs dependencies, and executes pytest, with additional jobs for documentation and QA reporting commented out for future use.
1 parent eafed3c commit c0705b1

File tree

1 file changed

+300
-0
lines changed

1 file changed

+300
-0
lines changed

.github/workflows/tests.yml

Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
name: Run tests workflow
2+
3+
on:
4+
# Trigger on pushes to main branch
5+
pull_request:
6+
types: [opened, synchronize, reopened, ready_for_review]
7+
8+
9+
# Allow manual trigger
10+
workflow_dispatch:
11+
inputs:
12+
run-tests:
13+
description: "Run tests before generating documentation"
14+
required: true
15+
default: "true"
16+
17+
env:
18+
PYTHON_VERSION: "3.9"
19+
NODE_VERSION: "16"
20+
21+
jobs:
22+
23+
# Job 0: Run Tests
24+
run-tests:
25+
if: github.event.pull_request && github.event.pull_request.draft == false
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
with:
31+
path: ${{ github.workspace }}
32+
33+
- name: Set up Python
34+
uses: actions/setup-python@v4
35+
with:
36+
python-version: ${{ env.PYTHON_VERSION }}
37+
38+
- name: Cache Poetry dependencies
39+
uses: actions/cache@v4
40+
with:
41+
path: |
42+
~/.cache/pypoetry
43+
~/.cache/pip
44+
.venv
45+
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
46+
47+
- name: Install Poetry
48+
run: |
49+
python -m pip install --upgrade pip
50+
pip install poetry==1.6.0
51+
poetry config virtualenvs.create false
52+
poetry config virtualenvs.in-project true
53+
working-directory: ${{ github.workspace }}
54+
55+
- name: Install dependencies
56+
run: |
57+
poetry install
58+
working-directory: ${{ github.workspace }}
59+
60+
- name: Install package in editable mode
61+
run: |
62+
poetry run pip install -e .
63+
working-directory: ${{ github.workspace }}
64+
65+
- name: Debug Python import
66+
run: |
67+
poetry run python -c "from nginx_security_monitor.config_manager import ConfigManager; print(ConfigManager)"
68+
working-directory: ${{ github.workspace }}
69+
70+
- name: Run tests
71+
run: |
72+
poetry run pytest --disable-warnings
73+
working-directory: ${{ github.workspace }}
74+
75+
# # Job 1: Generate documentation
76+
# generate-docs:
77+
# runs-on: ubuntu-latest
78+
# steps:
79+
# - name: Checkout repository
80+
# uses: actions/checkout@v4
81+
82+
# - name: Set up Python
83+
# uses: actions/setup-python@v4
84+
# with:
85+
# python-version: ${{ env.PYTHON_VERSION }}
86+
# - name: Install Poetry
87+
# run: |
88+
# python -m pip install --upgrade pip
89+
# pip install poetry==1.6.0
90+
# poetry config virtualenvs.create false
91+
# poetry config virtualenvs.in-project true
92+
93+
# - name: Generate API documentation
94+
# run: |
95+
# echo "Current directory: $(pwd)" && \
96+
# echo "files" && echo $(ls -1) && \
97+
# ./bin/generate-docs --config docs/docgen-config.yaml --api-docs
98+
99+
# - name: Upload API Documentation
100+
# uses: actions/upload-artifact@v4
101+
# with:
102+
# name: api-documentation
103+
# path: .
104+
# retention-days: 7
105+
106+
# - name: Upload Documentation Metrics
107+
# uses: actions/upload-artifact@v4
108+
# with:
109+
# name: documentation-metrics
110+
# path: docs/metrics-report.json
111+
# retention-days: 7
112+
113+
# - name: Upload Documentation Site
114+
# uses: actions/upload-artifact@v4
115+
# with:
116+
# name: documentation-site
117+
# path: site/
118+
# retention-days: 7
119+
120+
# # Job 2: Quality assurance and reporting
121+
# qa-report:
122+
# runs-on: ubuntu-latest
123+
# needs: [generate-docs]
124+
# if: success()
125+
126+
# steps:
127+
# - name: Checkout repository
128+
# uses: actions/checkout@v4
129+
130+
# - name: Download metrics
131+
# uses: actions/download-artifact@v4
132+
# with:
133+
# name: documentation-metrics
134+
# path: docs/
135+
# continue-on-error: true
136+
137+
# - name: Generate QA report
138+
# run: |
139+
# cat > qa-report.md << 'EOF'
140+
# # Documentation Quality Assurance Report
141+
142+
# **Generated**: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
143+
# **Workflow**: ${{ github.workflow }}
144+
# **Run**: ${{ github.run_number }}
145+
146+
# ## Summary
147+
148+
# - **Repository**: ${{ github.repository }}
149+
# - **Branch**: ${{ github.ref_name }}
150+
# - **Commit**: ${{ github.sha }}
151+
# - **Trigger**: ${{ github.event_name }}
152+
153+
# ## Documentation Metrics
154+
155+
# EOF
156+
157+
# if [ -f "docs/metrics-report.json" ]; then
158+
# echo "### Generated Metrics" >> qa-report.md
159+
# python3 << 'PYTHON'
160+
# import json
161+
162+
# try:
163+
# with open('docs/metrics-report.json', 'r') as f:
164+
# metrics = json.load(f)
165+
166+
# print("| Metric | Value |")
167+
# print("|--------|-------|")
168+
169+
# for key, value in metrics.items():
170+
# if isinstance(value, dict):
171+
# for subkey, subvalue in value.items():
172+
# print(f"| {key}.{subkey} | {subvalue} |")
173+
# else:
174+
# print(f"| {key} | {value} |")
175+
# except:
176+
# print("Could not parse metrics file")
177+
# PYTHON
178+
# fi >> qa-report.md
179+
180+
# echo "" >> qa-report.md
181+
# echo "## Next Steps" >> qa-report.md
182+
# echo "" >> qa-report.md
183+
# echo "- Review any failed quality checks above" >> qa-report.md
184+
# echo "- Check the uploaded documentation artifacts" >> qa-report.md
185+
# echo "- Visit the deployed documentation site" >> qa-report.md
186+
187+
# - name: Upload QA report
188+
# uses: actions/upload-artifact@v4
189+
# with:
190+
# name: qa-report
191+
# path: qa-report.md
192+
# retention-days: 7
193+
194+
# - name: Comment on PR (if applicable)
195+
# if: github.event_name == 'pull_request'
196+
# uses: actions/github-script@v6
197+
# with:
198+
# script: |
199+
# const fs = require('fs');
200+
201+
# try {
202+
# const qaReport = fs.readFileSync('qa-report.md', 'utf8');
203+
204+
# github.rest.issues.createComment({
205+
# issue_number: context.issue.number,
206+
# owner: context.repo.owner,
207+
# repo: context.repo.repo,
208+
# body: `## 📚 Documentation Quality Report\n\n${qaReport}\n\n*This report was automatically generated by the documentation workflow.*`
209+
# });
210+
# } catch (error) {
211+
# console.log('Could not post QA report:', error);
212+
# }
213+
214+
# # Job 3: Update documentation in repository
215+
# update-docs:
216+
# runs-on: ubuntu-latest
217+
# needs: [qa-report]
218+
219+
# steps:
220+
# - name: Checkout repository
221+
# uses: actions/checkout@v4
222+
# with:
223+
# token: ${{ secrets.GITHUB_TOKEN }}
224+
225+
# - name: Set up Python
226+
# uses: actions/setup-python@v4
227+
# with:
228+
# python-version: ${{ env.PYTHON_VERSION }}
229+
230+
# # - name: Install dependencies
231+
# # run: |
232+
# # python -m pip install --upgrade pip
233+
# # pip install pyyaml requests
234+
235+
# - name: Download API documentation
236+
# uses: actions/download-artifact@v4
237+
# with:
238+
# name: api-documentation
239+
# path: docs/api/
240+
241+
# - name: Download metrics
242+
# uses: actions/download-artifact@v4
243+
# with:
244+
# name: documentation-metrics
245+
# path: docs/
246+
247+
# - name: Check for changes
248+
# id: verify-changes
249+
# run: |
250+
# git config --local user.email "action@github.com"
251+
# git config --local user.name "GitHub Action"
252+
253+
# if git diff --quiet; then
254+
# echo "changes=false" >> $GITHUB_OUTPUT
255+
# else
256+
# echo "changes=true" >> $GITHUB_OUTPUT
257+
# fi
258+
259+
# - name: Commit documentation updates
260+
# if: steps.verify-changes.outputs.changes == 'true'
261+
# run: |
262+
# git add docs/
263+
# git add README.md
264+
# git commit -m "docs: automated documentation update [skip ci]" || exit 0
265+
# git push
266+
267+
# # Job 4: Deploy documentation site
268+
# deploy-docs:
269+
# runs-on: ubuntu-latest
270+
# needs: [update-docs]
271+
272+
# permissions:
273+
# contents: read
274+
# pages: write
275+
# id-token: write
276+
277+
# steps:
278+
# - name: Checkout repository
279+
# uses: actions/checkout@v4
280+
281+
# - name: Download documentation site
282+
# uses: actions/download-artifact@v4
283+
# with:
284+
# name: documentation-site
285+
# path: site/
286+
287+
# - name: Setup Pages
288+
# uses: actions/configure-pages@v3
289+
290+
# - name: Upload to GitHub Pages
291+
# uses: actions/upload-pages-artifact@v3
292+
# with:
293+
# path: site/
294+
295+
# - name: Deploy to GitHub Pages
296+
# id: deployment
297+
# uses: actions/deploy-pages@v2
298+
# with:
299+
# branch: gh-pages
300+
# folder: docs

0 commit comments

Comments
 (0)