เอกสารอ้างอิง GitHub Actions ที่ค้นหาและพิมพ์ได้: workflow triggers, jobs, steps, expressions, matrices, caching และ reusable workflows ฟรี

Workflow skeleton & triggers

12
.github/workflows/ci.yml
Where workflow files live
name: CI
Workflow display name
on: push
Run on every push
on: { push: { branches: [main] } }
Only pushes to main
on: { push: { tags: ["v*"] } }
Run on version tags
on: pull_request
Run on PR open/update
on: { pull_request: { paths: ["src/**"] } }
Only when paths change
on: { schedule: [{ cron: "0 6 * * 1" }] }
Cron: Mondays 06:00 UTC
on: workflow_dispatch
Manual "Run workflow" button
workflow_dispatch: { inputs: { env: { type: choice, options: [dev, prod] } } }
Manual run with inputs
on: { release: { types: [published] } }
Run when a release ships
on: workflow_call
Make workflow reusable

Jobs & runners

12
jobs: { build: { runs-on: ubuntu-latest } }
Define a job and its runner
runs-on: [macos-latest / windows-latest]
Other hosted runner images
runs-on: [self-hosted, linux, x64]
Route to self-hosted by labels
needs: build
Run after another job
needs: [lint, test]
Wait for several jobs
if: github.ref == 'refs/heads/main'
Conditional job
container: node:22
Run job inside a Docker image
services: { redis: { image: redis:7, ports: ["6379:6379"] } }
Sidecar service container
outputs: { sha: ${{ steps.vars.outputs.sha }} }
Expose job outputs
needs.build.outputs.sha
Read another job's output
defaults: { run: { working-directory: app } }
Default dir for run steps
strategy: { fail-fast: false }
Keep matrix jobs running

Steps & popular actions

14
- uses: actions/checkout@v4
Clone the repository
- uses: actions/checkout@v4 with fetch-depth: 0
Full history (tags, blame)
- uses: actions/setup-node@v4 with node-version: 22
Install Node.js
- uses: actions/setup-python@v5 with python-version: "3.12"
Install Python
- uses: shivammathur/setup-php@v2 with php-version: "8.3"
Install PHP
- run: npm ci && npm test
Run shell commands
- run: | (multiline)
Multi-line script step
- name: Build
Readable step name in logs
- id: vars
Reference step outputs later
echo "sha=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
Set a step output
echo "PATH_EXTRA=/opt/bin" >> "$GITHUB_ENV"
Set env for later steps
- uses: actions/upload-artifact@v4
Save build outputs
- uses: actions/download-artifact@v4
Fetch artifacts in later jobs
continue-on-error: true
Don't fail the job on error

Expressions & contexts

14
${{ github.ref }}
Full ref, e.g. refs/heads/main
${{ github.ref_name }}
Branch or tag name only
${{ github.sha }}
Commit SHA being built
${{ github.event_name }}
Trigger: push, pull_request...
${{ github.actor }}
User who triggered the run
${{ github.repository }}
owner/repo string
${{ github.event.pull_request.number }}
Dig into the event payload
${{ secrets.API_KEY }}
Encrypted repo/org secret
${{ vars.SITE_URL }}
Non-secret config variable
${{ env.NODE_ENV }}
Environment variable
${{ runner.os }} / ${{ runner.temp }}
Runner OS and temp dir
${{ steps.vars.outputs.sha }}
Output of an earlier step
contains(), startsWith(), format()
Expression helper functions
GITHUB_TOKEN
Auto-provided per-run token

Conditionals & matrix

11
if: success() / failure() / always()
Run based on prior status
if: cancelled()
Only when the run is cancelled
if: github.event_name == 'push'
Trigger-specific step
if: startsWith(github.ref, 'refs/tags/')
Only for tag builds
if: contains(github.event.head_commit.message, '[skip e2e]')
Commit-message switches
strategy: { matrix: { node: [20, 22] } }
One job per matrix value
matrix: { os: [ubuntu-latest, macos-latest], node: [20, 22] }
Cross-product matrix (4 jobs)
${{ matrix.node }}
Use the matrix value
matrix: { include: [{ os: ubuntu-latest, node: 23, experimental: true }] }
Add extra combos
matrix: { exclude: [{ os: macos-latest, node: 20 }] }
Drop combos
max-parallel: 2
Throttle concurrent matrix jobs

Caching & artifacts

