Skip to content

Commit 69d0e4c

Browse files
Claudeilaflott
andauthored
Add IOOS compliance-checker pipeline
- Create compliance_check.yml workflow - Add compliance-checker to environment.yaml - Add compliance_check badge to README.md Agent-Logs-Url: https://github.com/ilaflott/fremorizer/sessions/a24e9cee-7b60-4639-8c0e-1f48f931ff49 Co-authored-by: ilaflott <6273252+ilaflott@users.noreply.github.com>
1 parent d8134cb commit 69d0e4c

File tree

3 files changed

+163
-0
lines changed

3 files changed

+163
-0
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
name: compliance_check
2+
3+
on:
4+
pull_request:
5+
branches:
6+
workflow_dispatch:
7+
8+
# cancel running jobs if theres a newer push
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
compliance-checker:
18+
runs-on: ubuntu-latest
19+
defaults:
20+
run:
21+
shell: bash -l {0}
22+
steps:
23+
- name: Checkout Files
24+
uses: actions/checkout@v4
25+
with:
26+
submodules: recursive
27+
28+
- name: Setup Conda
29+
uses: conda-incubator/setup-miniconda@v3
30+
with:
31+
activate-environment: fremorizer-compliance
32+
python-version: "3.12"
33+
auto-activate-base: false
34+
miniforge-version: latest
35+
channels: conda-forge,noaa-gfdl
36+
37+
- name: Configure Conda
38+
run: |
39+
echo "removing main and r channels from defaults"
40+
conda config --remove channels defaults || true
41+
conda config --remove channels main || true
42+
conda config --remove channels r || true
43+
44+
echo "setting strict channel priority"
45+
conda config --set channel_priority strict
46+
47+
echo "printing conda config just in case"
48+
conda config --show
49+
50+
- name: Install dependencies for fremorizer
51+
run: |
52+
conda install -y \
53+
conda-forge::cftime \
54+
"conda-forge::click>=8.2" \
55+
"conda-forge::cmor>=3.14" \
56+
"conda-forge::netcdf4>=1.7" \
57+
"conda-forge::numpy>=2" \
58+
conda-forge::pyyaml \
59+
conda-forge::pytest
60+
61+
- name: Install compliance-checker
62+
run: |
63+
conda install -y conda-forge::compliance-checker
64+
65+
- name: Install fremorizer
66+
run: |
67+
pip install .
68+
69+
- name: Run tests to generate output files
70+
run: |
71+
pytest fremorizer/tests/test_cmor_run_subtool.py -v
72+
continue-on-error: true
73+
74+
- name: Find generated NetCDF files
75+
id: find_files
76+
run: |
77+
echo "Searching for generated NetCDF files..."
78+
find fremorizer/tests/test_files/outdir -name "*.nc" -type f > /tmp/netcdf_files.txt || true
79+
if [ -s /tmp/netcdf_files.txt ]; then
80+
echo "Found NetCDF files:"
81+
cat /tmp/netcdf_files.txt
82+
echo "file_count=$(wc -l < /tmp/netcdf_files.txt)" >> $GITHUB_OUTPUT
83+
else
84+
echo "No NetCDF files found"
85+
echo "file_count=0" >> $GITHUB_OUTPUT
86+
fi
87+
88+
- name: Run compliance-checker on outputs
89+
if: steps.find_files.outputs.file_count != '0'
90+
run: |
91+
echo "Running IOOS Compliance Checker on generated NetCDF files..."
92+
mkdir -p /tmp/compliance_reports
93+
94+
while IFS= read -r ncfile; do
95+
if [ -f "$ncfile" ]; then
96+
basename=$(basename "$ncfile" .nc)
97+
echo ""
98+
echo "=========================================="
99+
echo "Checking: $ncfile"
100+
echo "=========================================="
101+
102+
# Run compliance checker with CF conventions
103+
# Generate text report (for viewing in logs)
104+
compliance-checker \
105+
--test=cf \
106+
--criteria=normal \
107+
--verbose \
108+
--format=text \
109+
--output=/tmp/compliance_reports/${basename}_report.txt \
110+
"$ncfile" || true
111+
112+
# Also generate HTML report (for artifact download)
113+
compliance-checker \
114+
--test=cf \
115+
--criteria=normal \
116+
--format=html \
117+
--output=/tmp/compliance_reports/${basename}_report.html \
118+
"$ncfile" 2>&1 || true
119+
120+
# Display the text report
121+
cat /tmp/compliance_reports/${basename}_report.txt || true
122+
123+
echo ""
124+
fi
125+
done < /tmp/netcdf_files.txt
126+
127+
echo ""
128+
echo "=========================================="
129+
echo "Compliance checking complete"
130+
echo "=========================================="
131+
132+
- name: Generate summary report
133+
if: steps.find_files.outputs.file_count != '0'
134+
run: |
135+
echo "# IOOS Compliance Checker Results" > /tmp/compliance_reports/SUMMARY.md
136+
echo "" >> /tmp/compliance_reports/SUMMARY.md
137+
echo "Checked ${{ steps.find_files.outputs.file_count }} NetCDF files" >> /tmp/compliance_reports/SUMMARY.md
138+
echo "" >> /tmp/compliance_reports/SUMMARY.md
139+
echo "## Files Checked" >> /tmp/compliance_reports/SUMMARY.md
140+
echo "" >> /tmp/compliance_reports/SUMMARY.md
141+
while IFS= read -r ncfile; do
142+
echo "- \`$ncfile\`" >> /tmp/compliance_reports/SUMMARY.md
143+
done < /tmp/netcdf_files.txt
144+
echo "" >> /tmp/compliance_reports/SUMMARY.md
145+
echo "See individual report files for detailed results." >> /tmp/compliance_reports/SUMMARY.md
146+
147+
cat /tmp/compliance_reports/SUMMARY.md
148+
149+
- name: Upload compliance reports
150+
if: always() && steps.find_files.outputs.file_count != '0'
151+
uses: actions/upload-artifact@v4
152+
with:
153+
name: compliance-checker-reports
154+
path: /tmp/compliance_reports/
155+
retention-days: 30
156+
157+
- name: Check if any files were tested
158+
if: steps.find_files.outputs.file_count == '0'
159+
run: |
160+
echo "::warning::No NetCDF files were found to check for compliance"
161+
echo "This may indicate that tests did not run successfully or outputs were not generated"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![build_conda](https://github.com/ilaflott/fremorizer/actions/workflows/build_conda.yml/badge.svg?branch=main)](https://github.com/ilaflott/fremorizer/actions/workflows/build_conda.yml)
44
[![create_test_conda_env](https://github.com/ilaflott/fremorizer/actions/workflows/create_test_conda_env.yml/badge.svg?branch=main)](https://github.com/ilaflott/fremorizer/actions/workflows/create_test_conda_env.yml)
5+
[![compliance_check](https://github.com/ilaflott/fremorizer/actions/workflows/compliance_check.yml/badge.svg?branch=main)](https://github.com/ilaflott/fremorizer/actions/workflows/compliance_check.yml)
56
[![publish_conda](https://github.com/ilaflott/fremorizer/actions/workflows/publish_conda.yml/badge.svg?branch=main)](https://github.com/ilaflott/fremorizer/actions/workflows/publish_conda.yml)
67
[![pylint](https://github.com/ilaflott/fremorizer/actions/workflows/pylint.yml/badge.svg?branch=main)](https://github.com/ilaflott/fremorizer/actions/workflows/pylint.yml)
78
[![codecov](https://codecov.io/gh/ilaflott/fremorizer/branch/main/graph/badge.svg)](https://codecov.io/gh/ilaflott/fremorizer)

environment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ dependencies:
1313
- conda-forge::pytest
1414
- conda-forge::pytest-cov
1515
- conda-forge::pylint
16+
- conda-forge::compliance-checker

0 commit comments

Comments
 (0)