跪拜 Guibai
← All articles
GitHub · Frontend · Backend

GitHub Actions from Zero to Ten Production Workflows: A Beginner's Map

By bysking ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

GitHub Actions has become the default automation layer for hosted repos, and the real cost of learning it is trial-and-error: the Pages 403 failure is nearly always the missing id-token permission, and the difference between pull_request and pull_request_target is a known secret-leak vector. This guide compresses both into copy-paste templates.

Summary

An event-driven automation platform runs any command sequence when a repo event fires. The core mental model: an event triggers a workflow, a workflow contains jobs, each job runs on its own fresh runner and each job is a list of steps that either execute shell commands or call reusable actions. This guide is built entirely around that five-term mental model, from the first `.github/workflows/` file through reading logs and troubleshooting. Checkout must precede any command that needs repo files because runners start empty.

Ten scenario configs make up the practical core: GitHub Pages deployment with the three required permissions, Vercel and Netlify deploys via secrets, a Node.js CI with a version matrix and a Postgres service container, monorepo builds gated by paths-filter and Turborepo, Docker images pushed to GHCR with OIDC-style GITHUB_TOKEN, SSH and rsync VPS deploys, PR automation with labeler, cron data sync, tag-triggered npm publishing with provenance, and reusable workflows via workflow_call.

Takeaways
— Workflow files must live in the repo's `.github/workflows/` directory with a `.yml` or `.yaml` extension; anywhere else and GitHub silently ignores them.
— Steps within a job run serially and share files; jobs run in parallel on separate ephemeral VMs unless `needs:` declares a dependency.
— Each runner starts empty, so `actions/checkout` must come before any command that needs the repo's files.
— GitHub Pages deployment requires three permissions: `contents: read`, `pages: write`, and `id-token: write`; missing the id-token is the most common cause of 403 errors.
— GitHub's cron for scheduled workflows runs on UTC, has a 5-minute minimum interval, can be delayed 10–30 minutes during peaks, and workflows get auto-disabled after 60 days without repo activity.
— `pull_request` runs without secrets for fork PRs, while `pull_request_target` runs in the target repo context with secrets, so never checkout and run PR-provided code under it.
— Third-party actions should be pinned to a commit SHA instead of a version tag, because tag refs can be repointed by the maintainer while SHAs cannot.
— `GITHUB_TOKEN` is generated automatically per repo, auto-renewed, and permission-scoped, so no personal access token is needed for GHCR or most Actions.
— Docker builds with `cache-from: type=gha` reuse the Actions cache layer and can make second builds 5–10x faster.
— npm publishing with `--provenance` generates verifiable supply-chain proof; the release tag version must match the package.json version.
— Cross-job file sharing requires `actions/upload-artifact` and `actions/download-artifact`; jobs cannot see each other's files by default.
— A reusable workflow defined with `workflow_call` in a shared repo lets multiple business repos call one CI template with just a few lines.
Conclusions

The five-term mental model is presented as the entire foundation: every later section, including the ten scenarios, is framed as an expansion of event/workflow/job/step/runner relationships.

The 90% Pages failure diagnosis is the most actionable claim in the guide, identifying a specific permission configuration rather than a vague deployment issue.

portraying `pull_request` vs `pull_request_target` as a security boundary rather than a YAML detail reflects a real fork-pr privilege distinction that teams often discover only after an incident.

The guide's repeated insistence on `--frozen-lockfile` addresses the class of bugs where local and CI environments diverge, treating dependency drift as a CI failure mode, not just a reproducibility concern.

The progression from copy-paste configs to a security hardening checklist shows that pipeline maintenance is as much about dependency pinning and secret hygiene as about writing working YAML.

Concepts & terms
Runner
A machine GitHub provides (Ubuntu, Windows, or macOS VM) that executes a job; each job gets a fresh, disposable runner that is destroyed when the job finishes.
Action
A reusable automation module invoked with `uses: owner/repo@version`, comparable to an npm or pip package; `actions/checkout` is the most common one.
Context expression
The `${{ }}` syntax in YAML that GitHub replaces at runtime with values like the triggering username (`github.actor`), the event name (`github.event_name`), or the runner OS (`runner.os`).
Artifact
Files a job produces, such as logs, build packages, or test reports; upload them with `actions/upload-artifact` so another job or a human can download them later.
OIDC
A token-based authentication method where GitHub issues short-lived credentials so workflows can authenticate to cloud providers like AWS without storing long-term keys; it removes the need for secrets that never expire.
Provenance
A machine-verifiable source proof attached to an npm package via `npm publish --provenance`, demonstrating which build environment produced the release; the guide calls it key to supply chain security.
From the discussion
Featured comments
组合搭配函数 1 likes

I really agree with those security reminders, especially that once a secret is written in, even deleting it counts as a leak — nine out of ten beginners will fall into that trap. When I first started, I also took the shortcut and hardcoded keys, and later I had to go through the painful rotation of everything; I was so frustrated I couldn't even cry.

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