InfraLab
GITHUB-ACTIONS40 cmd

GitHub Actions チート集

GitHub Actions の workflow、events、jobs/steps、matrix、reusable workflow/action、artifacts/cache、secrets、OIDC、runner、デバッグを整理したチート集。

更新日
2026-05-29
参照範囲
公式ドキュメント / man page / 主要ベンダーCLI
対象実装
主要 Linux / BSD / ネットワーク機器 CLI の一般的な実装
免責
OS とバージョン差分は実環境で確認してください。

このチートシートの使いどころ

GitHub Actions チート集は、GitHub Actions の workflow、events、jobs/steps、matrix、reusable workflow/action、artifacts/cache、secrets、OIDC、runner、デバッグを整理したチート集。 対象は公式ドキュメント、man page、主要ベンダー CLI で確認できる現行の一般的な実装です。カテゴリは基本、events-trigger、jobs-step、matrix-reusable、secrets-permissionsを中心に、40件のコマンドや値を用途別に引けます。障害調査、設定変更前の確認、作業メモ作成で、GitHub Actions、CI/CD、workflow、matrix、OIDCに関連する操作を短時間で探すために使います。

40 / 40

.github/workflows/*.yml

workflow ファイルの配置場所。

Example
.github/workflows/ci.yml
name

workflow 名を定義する。

Example
name: CI
on push

push を契機に実行する。

Example
on: push: branches: [main]
on pull_request

PR を契機に実行する。

Example
on: pull_request: branches: [main]
workflow_dispatch

手動実行を有効にする。

Example
on: workflow_dispatch: inputs: environment: type: choice options: [stg, prod]
schedule cron

定期実行する。

Example
on: schedule: - cron: "15 2 * * *"
workflow_run

別 workflow 完了後に実行する。

Example
on: workflow_run: workflows: [CI] types: [completed]
jobs runs-on

job の実行環境を指定する。

Example
jobs: test: runs-on: ubuntu-latest
steps uses checkout

action を利用する。

Example
steps: - uses: actions/checkout@v4
steps run

shell コマンドを実行する。

Example
steps: - name: Test run: npm ci && npm test
if condition

条件付きで step/job を実行する。

Example
if: github.ref == 'refs/heads/main'
needs

job 間の依存を定義する。

Example
deploy: needs: [test, build] runs-on: ubuntu-latest
env

環境変数を設定する。

Example
env: NODE_ENV: test
defaults run shell

既定 shell を指定する。

Example
defaults: run: shell: bash
matrix strategy

複数 Node 版で実行する。

Example
strategy: matrix: node: [20, 22] steps: - uses: actions/setup-node@v4 with: { node-version: "${{ matrix.node }}" }
matrix include

matrix に追加値を持たせる。

Example
strategy: matrix: include: - os: ubuntu-latest node: 22 experimental: false
matrix exclude

特定組み合わせを除外する。

Example
strategy: matrix: os: [ubuntu-latest, windows-latest] node: [20, 22] exclude: - os: windows-latest node: 20
fail-fast false

matrix の一部失敗で他を止めない。

Example
strategy: fail-fast: false matrix: node: [20, 22]
workflow_call

再利用可能 workflow を定義する。

Example
on: workflow_call: inputs: image: type: string required: true
uses reusable workflow

別 workflow を呼ぶ。

Example
jobs: deploy: uses: ./.github/workflows/deploy.yml with: image: ghcr.io/example/api:sha
composite action

複合 action の基本。

Example
runs: using: composite steps: - run: npm ci shell: bash
docker action

Docker action の基本。

Example
runs: using: docker image: Dockerfile
javascript action

JavaScript action の基本。

Example
runs: using: node20 main: dist/index.js
artifacts upload

成果物を保存する。

Example
- uses: actions/upload-artifact@v4 with: name: coverage path: coverage/
artifacts download

成果物を取得する。

Example
- uses: actions/download-artifact@v4 with: name: coverage path: coverage/
actions/cache

依存キャッシュを使う。

Example
- uses: actions/cache@v4 with: path: ~/.npm key: npm-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
GITHUB_OUTPUT

step output を設定する。

Example
run: echo "image=ghcr.io/example/api:${GITHUB_SHA}" >> "$GITHUB_OUTPUT" id: meta
needs outputs

別 job の output を使う。

Example
deploy: needs: build steps: - run: echo "${{ needs.build.outputs.image }}"
secrets

secret を参照する。

Example
env: API_TOKEN: ${{ secrets.API_TOKEN }}
environment

environment と保護ルールを使う。

Example
environment: name: production url: https://example.com
permissions minimal

GITHUB_TOKEN 権限を最小化する。

Example
permissions: contents: read pull-requests: write
OIDC AWS

OIDC で AWS ロールを引き受ける。

Example
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 認証する。

Example
- 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 を指定する。

Example
runs-on: [self-hosted, linux, x64, prod]
runner labels

runner label で用途を分ける。

Example
runs-on: group: prod-runners labels: [linux, deploy]
ACTIONS_STEP_DEBUG

step debug ログを有効化する。

Example
gh secret set ACTIONS_STEP_DEBUG --body true --repo example/repo
tmate action

失敗時に一時 SSH デバッグする。

Example
- uses: mxschmitt/action-tmate@v3 if: failure()
concurrency

同一環境への同時 deploy を抑止する。

Example
concurrency: group: deploy-${{ github.ref }} cancel-in-progress: true
job summary

Markdown サマリを書く。

Example
run: echo "## Deploy complete" >> "$GITHUB_STEP_SUMMARY"
gh workflow run

CLI から workflow を手動起動する。

Example
gh workflow run deploy.yml -f environment=stg
Related