Testing #2
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
| name: Markdown Lint Check | |
| on: | |
| pull_request: | |
| branches: | |
| - master | |
| paths: | |
| - '**.md' | |
| - '!.github/**' | |
| jobs: | |
| lint: | |
| permissions: | |
| contents: read | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Base | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| repository: OWASP/wstg | |
| ref: ${{ github.base_ref || 'master' }} | |
| path: base | |
| - name: Checkout PR | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| path: pr | |
| fetch-depth: 0 | |
| - name: Save PR Number | |
| env: | |
| PR_NUMBER: ${{ github.event.number }} | |
| run: echo $PR_NUMBER > pr_number | |
| - name: Setup Node | |
| uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 | |
| with: | |
| node-version: 24 | |
| - name: Cache npm Global | |
| uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 | |
| with: | |
| path: ~/.npm | |
| key: ${{ runner.os }}-npm-global-markdownlint-cli2 | |
| - name: Install Dependencies | |
| run: npm install -g markdownlint-cli2 | |
| - name: Get Changed Files | |
| id: files | |
| working-directory: pr | |
| run: | | |
| # Get list of changed .md files (excluding .github/) | |
| git fetch origin ${{ github.base_ref }} | |
| FILES=$(git diff --name-only --diff-filter=d origin/${{ github.base_ref }}...HEAD | grep '\.md$' | grep -v '^\.github/' || true) | |
| # Convert newlines to spaces for compatibility with expected format | |
| FILES_SPACE_SEPARATED=$(echo "$FILES" | tr '\n' ' ' | xargs) | |
| echo "files_updated=$FILES_SPACE_SEPARATED" >> $GITHUB_OUTPUT | |
| echo "## Changed files" >> $GITHUB_STEP_SUMMARY | |
| echo "$FILES" >> $GITHUB_STEP_SUMMARY | |
| shell: bash | |
| - name: Run Linter | |
| env: | |
| FILES: '${{ steps.files.outputs.files_updated }}' | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| # Initialize lint file (will remain empty if there are no issues) | |
| : > lint.txt | |
| for FILE in $FILES; do | |
| if [ -f "pr/$FILE" ]; then | |
| OUTPUT="$(markdownlint-cli2 "pr/$FILE" --config base/.github/configs/.markdownlint.json 2>&1)" || STATUS=$? | |
| if [ "${STATUS:-0}" -eq 0 ]; then | |
| # File passed linting, continue to next file | |
| continue | |
| elif [ "${STATUS:-0}" -eq 1 ]; then | |
| printf '%s\n' "$OUTPUT" | tee -a lint.txt | |
| else | |
| printf 'markdownlint failed for "%s" with exit code %s\n%s\n' "$FILE" "${STATUS:-0}" "$OUTPUT" >&2 | |
| exit "${STATUS:-0}" | |
| fi | |
| fi | |
| done | |
| if [ -s lint.txt ]; then | |
| exit 1 | |
| fi | |
| - name: Show Linting Issues | |
| if: failure() | |
| run: | | |
| cat lint.txt | |
| sed -i 's/```/triple-backtick/g' lint.txt | |
| - name: Create Artifact for Comment | |
| if: failure() | |
| run: | | |
| # Parse and format the lint output for better readability | |
| python3 base/.github/workflows/scripts/format_lint_output.py > artifact.txt | |
| - name: Upload List of Issues | |
| if: failure() | |
| uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 | |
| with: | |
| name: artifact | |
| path: | | |
| artifact.txt | |
| pr_number | |
| - name: Upload PR Number on Success | |
| if: success() | |
| uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 | |
| with: | |
| name: artifact | |
| path: pr_number | |