@@ -44,25 +44,144 @@ jobs:
4444 runs-on: ubuntu-latest
4545
4646 steps:
47+ - name: Get PR information
48+ id: pr
49+ uses: actions/github-script@v7
50+ with:
51+ script: |
52+ const { data: pullRequest } = await github.rest.pulls.get({
53+ owner: context.repo.owner,
54+ repo: context.repo.repo,
55+ pull_number: context.issue.number,
56+ });
57+
58+ core.setOutput('head-sha', pullRequest.head.sha);
59+ core.setOutput('head-ref', pullRequest.head.ref);
60+ core.setOutput('base-sha', pullRequest.base.sha);
61+
4762 - name: Checkout PR branch
4863 uses: actions/checkout@v4
4964 with:
5065 token: ${{ secrets.GITHUB_TOKEN }}
51- ref: ${{ github.event.pull_request.head.ref }}
66+ ref: ${{ steps.pr.outputs.head-ref }}
67+ fetch-depth: 0
5268
5369 - name: Get changed files
5470 id: changed-files
5571 uses: tj-actions/changed-files@v40
5672 with:
5773 files: '**/*.md'
74+ base_sha: ${{ steps.pr.outputs.base-sha }}
75+ sha: ${{ steps.pr.outputs.head-sha }}
76+
77+ - name: Check if any markdown files changed
78+ id: check-files
79+ run: |
80+ if [ -z "${{ steps.changed-files.outputs.all_changed_files }}" ]; then
81+ echo "no-files=true" >> $GITHUB_OUTPUT
82+ echo "No markdown files were changed in this PR"
83+ else
84+ echo "no-files=false" >> $GITHUB_OUTPUT
85+ echo "Changed markdown files:"
86+ echo "${{ steps.changed-files.outputs.all_changed_files }}"
87+ fi
5888
59- - name: Format markdown files
89+ - name: Format MyST markdown files
90+ if: steps.check-files.outputs.no-files == 'false'
91+ id: format
6092 uses: QuantEcon/meta/.github/actions/code-style-checker@main
6193 with:
6294 files: ${{ steps.changed-files.outputs.all_changed_files }}
95+ check-myst-code-cells: 'true'
96+ check-markdown-blocks: 'true'
97+ python-languages: 'python,python3,ipython,ipython3'
98+ black-args: '--line-length=88'
99+ commit-files: 'true'
100+ git-user-name: 'GitHub Action'
101+ git-user-email: 'action@github.com'
63102
64103 - name: Push changes
65- run: git push
104+ if: steps.check-files.outputs.no-files == 'false' && steps.format.outputs.changes-made == 'true'
105+ run: |
106+ git push
107+ echo "Successfully pushed formatting changes"
108+
109+ - name: Post comment with results
110+ uses: actions/github-script@v7
111+ with:
112+ script: |
113+ const noFiles = '${{ steps.check-files.outputs.no-files }}';
114+ const changesMade = '${{ steps.format.outputs.changes-made }}';
115+ const filesProcessed = '${{ steps.format.outputs.files-processed }}';
116+ const filesChanged = '${{ steps.format.outputs.files-changed }}';
117+ const blocksFormatted = '${{ steps.format.outputs.total-blocks-formatted }}';
118+
119+ let body;
120+
121+ if (noFiles === 'true') {
122+ body = [
123+ '## 🔍 Code Style Check Results',
124+ '',
125+ '✅ **No markdown files were changed in this PR.**',
126+ '',
127+ 'The code style checker found no markdown files to process.',
128+ '',
129+ '---',
130+ '',
131+ '🤖 *This comment was automatically generated by the [Code Style Formatter](https://github.com/QuantEcon/meta/.github/actions/code-style-checker).*'
132+ ].join('\n ');
133+ } else if (changesMade === 'true') {
134+ body = [
135+ '## ✅ Code Style Formatting Applied',
136+ '',
137+ ` 🎉 **Successfully applied black formatting to ${blocksFormatted} code block(s) across ${filesChanged} file(s).**`,
138+ ' ' ,
139+ ' **Summary:**' ,
140+ ` - **Files processed:** ${filesProcessed}` ,
141+ ` - **Files modified:** ${filesChanged}` ,
142+ ` - **Code blocks formatted:** ${blocksFormatted}` ,
143+ ' ' ,
144+ ' **Changes committed:**' ,
145+ ' - Each modified file has been committed separately with a descriptive commit message' ,
146+ ' - The formatting follows PEP8 standards using black' ,
147+ ' ' ,
148+ ' **Languages processed:**' ,
149+ ' - \`python\`, \`python3\`, \`ipython\`, \`ipython3\` code blocks' ,
150+ ' - Both MyST \`{code-cell}\` directives and standard markdown fenced code blocks' ,
151+ ' ' ,
152+ ' ---' ,
153+ ' ' ,
154+ ' 🤖 *This comment was automatically generated by the [Code Style Formatter](https://github.com/QuantEcon/meta/.github/actions/code-style-checker).*'
155+ ].join('\n');
156+ } else {
157+ body = [
158+ ' ## ✅ Code Style Check Completed' ,
159+ ' ' ,
160+ ` 📝 **Processed ${filesProcessed} markdown file(s) - no formatting changes needed.**` ,
161+ ' ' ,
162+ ' All Python code blocks in the changed markdown files are already properly formatted according to PEP8 standards.' ,
163+ ' ' ,
164+ ' **Summary:**' ,
165+ ` - **Files processed:** ${filesProcessed}` ,
166+ ' - **Files modified:** 0' ,
167+ ' - **Code blocks formatted:** 0' ,
168+ ' ' ,
169+ ' **Languages checked:**' ,
170+ ' - \`python\`, \`python3\`, \`ipython\`, \`ipython3\` code blocks' ,
171+ ' - Both MyST \`{code-cell}\` directives and standard markdown fenced code blocks' ,
172+ ' ' ,
173+ ' ---' ,
174+ ' ' ,
175+ ' 🤖 *This comment was automatically generated by the [Code Style Formatter](https://github.com/QuantEcon/meta/.github/actions/code-style-checker).*'
176+ ].join('\n');
177+ }
178+
179+ await github.rest.issues.createComment({
180+ owner : context.repo.owner,
181+ repo : context.repo.repo,
182+ issue_number : context.issue.number,
183+ body : body
184+ });
66185```
67186
68187## Inputs
0 commit comments