|
| 1 | +name: Lint new posts |
| 2 | + |
| 3 | +# Blocking PR check: any new file added to docs/blog/posts/ MUST include |
| 4 | +# `draft: true` in its frontmatter. This guarantees a PR merge cannot |
| 5 | +# accidentally publish a post — the only legitimate way to flip a post live |
| 6 | +# is through the scheduling workflows (auto-publisher, /publish-now, |
| 7 | +# "Schedule a post" → publish-now). Removing `draft: true` is the dedicated |
| 8 | +# job of the github-actions bot, and that path doesn't go through PR review. |
| 9 | +# |
| 10 | +# Modified existing posts are NOT checked here — auto-publisher commits |
| 11 | +# legitimately remove `draft: true`. |
| 12 | + |
| 13 | +# |
| 14 | +# Runs on every PR (no path filter) so this check can be marked "required" in |
| 15 | +# branch protection without leaving unrelated PRs hanging on a missing status. |
| 16 | +# When no posts were added the check passes trivially. |
| 17 | + |
| 18 | +on: |
| 19 | + pull_request: |
| 20 | + branches: [main] |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: read |
| 24 | + pull-requests: write |
| 25 | + |
| 26 | +jobs: |
| 27 | + lint: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + fetch-depth: 0 # need history to diff against base |
| 33 | + |
| 34 | + - uses: actions/setup-python@v5 |
| 35 | + with: |
| 36 | + python-version: "3.12" |
| 37 | + |
| 38 | + - name: Install PyYAML |
| 39 | + run: pip install pyyaml |
| 40 | + |
| 41 | + - name: Collect newly added posts |
| 42 | + id: added |
| 43 | + env: |
| 44 | + BASE_SHA: ${{ github.event.pull_request.base.sha }} |
| 45 | + HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 46 | + run: | |
| 47 | + set -e |
| 48 | + ADDED=$(git diff --name-only --diff-filter=A "$BASE_SHA" "$HEAD_SHA" -- 'docs/blog/posts/*.md' || true) |
| 49 | + if [ -z "$ADDED" ]; then |
| 50 | + echo "No new posts added in this PR — lint passes trivially." |
| 51 | + else |
| 52 | + echo "Newly added post files:" |
| 53 | + echo "$ADDED" |
| 54 | + fi |
| 55 | + { |
| 56 | + echo "files<<EOF" |
| 57 | + echo "$ADDED" |
| 58 | + echo "EOF" |
| 59 | + } >> "$GITHUB_OUTPUT" |
| 60 | +
|
| 61 | + - name: Enforce draft on new posts |
| 62 | + if: steps.added.outputs.files != '' |
| 63 | + env: |
| 64 | + FILES: ${{ steps.added.outputs.files }} |
| 65 | + run: | |
| 66 | + set -e |
| 67 | + # FILES is newline-separated; word-splitting on whitespace gives the arg list. |
| 68 | + # shellcheck disable=SC2086 |
| 69 | + python scripts/schedule_lib.py lint-new-posts $FILES | tee result.json |
| 70 | +
|
| 71 | + - name: Post-fail explainer |
| 72 | + if: failure() |
| 73 | + uses: actions/github-script@v7 |
| 74 | + with: |
| 75 | + script: | |
| 76 | + const fs = require('fs'); |
| 77 | + let body = '### Lint failed: new post(s) missing `draft: true`\n\n'; |
| 78 | + body += 'Every new post in `docs/blog/posts/` must include `draft: true` in its frontmatter when first added. '; |
| 79 | + body += 'This is a safety rail — a merge of this PR with the post in its current state would put it live on blogs.jaseci.org immediately, bypassing editorial review.\n\n'; |
| 80 | + body += 'Fix: add `draft: true` to the frontmatter of the affected file(s):\n\n'; |
| 81 | + body += '```yaml\n---\ndate: 2026-XX-XX\nauthors:\n - your_author_id\ncategories:\n - Your Category\nslug: your-slug\ndraft: true # <- this line\n---\n```\n\n'; |
| 82 | + body += 'Once an editor merges the PR, they will schedule a publish time using the *Schedule a post* workflow (or `/schedule <ISO datetime>` in this PR\'s comments). The auto-publisher will flip `draft: true` off when that time arrives.\n\n'; |
| 83 | + try { |
| 84 | + const result = fs.readFileSync('result.json', 'utf8'); |
| 85 | + body += '<details><summary>Lint output</summary>\n\n```json\n' + result + '\n```\n\n</details>'; |
| 86 | + } catch (e) {} |
| 87 | + await github.rest.issues.createComment({ |
| 88 | + owner: context.repo.owner, |
| 89 | + repo: context.repo.repo, |
| 90 | + issue_number: context.payload.pull_request.number, |
| 91 | + body, |
| 92 | + }); |
0 commit comments