Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 51 additions & 9 deletions .github/actions/check-warnings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the

- Scans HTML files for configurable Python warnings **within code cell outputs only**
- Prevents false positives by only checking warnings in `cell_output` HTML elements
- Supports multiple warning types (SyntaxWarning, DeprecationWarning, FutureWarning)
- Supports multiple warning types (all Python warning types by default: UserWarning, DeprecationWarning, PendingDeprecationWarning, SyntaxWarning, RuntimeWarning, FutureWarning, ImportWarning, UnicodeWarning, BytesWarning, ResourceWarning, EncodingWarning)
- Provides detailed output about warnings found
- Optionally fails the workflow when warnings are detected
- **Creates GitHub issues** with detailed warning reports
Expand All @@ -32,7 +32,7 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning'
# Uses comprehensive default warnings (all Python warning types)
fail-on-warning: 'true' # This will post a comment to the PR if warnings are found
```

Expand All @@ -43,7 +43,7 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning,UserWarning'
# Uses comprehensive default warnings (all Python warning types)
fail-on-warning: 'false'
create-issue: 'true'
issue-title: 'Python Warnings Found in Documentation Build'
Expand All @@ -56,7 +56,7 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning'
# Uses comprehensive default warnings (all Python warning types)
fail-on-warning: 'false'
create-issue: 'true'
issue-title: 'Python Warnings Found in Documentation Build'
Expand All @@ -70,7 +70,7 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning'
# Uses comprehensive default warnings (all Python warning types)
fail-on-warning: 'true'
create-artifact: 'true'
artifact-name: 'python-warning-report'
Expand All @@ -83,7 +83,7 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning,UserWarning'
# Uses comprehensive default warnings (all Python warning types)
fail-on-warning: 'false'
create-issue: 'true'
issue-title: 'Python Warnings Detected in Build'
Expand All @@ -92,6 +92,42 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the
artifact-name: 'detailed-warning-report'
```

### Excluding Specific Warning Types

Sometimes you may want to temporarily exclude certain warning types (e.g., when dealing with upstream warnings that take time to fix):

```yaml
- name: Check for Python warnings excluding upstream warnings
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
exclude-warning: 'UserWarning' # Exclude single warning type
fail-on-warning: 'true'
```

```yaml
- name: Check for Python warnings excluding multiple warning types
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
exclude-warning: 'UserWarning,RuntimeWarning,ResourceWarning' # Exclude multiple warnings
fail-on-warning: 'true'
```

### Custom Warning Types with Exclusions

You can combine custom warning lists with exclusions:

```yaml
- name: Check for specific warnings but exclude problematic ones
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
warnings: 'UserWarning,DeprecationWarning,RuntimeWarning,ResourceWarning'
exclude-warning: 'ResourceWarning' # Check all above except ResourceWarning
fail-on-warning: 'true'
```

### Using Outputs

```yaml
Expand Down Expand Up @@ -215,7 +251,8 @@ If you're only using the basic warning check functionality, only `contents: read
| Input | Description | Required | Default |
|-------|-------------|----------|---------|
| `html-path` | Path to directory containing HTML files to scan | No | `.` |
| `warnings` | Comma-separated list of warnings to check for | No | `SyntaxWarning,DeprecationWarning,FutureWarning` |
| `warnings` | Comma-separated list of warnings to check for | No | `UserWarning,DeprecationWarning,PendingDeprecationWarning,SyntaxWarning,RuntimeWarning,FutureWarning,ImportWarning,UnicodeWarning,BytesWarning,ResourceWarning,EncodingWarning` |
| `exclude-warning` | Comma-separated list of warnings to exclude from checking (can be a single warning or multiple warnings) | No | `` |
| `fail-on-warning` | Whether to fail the workflow if warnings are found | No | `true` |
| `create-issue` | Whether to create a GitHub issue when warnings are found | No | `false` |
| `issue-title` | Title for the GitHub issue when warnings are found | No | `Python Warnings Found in Documentation Build` |
Expand Down Expand Up @@ -276,7 +313,7 @@ jobs:
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning'
# Uses comprehensive default warnings (all Python warning types)
fail-on-warning: ${{ github.event_name == 'push' }} # Fail on push, warn on PR
create-issue: ${{ github.event_name == 'push' }} # Create issues for main branch
notify: 'maintainer1,reviewer2' # Assign issues to team members
Expand Down Expand Up @@ -313,7 +350,12 @@ This action is particularly useful for:

3. **Customize warning types**: Adjust the `warnings` input to match your project's needs.

4. **Path considerations**: Make sure the `html-path` points to where your build process outputs HTML files.
4. **Exclude problematic warnings temporarily**: Use `exclude-warning` to temporarily exclude warnings from upstream dependencies or issues that take time to fix:
```yaml
exclude-warning: 'UserWarning,RuntimeWarning' # Exclude multiple warnings
```

5. **Path considerations**: Make sure the `html-path` points to where your build process outputs HTML files.

5. **Integration with existing workflows**: This action can be easily added to existing CI/CD pipelines.

Expand Down
53 changes: 52 additions & 1 deletion .github/actions/check-warnings/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ inputs:
warnings:
description: 'Comma-separated list of warnings to check for'
required: false
default: 'SyntaxWarning,DeprecationWarning,FutureWarning'
default: 'UserWarning,DeprecationWarning,PendingDeprecationWarning,SyntaxWarning,RuntimeWarning,FutureWarning,ImportWarning,UnicodeWarning,BytesWarning,ResourceWarning,EncodingWarning'
exclude-warning:
description: 'Comma-separated list of warnings to exclude from checking (can be a single warning or multiple warnings)'
required: false
default: ''
fail-on-warning:
description: 'Whether to fail the workflow if warnings are found'
required: false
Expand Down Expand Up @@ -63,6 +67,7 @@ runs:
# Parse inputs
HTML_PATH="${{ inputs.html-path }}"
WARNINGS="${{ inputs.warnings }}"
EXCLUDE_WARNINGS="${{ inputs.exclude-warning }}"
FAIL_ON_WARNING="${{ inputs.fail-on-warning }}"

