GITHUB-ACTIONS40 cmd
GitHub Actions チート集
GitHub Actions の workflow、events、jobs/steps、matrix、reusable workflow/action、artifacts/cache、secrets、OIDC、runner、デバッグを整理したチート集。
- 更新日
- 2026-05-14
- 参照範囲
- 公式ドキュメント / man page / 主要ベンダーCLI
- 対象実装
- 主要 Linux / BSD / ネットワーク機器 CLI の一般的な実装
- 免責
- OS とバージョン差分は実環境で確認してください。
40 / 40
| Command | Description | Example | Copy |
|---|---|---|---|
.github/workflows/*.yml | workflow ファイルの配置場所。 | .github/workflows/ci.yml | |
name | workflow 名を定義する。 | name: CI | |
on push | push を契機に実行する。 | on:
push:
branches: [main] | |
on pull_request | PR を契機に実行する。 | on:
pull_request:
branches: [main] | |
workflow_dispatch | 手動実行を有効にする。 | on:
workflow_dispatch:
inputs:
environment:
type: choice
options: [stg, prod] | |
schedule cron | 定期実行する。 | on:
schedule:
- cron: "15 2 * * *" | |
workflow_run | 別 workflow 完了後に実行する。 | on:
workflow_run:
workflows: [CI]
types: [completed] | |
jobs runs-on | job の実行環境を指定する。 | jobs:
test:
runs-on: ubuntu-latest | |
steps uses checkout | action を利用する。 | steps:
- uses: actions/checkout@v4 | |
steps run | shell コマンドを実行する。 | steps:
- name: Test
run: npm ci && npm test | |
if condition | 条件付きで step/job を実行する。 | if: github.ref == 'refs/heads/main' | |
needs | job 間の依存を定義する。 | deploy:
needs: [test, build]
runs-on: ubuntu-latest | |
env | 環境変数を設定する。 | env:
NODE_ENV: test | |
defaults run shell | 既定 shell を指定する。 | defaults:
run:
shell: bash | |
matrix strategy | 複数 Node 版で実行する。 | strategy:
matrix:
node: [20, 22]
steps:
- uses: actions/setup-node@v4
with: { node-version: "${{ matrix.node }}" } | |
matrix include | matrix に追加値を持たせる。 | strategy:
matrix:
include:
- os: ubuntu-latest
node: 22
experimental: false | |
matrix exclude | 特定組み合わせを除外する。 | strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node: [20, 22]
exclude:
- os: windows-latest
node: 20 | |
fail-fast false | matrix の一部失敗で他を止めない。 | strategy:
fail-fast: false
matrix:
node: [20, 22] | |
workflow_call | 再利用可能 workflow を定義する。 | on:
workflow_call:
inputs:
image:
type: string
required: true | |
uses reusable workflow | 別 workflow を呼ぶ。 | jobs:
deploy:
uses: ./.github/workflows/deploy.yml
with:
image: ghcr.io/example/api:sha | |
composite action | 複合 action の基本。 | runs:
using: composite
steps:
- run: npm ci
shell: bash | |
docker action | Docker action の基本。 | runs:
using: docker
image: Dockerfile | |
javascript action | JavaScript action の基本。 | runs:
using: node20
main: dist/index.js | |
artifacts upload | 成果物を保存する。 | - uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage/ | |
artifacts download | 成果物を取得する。 | - uses: actions/download-artifact@v4
with:
name: coverage
path: coverage/ | |
actions/cache | 依存キャッシュを使う。 | - uses: actions/cache@v4
with:
path: ~/.npm
key: npm-${{ runner.os }}-${{ hashFiles('package-lock.json') }} | |
GITHUB_OUTPUT | step output を設定する。 | run: echo "image=ghcr.io/example/api:${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
id: meta | |
needs outputs | 別 job の output を使う。 | deploy:
needs: build
steps:
- run: echo "${{ needs.build.outputs.image }}" | |
secrets | secret を参照する。 | env:
API_TOKEN: ${{ secrets.API_TOKEN }} | |
environment | environment と保護ルールを使う。 | environment:
name: production
url: https://example.com | |
permissions minimal | GITHUB_TOKEN 権限を最小化する。 | permissions:
contents: read
pull-requests: write | |
OIDC AWS | OIDC で AWS ロールを引き受ける。 | permissions:
id-token: write
contents: read
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/github-actions
aws-region: ap-northeast-1 | |
OIDC GCP | OIDC で GCP 認証する。 | - uses: google-github-actions/auth@v2
with:
workload_identity_provider: projects/123/locations/global/workloadIdentityPools/gha/providers/github
service_account: deploy@example.iam.gserviceaccount.com | |
self-hosted runner | 自前 runner を指定する。 | runs-on: [self-hosted, linux, x64, prod] | |
runner labels | runner label で用途を分ける。 | runs-on:
group: prod-runners
labels: [linux, deploy] | |
ACTIONS_STEP_DEBUG | step debug ログを有効化する。 | gh secret set ACTIONS_STEP_DEBUG --body true --repo example/repo | |
tmate action | 失敗時に一時 SSH デバッグする。 | - uses: mxschmitt/action-tmate@v3
if: failure() | |
concurrency | 同一環境への同時 deploy を抑止する。 | concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: true | |
job summary | Markdown サマリを書く。 | run: echo "## Deploy complete" >> "$GITHUB_STEP_SUMMARY" | |
gh workflow run | CLI から workflow を手動起動する。 | gh workflow run deploy.yml -f environment=stg |