InfraLab
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

CommandDescriptionExampleCopy
.github/workflows/*.ymlworkflow ファイルの配置場所。.github/workflows/ci.yml
nameworkflow 名を定義する。name: CI
on pushpush を契機に実行する。on: push: branches: [main]
on pull_requestPR を契機に実行する。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-onjob の実行環境を指定する。jobs: test: runs-on: ubuntu-latest
steps uses checkoutaction を利用する。steps: - uses: actions/checkout@v4
steps runshell コマンドを実行する。steps: - name: Test run: npm ci && npm test
if condition条件付きで step/job を実行する。if: github.ref == 'refs/heads/main'
needsjob 間の依存を定義する。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 includematrix に追加値を持たせる。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 falsematrix の一部失敗で他を止めない。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 actionDocker action の基本。runs: using: docker image: Dockerfile
javascript actionJavaScript 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_OUTPUTstep 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 }}"
secretssecret を参照する。env: API_TOKEN: ${{ secrets.API_TOKEN }}
environmentenvironment と保護ルールを使う。environment: name: production url: https://example.com
permissions minimalGITHUB_TOKEN 権限を最小化する。permissions: contents: read pull-requests: write
OIDC AWSOIDC で 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 GCPOIDC で 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 labelsrunner label で用途を分ける。runs-on: group: prod-runners labels: [linux, deploy]
ACTIONS_STEP_DEBUGstep 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 summaryMarkdown サマリを書く。run: echo "## Deploy complete" >> "$GITHUB_STEP_SUMMARY"
gh workflow runCLI から workflow を手動起動する。gh workflow run deploy.yml -f environment=stg
Related