Skip to content

Workflow file for this run

name: Javadoc Validation
on:
push:
branches: [ '*' ]
pull_request:
branches: [ master ]
workflow_dispatch:
inputs:
createIssue:
description: 'Create an issue for missing Javadocs'
required: true
type: boolean
default: true
jobs:
check-javadoc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Check Javadoc presence with Checkstyle
run: |
cat > checkstyle.xml << 'EOF'
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="JavadocMethod">
<property name="severity" value="warning"/>
<property name="scope" value="public"/>
</module>
<module name="JavadocType">
<property name="severity" value="warning"/>
<property name="scope" value="public"/>
</module>
<module name="JavadocVariable">
<property name="severity" value="warning"/>
<property name="scope" value="public"/>
</module>
<module name="MissingJavadocMethod">
<property name="severity" value="warning"/>
<property name="scope" value="public"/>
</module>
</module>
</module>
EOF
mvn checkstyle:check@validate-javadoc -Dcheckstyle.config.location=checkstyle.xml
- name: Generate Javadoc Report
if: failure()
run: mvn javadoc:javadoc
- name: Upload Javadoc Report
if: failure()
uses: actions/upload-artifact@v3
with:
name: javadoc-report
path: target/site/apidocs/
- name: Create Issue on Failure
if: failure()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const checkstyleOutput = fs.readFileSync('target/checkstyle-result.xml', 'utf8');
// Parse the checkstyle XML to get violation details
const violations = checkstyleOutput.match(/<error.*?\/>/g) || [];
const violationCount = violations.length;
const issueBody = `## Javadoc Validation Failed
${violationCount} Javadoc issues were found in the codebase.
### Details
${violations.map(v => {
const file = v.match(/file="([^"]+)"/)[1];
const line = v.match(/line="([^"]+)"/)[1];
const message = v.match(/message="([^"]+)"/)[1];
return `- ${file}:${line} - ${message}`;
}).join('\n')}
[View full Javadoc report](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID})
`;
// Create the issue
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '📝 Missing Javadoc Documentation Detected',
body: issueBody,
labels: ['documentation', 'javadoc']
});