-
Notifications
You must be signed in to change notification settings - Fork 176
66 lines (57 loc) · 2.19 KB
/
validate-frontmatter.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: Validate-Frontmatter
on:
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
validate-frontmatter:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
repository-projects: read
pull-requests: write
steps:
# Step 1: Check out the source code of the pull request.
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
# Step 2: Set up the Node.js environment.
- uses: actions/setup-node@v4
# Step 3: Get the list of changed files in the PR
- name: Get changed files
id: get_changed
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "changed=$(git diff --name-only $(git merge-base origin/main HEAD) HEAD)" | paste -sd "," - >> $GITHUB_ENV
echo "pr_owner=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
# Step 4: Check Markdown files for valid frontmatter
- name: Lint Frontmatter
uses: mathiasvr/command-output@v1
id: check_markdown
with:
run: |
cd scripts/frontmatter-validator
npm install --silent
node frontmatter-validator.js '${{ env.changed }}'
# Step 5: Write workflow job summary if the previous step failed
- name: Add Job Summary
if: failure()
run: |
echo "Hi @$pr_owner," >> $GITHUB_STEP_SUMMARY
echo "${{ steps.check_markdown.outputs.stdout }}" >> $GITHUB_STEP_SUMMARY
# Step 6: Leave a comment if the validation has failed and if it's not a PR from a fork
- name: Comment on PR
if: failure() && github.event.pull_request.head.repo.fork == false
uses: mshick/add-pr-comment@v2
with:
message: |
Hi @${{ env.pr_owner }},
${{ steps.check_markdown.outputs.stdout }}
Please fix the Frontmatter in your Markdown files.
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: "github-actions[bot]"
allow-repeats: true