XS✔ ◾ [⚠️Don't merge] Testing new markdown action #7
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
name: Validate-Markdown | |
on: | |
pull_request: | |
branches: [ main ] | |
workflow_dispatch: | |
jobs: | |
validate-markdown: | |
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 | |
with: | |
config: ./.markdownlint/config.json | |
files: ${{ env.changed }} | |
ignore: node_modules | |
# 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 |