Open9
【GitHub Actions】 GitHub を使った CI/CD について📝
ピン留めされたアイテム

GitHub Actions入門📝
GitHub CI/CD実践ガイド
ピン留めされたアイテム

[act]GitHub Actionsをローカルで試す📝
actをinstallする。
brew install act
GitHub ActionsのWorkflowを実行する
cd 該当Repository
# すべてのWorkflowを実行する
act
# すべてのWorkflowを実行する Ver. M系のMacの場合📝
act --container-architecture linux/amd64
# -W オプションを使用して、特定のWorkflowを実行する
act -W .github/workflows/pr-check.yml
# ワークフロー内のさらに一部のジョブのみを流す
act -W .github/workflows/pr-check.yml -j build
登録されているWorkflowを確認する📝
act -l
INFO[0000] Using docker host 'unix:///var/run/docker.sock', and daemon socket 'unix:///var/run/docker.sock'
WARN ⚠ You are using Apple M-series chip and you have not specified container architecture, you might encounter issues while running act. If so, try running it with '--container-architecture linux/amd64'. ⚠
Stage Job ID Job name Workflow name Workflow file Events
0 test Run Server-Side Tests Server CI server-ci.yml pull_request,push
初回実行時のメッセージ
act
INFO[0000] Using docker host 'unix:///var/run/docker.sock', and daemon socket 'unix:///var/run/docker.sock'
WARN ⚠ You are using Apple M-series chip and you have not specified container architecture, you might encounter issues while running act. If so, try running it with '--container-architecture linux/amd64'. ⚠
? Please choose the default image you want to use with act:
- Large size image: ca. 17GB download + 53.1GB storage, you will need 75GB of free disk space, snapshots of GitHub Hosted Runners without snap and pulled docker images
- Medium size image: ~500MB, includes only necessary tools to bootstrap actions and aims to be compatible with most actions
- Micro size image: <200MB, contains only NodeJS required to bootstrap actions, doesn't work with all actions
Default image and other options can be changed manually in /Users/sudamasahiro/Library/Application Support/act/actrc (please refer to https://nektosact.com/usage/index.html?highlight=configur#configuration-file for additional information about file structure) [Use arrows to move, type to filter, ? for more help]
Large
> Medium
Micro

GitHub Actions について

GitHub に Actions タブが表示されない

GitHub Actions Permissions (権限周りの設定)

Next.js の CI を GitHub Actionsで構築する

GitHubのWebhookを使ってみる🌟

Server Test CI のWorkflow Sample📝
server-ci.yml
# PR が push されたら、テストを実行する。
name: Server CI
on:
pull_request:
branches: [main] # レビューゲート
push:
branches: [main] # CD 用に拡張可
jobs:
test:
name: Run Server-Side Tests
runs-on: ubuntu-latest # 実行環境(Ubuntu最新版)
strategy:
# Node 20.x と Node 22.x の両方でテストを実行する。
matrix:
node-version: [20.x, 22.x] # 将来 LTS が増えても1行追加で済む
# テスト実行のためのステップ
steps:
- uses: actions/checkout@v4
# 1. Node をセットアップ
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
# 2. pnpmのセットアップ
- uses: pnpm/action-setup@v4
with:
version: latest
# 3. 依存インストール & Prisma生成 & テスト(サーバーディレクトリで実行)
- name: Install dependencies
working-directory: ./server
run: pnpm install --frozen-lockfile
- name: Generate Prisma client
working-directory: ./server
run: pnpm prisma generate
- name: Run tests
working-directory: ./server
run: pnpm test -- --ci --reporter=junit
# 4. テスト結果を GitHub に表示
- uses: test-summary/action@v2
if: always() # 失敗してもサマリ生成
with:
paths: "**/junit.xml"

GitHub Actionsで自動テストとビルドを設定する方法📝