echo "Scanning HTML files in: $HTML_PATH"
Expand All @@ -71,6 +76,46 @@ runs:
# Convert comma-separated warnings to array
IFS=',' read -ra WARNING_ARRAY <<< "$WARNINGS"

# Handle exclude-warning parameter
if [ -n "$EXCLUDE_WARNINGS" ]; then
echo "Excluding warnings: $EXCLUDE_WARNINGS"
# Convert comma-separated exclude warnings to array
IFS=',' read -ra EXCLUDE_ARRAY <<< "$EXCLUDE_WARNINGS"

# Create a new array with warnings not in exclude list
FILTERED_WARNING_ARRAY=()
for warning in "${WARNING_ARRAY[@]}"; do
# Remove leading/trailing whitespace from warning
warning=$(echo "$warning" | xargs)
exclude_warning=false

# Check if this warning should be excluded
for exclude in "${EXCLUDE_ARRAY[@]}"; do
# Remove leading/trailing whitespace from exclude warning
exclude=$(echo "$exclude" | xargs)
if [ "$warning" = "$exclude" ]; then
exclude_warning=true
break
fi
done

# Add to filtered array if not excluded
if [ "$exclude_warning" = false ]; then
FILTERED_WARNING_ARRAY+=("$warning")
fi
done

# Replace WARNING_ARRAY with filtered array
WARNING_ARRAY=("${FILTERED_WARNING_ARRAY[@]}")

# Show final warning list
if [ ${#WARNING_ARRAY[@]} -eq 0 ]; then
echo "⚠️ All warnings have been excluded. No warnings will be checked."
else
echo "Final warning list after exclusions: ${WARNING_ARRAY[*]}"
fi
fi

# Initialize counters
TOTAL_WARNINGS=0
WARNING_DETAILS=""
Expand Down Expand Up @@ -150,6 +195,12 @@ runs:
for file in "${FILES[@]}"; do
echo "Checking file: $file"

# Skip warning check if no warnings to check for
if [ ${#WARNING_ARRAY[@]} -eq 0 ]; then
echo "No warnings to check for in $file (all excluded)"
continue
fi

for warning in "${WARNING_ARRAY[@]}"; do
# Remove leading/trailing whitespace from warning
warning=$(echo "$warning" | xargs)
Expand Down
101 changes: 97 additions & 4 deletions .github/actions/check-warnings/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning'
# Uses comprehensive default warnings (all Python warning types)
fail-on-warning: 'true'
```

Expand Down Expand Up @@ -158,7 +158,7 @@ jobs:
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning,UserWarning'
# Uses comprehensive default warnings (all Python warning types)
fail-on-warning: 'false' # Don't fail on warnings
create-issue: ${{ github.event_name == 'push' }} # Create issues only on push to main
issue-title: 'Python Warnings in Documentation Build - ${{ github.sha }}'
Expand Down Expand Up @@ -267,10 +267,103 @@ jobs:
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './output'
warnings: ${{ github.event.inputs.custom_warnings || 'SyntaxWarning,DeprecationWarning,FutureWarning' }}
warnings: ${{ github.event.inputs.custom_warnings || 'UserWarning,RuntimeWarning,ResourceWarning' }}
fail-on-warning: 'true'
```

## Example 6b: Excluding Specific Warning Types

```yaml
name: Check with Warning Exclusions

on:
push:
branches: [ main ]

jobs:
warning-check-with-exclusions:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build documentation
run: |
jupyter-book build .

- name: Check for warnings excluding upstream issues
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
exclude-warning: 'UserWarning' # Exclude problematic upstream warnings
fail-on-warning: 'true'
```

## Example 6c: Multiple Warning Exclusions

```yaml
name: Check with Multiple Warning Exclusions

on:
pull_request:
branches: [ main ]

jobs:
warning-check-multiple-exclusions:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build documentation
run: |
jupyter-book build .

- name: Check for warnings excluding multiple types
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
exclude-warning: 'UserWarning,RuntimeWarning,ResourceWarning' # Exclude multiple warning types
fail-on-warning: 'true'
create-artifact: 'true'
artifact-name: 'filtered-warning-report'
```

## Example 6d: Custom Warnings with Exclusions

```yaml
name: Custom Warnings with Exclusions

on:
schedule:
- cron: '0 2 * * 1' # Weekly on Monday

jobs:
custom-warning-check-with-exclusions:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build project
run: |
make build

- name: Check for specific warnings but exclude problematic ones
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './output'
warnings: 'UserWarning,DeprecationWarning,RuntimeWarning,FutureWarning,ResourceWarning'
exclude-warning: 'ResourceWarning,RuntimeWarning' # Exclude known upstream issues
fail-on-warning: 'false'
create-issue: 'true'
issue-title: 'Critical Python Warnings Found (Filtered)'
notify: 'team-lead'
```

## Example 7: Matrix Strategy

```yaml
Expand Down Expand Up @@ -308,7 +401,7 @@ jobs:
uses: QuantEcon/meta/.github/actions/check-warnings@main
with:
html-path: './_build/html'
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning'
# Uses comprehensive default warnings (all Python warning types)
fail-on-warning: 'false'

- name: Upload HTML artifacts if warnings found
Expand Down
Loading
Loading