11
- uses: actions/cache@v4
Generic dependency cache
key: npm-${{ hashFiles('package-lock.json') }}
Cache key from lockfile hash
restore-keys: | npm-
Fallback prefix on miss
path: ~/.npm
What directory to cache
setup-node@v4 with cache: npm
Built-in npm cache (easiest)
setup-python@v5 with cache: pip
Built-in pip cache
upload-artifact@v4 with name/path
Store files for download
upload-artifact: retention-days: 5
Auto-delete artifacts
download-artifact@v4 (no name)
Download all artifacts
if-no-files-found: error
Fail if the path is empty
Cache limit: 10 GB per repo
Old caches get evicted

Environments & permissions

11
permissions: { contents: read }
Least-privilege GITHUB_TOKEN
permissions: { contents: write, pull-requests: write }
Allow pushes + PR comments
permissions: { id-token: write }
OIDC for cloud auth (no keys)
environment: production
Use a deploy environment
environment: { name: prod, url: https://app.example.com }
Link shown on the run
Environment protection rules
Required reviewers, wait timer
env: { NODE_ENV: production }
Env at workflow/job/step level
secrets.GITHUB_TOKEN
Scoped to the current repo
Settings > Secrets and variables > Actions
Where to define secrets
Org secrets with repo allowlists
Share secrets across repos
pull_request_target: use with care
Runs with secrets on fork PRs

Reusable workflows & composite actions

11
on: { workflow_call: { inputs: ..., secrets: ... } }
Declare a reusable workflow
jobs: { ci: { uses: org/repo/.github/workflows/ci.yml@v1 } }
Call a reusable workflow
uses: ./.github/workflows/ci.yml
Call one from the same repo
with: { node-version: 22 }
Pass inputs to the callee
secrets: inherit
Forward all caller secrets
${{ inputs.node-version }}
Read inputs in the callee
action.yml with runs: { using: composite }
Define a composite action
steps: - run: ... shell: bash
Composite steps need shell:
uses: ./.github/actions/setup
Use a local composite action
inputs/outputs in action.yml
Action interface definition
Nesting limit: 4 levels of reusable calls
Plan the call depth

Concurrency & timeouts

9
concurrency: { group: deploy, cancel-in-progress: true }
Kill superseded runs
group: ${{ github.workflow }}-${{ github.ref }}
One run per branch
cancel-in-progress: false
Queue instead of cancel
timeout-minutes: 15 (job level)
Kill runaway jobs (default 360)
timeout-minutes: 5 (step level)
Cap a single step
retry via nick-fields/retry@v3
Retry flaky steps
jobs.<id>.strategy.max-parallel
Limit parallel matrix legs
if: always() on cleanup steps
Cleanup even after failure
Scheduled runs can be delayed/skipped
Cron is best-effort, not exact

Common recipes

12
on: push: tags: ["v*"] + softprops/action-gh-release@v2
Release on version tag
on: push: paths: ["apps/api/**"]
Monorepo: build only what changed
dorny/paths-filter@v3
Per-job change detection
peaceiris/actions-gh-pages@v4
Deploy static site to Pages
docker/build-push-action@v6
Build and push Docker images
docker/login-action@v3 with ghcr.io
Log in to GitHub registry
aws-actions/configure-aws-credentials@v4 (OIDC)
Keyless AWS deploys
appleboy/ssh-action@v1
Run commands on a server
codecov/codecov-action@v4
Upload coverage reports
github/codeql-action
Code scanning / security
dependabot.yml + auto-merge workflow
Auto-update dependencies
schedule + stale action
Auto-close stale issues

Debugging

12
Secret ACTIONS_STEP_DEBUG = true
Verbose step debug logs
Secret ACTIONS_RUNNER_DEBUG = true
Runner diagnostic logs
Re-run jobs > Enable debug logging
One-off debug re-run
act
Run workflows locally in Docker
act -j build
Run a single job locally
act -s GITHUB_TOKEN=$(gh auth token)
Pass secrets to act
echo "::debug::message"
Emit a debug log line
echo "::error file=app.js,line=1::Oops"
Annotate code with errors
echo "::group::Install" ... "::endgroup::"
Collapsible log sections
$GITHUB_STEP_SUMMARY
Write Markdown run summary
mxschmitt/action-tmate@v3
SSH into a live runner
cat "$GITHUB_EVENT_PATH"
Inspect the raw event JSON

gh CLI for Actions

13
gh run list
Recent workflow runs
gh run list --workflow ci.yml
Runs for one workflow
gh run watch
Live-follow the latest run
gh run view 123456 --log
Full logs of a run
gh run view --log-failed
Only the failed steps' logs
gh run rerun 123456 --failed
Re-run failed jobs only
gh run cancel 123456
Cancel a run
gh run download 123456
Download run artifacts
gh workflow list
List workflows in the repo
gh workflow run ci.yml -f env=prod
Trigger workflow_dispatch
gh workflow disable ci.yml
Disable a workflow
gh secret set API_KEY
Set a repo secret
gh cache list / gh cache delete
Inspect and prune caches

ไม่มีรายการที่ตรงกับ “:q”


เกี่ยวกับ ชีตสรุป GitHub Actions

GitHub Actions cheat sheet นี้บีบ YAML ของ workflow ไว้ในหน้าเดียวที่ค้นหาได้: โครง workflow และ triggers, jobs และ runners, steps และ actions ยอดนิยม, expressions และ contexts, เงื่อนไขและ matrix builds, caching และ artifacts, environments และสิทธิ์, reusable workflows และ composite actions, concurrency และ timeouts, สูตรที่พบบ่อย, การดีบัก และคำสั่ง gh CLI สำหรับ Actions

ไฟล์ workflow ส่วนใหญ่เป็นไวยากรณ์ที่ต้องจำ (trigger ใดทำงานเมื่อมี tag, อ้างอิง secret อย่างไร, นิพจน์ if ที่ข้าม step บน fork, รูปแบบ cache key สำหรับ lockfile) ทุกแถวจึงแสดงชิ้นส่วน YAML พร้อมคำอธิบายหนึ่งบรรทัด

ชีตนี้ใช้ฟรีและทำงานฝั่งไคลเอนต์: กรองแถวแบบเรียลไทม์ด้วยช่องค้นหา ข้ามระหว่างส่วนต่างๆ ด้วยสารบัญที่ติดอยู่ คัดลอกชิ้นส่วนด้วยคลิกเดียว และพิมพ์หน้านี้เป็นเอกสารอ้างอิงบนโต๊ะทำงาน

วิธีใช้ ชีตสรุป GitHub Actions

  1. ไล่ดูแต่ละส่วน ตั้งแต่ Workflow skeleton & triggers และ Jobs & runners ไปจนถึง gh CLI for Actions
  2. ค้นหาด้วยคำสำคัญ เช่น matrix, secrets หรือ cache เพื่อกรองทุกแถวแบบเรียลไทม์
  3. ข้ามไปที่ Common recipes สำหรับ job build, test หรือ deploy สำเร็จรูปที่นำไปปรับใช้ได้
  4. คลิกที่ชิ้นส่วน YAML หรือไอคอนคัดลอกเพื่อคัดลอกไปวางในไฟล์ workflow ของคุณ
  5. พิมพ์ชีตเพื่อใช้เป็นเอกสารอ้างอิง GitHub Actions แบบออฟไลน์

คำถามที่พบบ่อย

สิบสองส่วน ได้แก่ โครง workflow และ triggers, jobs และ runners, steps และ actions ยอดนิยม, expressions และ contexts, เงื่อนไขและ matrix, caching และ artifacts, environments และสิทธิ์, reusable และ composite workflows, concurrency และ timeouts, สูตรที่พบบ่อย, การดีบัก และ gh CLI

มี: push, pull_request, schedule พร้อม cron, workflow_dispatch พร้อม inputs, release และตัวกรอง path และ branch ที่จำกัดแต่ละอย่าง

ทั้งสองอย่างมีส่วนของตัวเอง: กลยุทธ์ matrix พร้อม include, exclude และ fail-fast และ actions/cache พร้อม key ที่อิงกับ lockfile และ restore-keys

ได้ คลิกแถวใดก็ได้หรือไอคอนคัดลอก แล้วชิ้นส่วนจะถูกคัดลอกไปยังคลิปบอร์ดพร้อมข้อความยืนยันสั้นๆ

ฟรีทั้งหมด: ค้นหาได้ พิมพ์ได้ และแสดงผลในเบราว์เซอร์ของคุณโดยไม่ต้องสมัครสมาชิก

แชร์สิ่งนี้

การค้นหายอดนิยม
github actions cheat sheet github actions workflow syntax ตัวอย่าง github actions yaml github actions matrix build github actions cache รายการ workflow triggers reusable workflows github
ต้องการความช่วยเหลือ?
พบปัญหากับเครื่องมือนี้หรือไม่? แจ้งทีมงานของเรา
รายงานปัญหา

เพิ่มเครื่องมือฟรีนี้ลงในเว็บไซต์ของคุณเอง: คัดลอกและวางโค้ดด้านล่าง