1+ name : Auto Documentation
2+
3+ on :
4+ pull_request :
5+ branches : [main]
6+ types : [opened, ready_for_review, reopened, synchronize]
7+ paths :
8+ - " source/**"
9+ - " plugins/**"
10+
11+ permissions :
12+ contents : write
13+ pull-requests : write
14+ id-token : write
15+
16+ jobs :
17+ auto-documentation :
18+ name : Generate Documentation
19+ if : ${{ !github.event.pull_request.draft }}
20+ runs-on : ubuntu-latest
21+ timeout-minutes : 15
22+
23+ steps :
24+ - name : Checkout PR Branch
25+ uses : actions/checkout@v4
26+ with :
27+ token : ${{ secrets.GITHUB_TOKEN }}
28+ ref : ${{ github.head_ref }}
29+ fetch-depth : 0
30+
31+ - name : Check if last commit was auto-documentation
32+ id : check-auto-commit
33+ run : |
34+ LAST_COMMIT_MSG=$(git log -1 --pretty=format:"%s")
35+ if [[ "$LAST_COMMIT_MSG" == *"Auto-generate documentation"* ]]; then
36+ echo "auto-commit=true" >> "$GITHUB_OUTPUT"
37+ echo "Last commit was auto-documentation - skipping to prevent loops"
38+ else
39+ echo "auto-commit=false" >> "$GITHUB_OUTPUT"
40+ echo "Last commit was not auto-documentation - analyzing code for documentation updates"
41+ fi
42+
43+ - name : Get Changed Apex Files
44+ if : steps.check-auto-commit.outputs.auto-commit == 'false'
45+ id : changed-files
46+ run : |
47+ # Get list of changed .cls files in source and plugins directories
48+ git diff --name-only origin/main..HEAD | grep -E '\.(cls|trigger)$' > changed_files.txt || touch changed_files.txt
49+
50+ if [ -s changed_files.txt ]; then
51+ echo "has-changes=true" >> "$GITHUB_OUTPUT"
52+ echo "Changed Apex files:"
53+ cat changed_files.txt
54+ else
55+ echo "has-changes=false" >> "$GITHUB_OUTPUT"
56+ echo "No Apex files changed"
57+ fi
58+
59+ - name : Analyze Code Changes with Claude
60+ if : steps.check-auto-commit.outputs.auto-commit == 'false' && steps.changed-files.outputs.has-changes == 'true'
61+ uses : anthropics/claude-code-action@beta
62+ with :
63+ claude_code_oauth_token : ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
64+ direct_prompt : |
65+ I need you to analyze the changed Apex files in this PR and automatically generate/update wiki documentation.
66+
67+ ## Your Task:
68+ 1. **Analyze each changed .cls and .trigger file** to identify new or modified `global` elements:
69+ - New `global` classes (including inner types)
70+ - New `global` methods
71+ - New `global` properties
72+ - Modified signatures of existing global elements
73+
74+ 2. **Generate wiki documentation** for any new global elements:
75+ - Create new wiki files for new global classes following the pattern `The-[ClassName]-Class.md`
76+ - Add new methods to existing class documentation files in the wiki directory
77+ - Add new properties to existing class documentation files in the wiki directory
78+ - Update `wiki/_Sidebar.md` to include new class files in alphabetical order within their appropriate sections
79+
80+ 3. **Follow the existing documentation patterns** in the `wiki/` directory:
81+ - Use the same markdown structure and formatting as existing files
82+ - Include method signatures, parameter descriptions, and return types
83+ - Add code examples where appropriate
84+ - Maintain consistent cross-references between files using relative links
85+ - Follow the existing naming conventions exactly
86+
87+ ## Important Guidelines:
88+ - Only document `global` elements (ignore private/protected/public without global)
89+ - Follow the existing wiki file naming conventions exactly (The-[ClassName]-Class.md)
90+ - Preserve existing content - only add new sections or update existing ones
91+ - If no new global elements are found, create no files
92+ - When updating existing files, insert new content in appropriate sections
93+ - Maintain alphabetical ordering in _Sidebar.md
94+
95+ ## Expected Output:
96+ Create or modify files in the `wiki/` directory as needed. I will review these changes as part of the PR.
97+
98+ - name : Check for Documentation Changes
99+ if : steps.check-auto-commit.outputs.auto-commit == 'false'
100+ id : check-docs
101+ run : |
102+ if git diff --quiet HEAD -- wiki/; then
103+ echo "has-doc-changes=false" >> "$GITHUB_OUTPUT"
104+ echo "No documentation changes generated"
105+ else
106+ echo "has-doc-changes=true" >> "$GITHUB_OUTPUT"
107+ echo "Documentation changes detected:"
108+ git diff --name-only HEAD -- wiki/
109+ fi
110+
111+ - name : Commit Documentation Updates
112+ if : steps.check-auto-commit.outputs.auto-commit == 'false' && steps.check-docs.outputs.has-doc-changes == 'true'
113+ run : |
114+ git config --local user.email "action@github.com"
115+ git config --local user.name "GitHub Action"
116+
117+ git add wiki/
118+ git commit -m "Auto-generate documentation for code changes
119+
120+ Updated docs
121+
122+ git push origin ${{ github.head_ref }}
0 commit comments