CI/CD for This Site
How Mengty Learns validates the Next.js static build, tests hands-on labs, and collects weekly RSS inbox items using three GitHub Actions workflows.
TL;DR
This repository runs three focused GitHub Actions workflows: ci.yml gates every PR on lint, typecheck, and static build; labs.yml lints and builds labs/** only when lab files or workflows change; and inbox.yml creates a weekly GitHub issue from RSS feeds.
Why it exists
A learning site with real code labs and an RSS reading inbox needs fast feedback without mixing concerns: PRs that edit a Markdown note should not rebuild Docker images, and an automated RSS job should never have write access to repository contents.
Mental model
Each workflow has a single trigger scope and minimal permissions:
| Workflow | Trigger | What it runs |
|---|---|---|
.github/workflows/ci.yml | push (main, mengtylearns-mvp) & pull_request | pnpm install --frozen-lockfile, lint, typecheck, build |
.github/workflows/labs.yml | push (main) & pull_request on labs/** or labs.yml | hadolint + docker build, tofu fmt/validate + tflint, kubeconform, actionlint |
.github/workflows/inbox.yml | Weekly cron: '0 9 * * 1' & workflow_dispatch | node scripts/inbox.mjs → creates/updates "Inbox week $WEEK" issue |
Do it
1. Site build gate (ci.yml)
Every push to main or PR runs the exact same three commands we run locally, using pinned pnpm 11.6.0 and Node 22:
# .github/workflows/ci.yml
- uses: pnpm/action-setup@v4
with:
version: 11.6.0
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm lint
- run: pnpm typecheck
- run: pnpm buildYou can run the same gate locally before committing:
pnpm lint && pnpm typecheck && pnpm build2. Path-filtered lab validation (labs.yml)
labs.yml only triggers when labs/** or .github/workflows/labs.yml changes, and drops token permissions to contents: read. Each job (docker, tofu, kubernetes, workflows) checks whether matching files exist before installing tools:
# .github/workflows/labs.yml
- name: Find Dockerfiles
id: find
shell: bash
run: |
shopt -s nullglob
files=(labs/*/Dockerfile)
echo "has_files=$([[ ${#files[@]} -gt 0 ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"
- name: Build Docker images (no push)
if: steps.find.outputs.has_files == 'true'
shell: bash
run: |
shopt -s nullglob
for df in labs/*/Dockerfile; do
dir="$(dirname "$df")"
name="$(basename "$dir")"
echo "::group::docker build $dir"
docker build --no-cache -t "lab-${name}:ci" "$dir"
echo "::endgroup::"
doneThe tofu job runs tofu fmt -check -recursive labs/, tofu init -backend=false && tofu validate, and tflint; kubernetes runs kubeconform -strict -summary labs/**/k8s/*.yaml; and workflows runs actionlint on .github/workflows/*.yml.
3. Weekly RSS inbox (inbox.yml)
inbox.yml runs every Monday at 09:00 UTC ('0 9 * * 1') with permissions: issues: write. It executes scripts/inbox.mjs and uses gh CLI to open or update one issue per ISO week so nothing is committed or published automatically:
# .github/workflows/inbox.yml
- name: Fetch feeds
run: node scripts/inbox.mjs --out inbox-report.md
- name: Create or update weekly inbox issue
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
WEEK=$(date +%V)
TITLE="Inbox week $WEEK"
EXISTING=$(gh issue list --state open --search "\"$TITLE\" in:title" --json number,title --jq ".[0].number // empty")
if [ -n "$EXISTING" ]; then
gh issue edit "$EXISTING" --body-file inbox-report.md
else
gh issue create --title "$TITLE" --body-file inbox-report.md
fiGotchas
- Lockfile drift:
ci.ymlandinbox.ymlboth pass--frozen-lockfile; updatingpackage.jsonwithout committingpnpm-lock.yamlfails immediately. - Unpinned actions vs pinned versions:
labs.ymlpinsactions/checkout@v4.2.2andhadolint/hadolint-action@v3.5.0, whereasci.ymluses@v4tags — prefer full version tags or commit SHAs for supply-chain hardening. labs.ymlpath filter: If you add a new lab tool that touches files outsidelabs/**,labs.ymlwill not trigger unless you update itspaths:list.
Production checklist
- Run
pnpm lint && pnpm typecheck && pnpm buildlocally before pushing. - Keep
permissionsscoped per workflow (contents: readfor checks,issues: writefor the inbox bot). - Pin
pnpmand Node versions across all workflows so local and CI builds match.
Check yourself
Check Yourself
1. Why does .github/workflows/labs.yml check has_files before running Docker, OpenTofu, or kubeconform steps?
2. What does .github/workflows/inbox.yml do with the fetched RSS items?
Sources
Related Notes
Deploy & Rollback Strategies
Compare rolling, blue-green, canary, feature flags, expand/contract DB migrations, and rollback vs roll-forward, using this site's planned Workers flow.
What Is GitOps? (Pull vs Push)
How GitOps uses a declarative Git repository as the single source of truth and an in-cluster pull agent to converge cluster state.