CSS random() reference doc #34178
Workflow file for this run
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: Lint and review content files | |
| on: | |
| pull_request: | |
| paths: | |
| - .github/workflows/pr-check-lint_content.yml | |
| pull_request_target: | |
| paths: | |
| - .nvmrc | |
| - "*.md" | |
| - "files/**/*.md" | |
| permissions: | |
| # Compare commits and add reviewdog comments. | |
| pull-requests: write | |
| concurrency: | |
| group: ci-${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| jobs: | |
| lint-and-review-docs: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check if PR reviews can be posted | |
| id: permissions | |
| env: | |
| EVENT_NAME: ${{ github.event_name }} | |
| HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} | |
| BASE_REPO: ${{ github.repository }} | |
| run: | | |
| if [[ "${EVENT_NAME}" == "pull_request_target" || "${HEAD_REPO}" == "${BASE_REPO}" ]]; then | |
| echo "CAN_POST_REVIEWS=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Checkout BASE | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| # explicitly specify base ref to ensure `pull_request` runs | |
| # behave the same as `pull_request_target` runs | |
| ref: ${{ github.event.pull_request.base.sha }} | |
| persist-credentials: false | |
| - name: Get changed files | |
| id: check | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | |
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| run: | | |
| # Use the GitHub API to get the list of changed files | |
| # documentation: https://docs.github.com/rest/commits/commits#compare-two-commits | |
| # Get files as newline-separated list | |
| FILTERED_FILES=$(gh api repos/{owner}/{repo}/compare/${BASE_SHA}...${HEAD_SHA} \ | |
| --jq '.files | .[] | select(.status|IN("added", "modified", "renamed", "copied", "changed")) | .filename' | \ | |
| egrep -i "^.*\.md$" || true) | |
| # Store as multiline output | |
| EOF="$(openssl rand -hex 8)" | |
| echo "DIFF_DOCUMENTS<<${EOF}" >> "$GITHUB_OUTPUT" | |
| echo "${FILTERED_FILES}" >> "$GITHUB_OUTPUT" | |
| echo "${EOF}" >> "$GITHUB_OUTPUT" | |
| # Also set a simple flag for whether we have files | |
| if [ -n "${FILTERED_FILES// /}" ]; then # Remove all spaces and check if anything remains | |
| echo "HAS_FILES=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "HAS_FILES=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Checkout HEAD | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| path: pr_head | |
| persist-credentials: false | |
| - name: Get changed content from HEAD | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| run: | | |
| git config --global user.email "108879845+mdn-bot@users.noreply.github.com" | |
| git config --global user.name "mdn-bot" | |
| # Remove non-Markdown files from BASE. | |
| find files -type f ! -name '*.md' -delete | |
| git commit --quiet -m "Remove non-Markdown files from PR base" files | |
| # Remove files from BASE. | |
| rm -r files *.md | |
| # Remove non-Markdown files from HEAD. | |
| find pr_head -type f ! -name '*.md' -delete | |
| # Move Markdown files from HEAD into BASE. | |
| mv pr_head/files pr_head/*.md . | |
| # Remove HEAD checkout. | |
| rm -r pr_head | |
| # To avoid contents of PR getting into the diff that we are going to generate | |
| # after running the linters, here we make a dummy commit. | |
| # Note, this commit is not getting pushed. | |
| git add . | |
| git commit -m "Use Markdown files from PR head" . | |
| - name: Setup Node.js environment | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 | |
| with: | |
| node-version-file: ".nvmrc" | |
| cache: npm | |
| - name: Install | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| run: npm ci | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Check CRLF line endings | |
| id: crlf | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| env: | |
| DIFF_DOCUMENTS: ${{ steps.check.outputs.DIFF_DOCUMENTS }} | |
| run: | | |
| EOF="$(openssl rand -hex 8)" | |
| readarray -t files_to_lint <<< "$DIFF_DOCUMENTS" | |
| printf "Files to process (%d files):\n" "${#files_to_lint[@]}" | |
| printf "'%s'\n" "${files_to_lint[@]}" | |
| CRLF_FAILED=true | |
| CRLF_LOG=$(git ls-files --eol "${files_to_lint[@]}" | grep -E 'w/(mixed|crlf)') || CRLF_FAILED=false | |
| echo "CRLF_LOG<<${EOF}" >> "$GITHUB_OUTPUT" | |
| echo "${CRLF_LOG}" >> "$GITHUB_OUTPUT" | |
| echo "${EOF}" >> "$GITHUB_OUTPUT" | |
| echo "CRLF_FAILED=${CRLF_FAILED}" >> "$GITHUB_OUTPUT" | |
| - name: Diff | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| run: | | |
| git status | |
| git diff HEAD --color=always --word-diff --word-diff-regex='[[:alnum:]_]+' | |
| - name: Run markdownlint | |
| id: markdownlint | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| env: | |
| DIFF_DOCUMENTS: ${{ steps.check.outputs.DIFF_DOCUMENTS }} | |
| run: | | |
| EOF="$(openssl rand -hex 8)" | |
| readarray -t files_to_lint <<< "$DIFF_DOCUMENTS" | |
| MD_LINT_FAILED=false | |
| MD_LINT_LOG=$(npx markdownlint-cli2 --fix "${files_to_lint[@]}" 2>&1) || MD_LINT_FAILED=true | |
| echo "MD_LINT_LOG<<${EOF}" >> "$GITHUB_OUTPUT" | |
| echo "${MD_LINT_LOG}" >> "$GITHUB_OUTPUT" | |
| echo "${EOF}" >> "$GITHUB_OUTPUT" | |
| echo "MD_LINT_FAILED=${MD_LINT_FAILED}" >> "$GITHUB_OUTPUT" | |
| - name: Diff | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| run: | | |
| git status | |
| git diff HEAD --color=always --word-diff --word-diff-regex='[[:alnum:]_]+' | |
| - name: Lint front-matter | |
| id: frontmatter | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| env: | |
| DIFF_DOCUMENTS: ${{ steps.check.outputs.DIFF_DOCUMENTS }} | |
| run: | | |
| EOF="$(openssl rand -hex 8)" | |
| readarray -t files_to_lint <<< "$DIFF_DOCUMENTS" | |
| FM_LINT_FAILED=false | |
| FM_LINT_LOG=$(node scripts/front-matter_linter.js --fix true "${files_to_lint[@]}" 2>&1) || FM_LINT_FAILED=true | |
| echo "FM_LINT_LOG<<${EOF}" >> "$GITHUB_OUTPUT" | |
| echo "${FM_LINT_LOG}" >> "$GITHUB_OUTPUT" | |
| echo "${EOF}" >> "$GITHUB_OUTPUT" | |
| echo "FM_LINT_FAILED=${FM_LINT_FAILED}" >> "$GITHUB_OUTPUT" | |
| - name: Diff | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| run: | | |
| git status | |
| git diff HEAD --color=always --word-diff --word-diff-regex='[[:alnum:]_]+' | |
| - name: Run Prettier | |
| id: prettier | |
| if: steps.check.outputs.HAS_FILES == 'true' | |
| env: | |
| DIFF_DOCUMENTS: ${{ steps.check.outputs.DIFF_DOCUMENTS }} | |
| run: | | |
| EOF="$(openssl rand -hex 8)" | |
| readarray -t files_to_lint <<< "$DIFF_DOCUMENTS" | |
| PRETTIER_FAILED=false | |
| PRETTIER_LOG=$(npx prettier --check "${files_to_lint[@]}" 2>&1) || PRETTIER_FAILED=true | |
| echo "PRETTIER_LOG<<${EOF}" >> "$GITHUB_OUTPUT" | |
| echo "${PRETTIER_LOG}" >> "$GITHUB_OUTPUT" | |
| echo "${EOF}" >> "$GITHUB_OUTPUT" | |
| echo "PRETTIER_FAILED=${PRETTIER_FAILED}" >> "$GITHUB_OUTPUT" | |
| npx prettier -w "${files_to_lint[@]}" | |
| - name: Diff | |
| id: lint-diff | |
| if: always() && steps.check.outputs.HAS_FILES == 'true' | |
| run: | | |
| git status | |
| git diff HEAD --color=always --word-diff --word-diff-regex='[[:alnum:]_]+' | |
| if [[ -n $(git diff) ]]; then | |
| echo "FILES_MODIFIED=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Setup reviewdog | |
| if: (steps.lint-diff.outputs.FILES_MODIFIED == 'true' || steps.markdownlint.outputs.MD_LINT_FAILED == 'true') && steps.permissions.outputs.CAN_POST_REVIEWS == 'true' | |
| uses: reviewdog/action-setup@d8a7baabd7f3e8544ee4dbde3ee41d0011c3a93f # v1.5.0 | |
| with: | |
| reviewdog_version: latest | |
| - name: Suggest changes using diff | |
| if: steps.lint-diff.outputs.FILES_MODIFIED == 'true' && steps.permissions.outputs.CAN_POST_REVIEWS == 'true' | |
| env: | |
| REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| TMPFILE=$(mktemp) | |
| git diff >"${TMPFILE}" | |
| git stash -u && git stash drop | |
| reviewdog \ | |
| -name="mdn-linter" \ | |
| -f=diff \ | |
| -f.diff.strip=1 \ | |
| -filter-mode=diff_context \ | |
| -reporter=github-pr-review < "${TMPFILE}" | |
| - name: Add reviews for markdownlint errors | |
| if: steps.markdownlint.outputs.MD_LINT_FAILED == 'true' && steps.permissions.outputs.CAN_POST_REVIEWS == 'true' | |
| env: | |
| MD_LINT_LOG: ${{ steps.markdownlint.outputs.MD_LINT_LOG }} | |
| REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| echo "${MD_LINT_LOG}" | \ | |
| reviewdog \ | |
| -efm="%f:%l:%c %m" \ | |
| -efm="%f:%l %m" \ | |
| -name="markdownlint" \ | |
| -diff="git diff" \ | |
| -reporter="github-pr-review" | |
| - name: Fail if any issues pending | |
| if: steps.lint-diff.outputs.FILES_MODIFIED == 'true' || steps.crlf.outputs.CRLF_FAILED == 'true' || steps.markdownlint.outputs.MD_LINT_FAILED == 'true' || steps.frontmatter.outputs.FM_LINT_FAILED == 'true' | |
| env: | |
| CRLF_FAILED: ${{ steps.crlf.outputs.CRLF_FAILED }} | |
| MD_LINT_FAILED: ${{ steps.markdownlint.outputs.MD_LINT_FAILED }} | |
| FM_LINT_FAILED: ${{ steps.frontmatter.outputs.FM_LINT_FAILED }} | |
| PRETTIER_FAILED: ${{ steps.prettier.outputs.PRETTIER_FAILED }} | |
| CRLF_LOG: ${{ steps.crlf.outputs.CRLF_LOG }} | |
| MD_LINT_LOG: ${{ steps.markdownlint.outputs.MD_LINT_LOG }} | |
| FM_LINT_LOG: ${{ steps.frontmatter.outputs.FM_LINT_LOG }} | |
| PRETTIER_LOG: ${{ steps.prettier.outputs.PRETTIER_LOG }} | |
| run: | | |
| echo -e "\nPlease fix all the linting issues mentioned in the following logs and in the PR review comments." | |
| if [[ ${CRLF_FAILED} == 'true' ]]; then | |
| echo -e "\n\n🪵 In the following files make sure all the lines end with only Line Feed (LF) character and not with Carriage Return Line Feed (CRLF) characters:" | |
| echo "${CRLF_LOG}" | |
| echo "For more information refer https://gist.github.com/LunarLambda/3df0840b336a5e314e4ffdac03cbf619 ." | |
| echo "You may use https://app.execeratics.com/LFandCRLFonline/?l=en online tool to convert line endings from CRLF to LF." | |
| fi | |
| if [[ ${MD_LINT_FAILED} == 'true' ]]; then | |
| echo -e "\n\n🪵 Logs from markdownlint:" | |
| echo "${MD_LINT_LOG}" | |
| fi | |
| if [[ ${FM_LINT_FAILED} == 'true' ]]; then | |
| echo -e "\n\n🪵 Logs from front-matter linter:" | |
| echo "${FM_LINT_LOG}" | |
| fi | |
| if [[ ${PRETTIER_FAILED} == 'true' ]]; then | |
| echo -e "\n\n🪵 Logs from Prettier formatter:" | |
| echo "${PRETTIER_LOG}" | |
| echo -e "\nYou can use Prettier playground to format the files online (configuration pre-filled): https://prettier.io/playground/#N4Igxg9gdgLgprEAuEBiABABwIYGd7owAWc6CMAlgE6kBmFANqSTSADQgSaXS7KjYqVCAHcACoIR8U2BiOwBPPhwBGVbGADWcGAGVsAWzgAZClDjIYVAK5xV6rTt04wZgOaWbdkLjgGKnrYccAAemHBUFEawsgAqEVCCFHDStLK+HLjuTACK1hDwyGkMGSAAVrghutlweQUWSMWlAI758GLCmNIgeAC05nAAJkPsIFbYjO4AwhAGBtjIPQwMo1lQbkwAgjBWFCrW7RGm5kXp3kQwBgwA6kQU8LgucLpS9xQAbvcKi2C4yiDvWwASSgw1gujAkW4m1BuhgCiYpxK3kwwl813UmEWqJSEXeFg4Zl8VBgHWwbnmSNKOCoxMW8yomkGoigo1RZhg1wog2IyAAHAAGDg0VrUOBkikLRpnDgwbAqLk8ojIABMHGsvli8tSMpAfhUQ2Gg2M2HW1nJcAAYhAqPMdu5FtgDhAQABfV1AA \n" | |
| fi | |
| exit 1 |