-
Notifications
You must be signed in to change notification settings - Fork 22
feat: auto-fix missing .md extensions on PRs + fix fs_sdd_delete pages #720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hilram7
wants to merge
20
commits into
dev
Choose a base branch
from
feature/md-extension-autofix
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
07d9592
feat(md-autofix): scaffold script with detection functions and tests
hilram7 98bd264
feat(md-autofix): add link rewriting function with tests
hilram7 f174618
feat(md-autofix): implement main loop and JSON output
hilram7 b5f218f
feat(md-autofix): add workflow to auto-fix missing .md extensions on PRs
hilram7 14eaf0e
fix(docs): add .md extension and frontmatter to fs_sdd_delete (access…
hilram7 b5ba6e1
fix(md-autofix): use mv + git add instead of git mv to support untrac…
hilram7 7223cf5
chore: remove test files from md-autofix local testing
hilram7 a95397a
Merge branch 'dev' into feature/md-extension-autofix
hilram7 c16e85d
fix(vale): auto-fix substitutions and removals
github-actions[bot] 673f19c
fix(vale): auto-fix rewrites (AI-assisted)
github-actions[bot] ad5acb6
fix(dale): auto-fix documentation issues (AI-assisted)
github-actions[bot] 27bb241
Potential fix for pull request finding 'CodeQL / Checkout of untruste…
hilram7 3e861f3
fix(dale): auto-fix documentation issues (AI-assisted)
github-actions[bot] 3494007
docs: convert blockquote warnings to :::warning admonitions
github-actions[bot] 648fc06
fix(dale): auto-fix documentation issues (AI-assisted)
github-actions[bot] d3cc2b7
Merge branch 'dev' into feature/md-extension-autofix
hilram7 50af468
fix(workflow): checkout base branch to prevent untrusted code execution
hilram7 c9ca57e
fix(dale): auto-fix documentation issues (AI-assisted)
github-actions[bot] 71154cc
Merge branch 'dev' into feature/md-extension-autofix
hilram7 e13dc9e
fix(dale): auto-fix documentation issues (AI-assisted)
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| name: MD Extension Auto-Fix | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize] | ||
| branches: | ||
| - dev | ||
|
|
||
| concurrency: | ||
| group: md-extension-autofix-${{ github.event.pull_request.number }} | ||
|
|
||
| jobs: | ||
| md-extension-autofix: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - name: Check if triggered by bot commit | ||
| id: bot-check | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| COMMIT=$(gh api repos/${{ github.repository }}/commits/${{ github.event.pull_request.head.sha }} \ | ||
| --jq '{message: .commit.message}') | ||
| MESSAGE=$(echo "$COMMIT" | jq -r '.message') | ||
| echo "Latest commit message: $MESSAGE" | ||
| if echo "$MESSAGE" | grep -qE '^fix\(docs\): add missing \.md extension'; then | ||
| echo "Skipping: commit is from md-extension-autofix workflow" | ||
| echo "skip=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "skip=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Checkout PR branch | ||
| if: steps.bot-check.outputs.skip != 'true' | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event.pull_request.base.ref }} | ||
| fetch-depth: 0 | ||
|
|
||
|
|
||
| - name: Configure git identity | ||
| if: steps.bot-check.outputs.skip != 'true' | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| - name: Get changed files in docs/ | ||
| id: changed-files | ||
| if: steps.bot-check.outputs.skip != 'true' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| PR_NUMBER=${{ github.event.pull_request.number }} | ||
| CHANGED=$(gh pr diff "$PR_NUMBER" --name-only | grep -E '^docs/' || true) | ||
| if [ -z "$CHANGED" ]; then | ||
| echo "No docs/ files changed" | ||
| echo "count=0" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "$CHANGED" > /tmp/changed-files.txt | ||
| echo "count=$(echo "$CHANGED" | wc -l | tr -d ' ')" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Run md-extension-autofix | ||
| id: autofix | ||
| if: steps.changed-files.outputs.count > 0 | ||
| run: | | ||
| chmod +x scripts/md-extension-autofix.sh | ||
| SUMMARY=$(./scripts/md-extension-autofix.sh /tmp/changed-files.txt) | ||
| echo "$SUMMARY" > /tmp/md-extension-summary.json | ||
| RENAMED_COUNT=$(echo "$SUMMARY" | jq '.renamed | length') | ||
| SKIPPED_COUNT=$(echo "$SUMMARY" | jq '.skipped | length') | ||
| echo "renamed=$RENAMED_COUNT" >> "$GITHUB_OUTPUT" | ||
| echo "skipped=$SKIPPED_COUNT" >> "$GITHUB_OUTPUT" | ||
| echo "Renamed: $RENAMED_COUNT, Skipped: $SKIPPED_COUNT" | ||
|
|
||
| - name: Commit renamed files | ||
| id: commit | ||
| if: steps.autofix.outputs.renamed > 0 | ||
| run: | | ||
| if git diff --quiet && git diff --staged --quiet; then | ||
| echo "committed=false" >> "$GITHUB_OUTPUT" | ||
| else | ||
| git add -A docs/ | ||
| git commit -m "fix(docs): add missing .md extension to renamed files" | ||
| echo "committed=true" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Push fixes | ||
| if: steps.commit.outputs.committed == 'true' | ||
| continue-on-error: true | ||
| env: | ||
| VALE_TOKEN: ${{ secrets.VALE_TOKEN }} | ||
| run: | | ||
| git remote set-url origin "https://x-access-token:${VALE_TOKEN}@github.com/${{ github.repository }}.git" | ||
| git push | ||
|
|
||
| - name: Post PR comment | ||
| if: steps.changed-files.outputs.count > 0 | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| PR_NUMBER=${{ github.event.pull_request.number }} | ||
| REPO=${{ github.repository }} | ||
|
|
||
| RENAMED_COUNT=0 | ||
| SKIPPED_COUNT=0 | ||
| if [ -f /tmp/md-extension-summary.json ]; then | ||
| RENAMED_COUNT=$(jq '.renamed | length' /tmp/md-extension-summary.json) | ||
| SKIPPED_COUNT=$(jq '.skipped | length' /tmp/md-extension-summary.json) | ||
| fi | ||
|
|
||
| # Nothing to report — exit silently | ||
| if [ "$RENAMED_COUNT" -eq 0 ] && [ "$SKIPPED_COUNT" -eq 0 ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| { | ||
| if [ "$RENAMED_COUNT" -gt 0 ]; then | ||
| echo "**Auto-fix: Missing \`.md\` extensions added**" | ||
| echo "" | ||
| echo "The following files were missing a \`.md\` extension and would not have appeared on the docs site. They've been renamed automatically:" | ||
| echo "" | ||
| echo "| Original filename | Renamed to |" | ||
| echo "|---|---|" | ||
| jq -r '.renamed[] | "| `\(.from)` | `\(.to | split("/") | last)` |"' /tmp/md-extension-summary.json | ||
| echo "" | ||
| echo "Links to these files in other pages have been updated. Please review the changes in the commit above." | ||
| fi | ||
|
|
||
| if [ "$SKIPPED_COUNT" -gt 0 ]; then | ||
| if [ "$RENAMED_COUNT" -gt 0 ]; then echo ""; fi | ||
| echo "**Action needed: Possible missing \`.md\` extension**" | ||
| echo "" | ||
| echo "The following files were added to a docs directory without a \`.md\` extension, but couldn't be auto-renamed:" | ||
| echo "" | ||
| echo "| File | Reason |" | ||
| echo "|---|---|" | ||
| jq -r '.skipped[] | "| `\(.file)` | \(.reason) |"' /tmp/md-extension-summary.json | ||
| echo "" | ||
| echo "If these are markdown pages, add the \`.md\` extension and push again." | ||
| fi | ||
| } > /tmp/md-extension-comment.md | ||
|
|
||
| # Delete previous comments from this workflow | ||
| COMMENT_IDS=$(gh api "repos/${REPO}/issues/${PR_NUMBER}/comments" \ | ||
| --jq '[.[] | select( | ||
| .user.login == "github-actions[bot]" and | ||
| (.body | (contains("Auto-fix: Missing `.md` extensions") or contains("Action needed: Possible missing `.md` extension"))) | ||
| ) | .id] | .[]' 2>/dev/null || true) | ||
| for ID in $COMMENT_IDS; do | ||
| gh api "repos/${REPO}/issues/comments/${ID}" -X DELETE 2>/dev/null || true | ||
| done | ||
|
|
||
| gh pr comment "$PR_NUMBER" --repo "$REPO" --body-file /tmp/md-extension-comment.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.