-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,61 @@ | ||
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@v3 | ||
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@v3 | ||
|
||
# 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: Lint + Validate Markdown files | ||
- name: Lint Markdown | ||
id: check_markdown | ||
uses: articulate/actions-markdownlint@v1 | ||
|
||
# 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 your Markdown files. | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
repo-token-user-login: "github-actions[bot]" | ||
allow-repeats: true |