Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .github/actions/setup-playwright/action.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
# Chapter 5 メンテナンス性を考慮したワークフロー (Custom actions).
# Chapter 5 ワークフローをDRYにする (Custom actions).
---
name: "Setup Playwright"
description: "Setup Playwright with deps and cache"
name: 'Setup Playwright'
description: 'Setup Playwright with deps and cache'
inputs:
working-directory:
description: "Working directory"
description: 'Working directory'
required: false
default: ${{ github.workspace }}

# Custom action は再利用可能なステップです。
# Custom action の種類の一つとして 同じ yaml で記載する Composite action があります。
# Composite action は複数のステップをまとめて再利用可能にすることができます。
# たとえば次のケースが考えられます。
# - 公開されている setup-* がないツールのインストール
# - 認証
# - キャッシュの設定
# - 成果物やテストデータのアップロード
# - 完了通知

runs:
using: "composite"
using: 'composite'
steps:
- name: Get Playwright version
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/articles-changed-detection.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# articles-changed-detection.yaml - 変更を自動検知しプロジェクトごとに並列実行するテスト
# 変更を自動検知しプロジェクトごとに並列実行するテスト
---
name: Articles - Changed detection sample

Expand Down
144 changes: 144 additions & 0 deletions .github/workflows/articles-docker-multi-platform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# マルチプラットフォームのDockerイメージをビルドしてGitHub Container Registryにプッシュするワークフロー
---
name: Articles - Build and push multi-platform image

on:
pull_request:
paths:
- 'chapters/go/hello-api/**'
- '.github/workflows/articles-docker-multi-platform.yaml'
workflow_dispatch:

permissions: {}
defaults:
run:
shell: bash

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
IMAGE_NAME: ghcr.io/${{ github.repository }}

jobs:
build:
name: Build ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm # arm64 runner
runs-on: ${{ matrix.runner }}
timeout-minutes: 5
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v7

- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> "$GITHUB_ENV"

# https://github.com/marketplace/actions/build-and-push-docker-images
- name: Login to Docker Hub
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.IMAGE_NAME }}

# QEMUは遅いので昨今は、arm64のRunnerを使うのが主流になってきている。
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

# GitHub Packages (GHCR) に latest タグで複数回プッシュすると
# 後から走ったジョブが前のイメージのメタデータを破壊・上書きするのを防ぐ
- name: Build and push by digest
id: build
uses: docker/build-push-action@v7
with:
context: './chapters/go/hello-api/'
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
provenance: false # 証明書マニフェストを作らない
sbom: false # 証明書マニフェストを作らない

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"

- name: Upload digest
uses: actions/upload-artifact@v7
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: '/tmp/digests/*'
if-no-files-found: error
retention-days: 1

merge:
name: Merge and push manifest list
runs-on: ubuntu-latest
needs: build
timeout-minutes: 5
permissions:
contents: read
packages: write
steps:
- name: Download digests
uses: actions/download-artifact@v7
with:
path: '/tmp/digests'
pattern: digests-*
merge-multiple: true

- name: Login to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
# 1. 最初に空の配列を定義
IMAGES=()

# 2. ループを回して配列に1つずつ安全に格納
for file in *; do
IMAGES+=("ghcr.io/suzu-devworks/examples-github-action@sha256:$file")
done

docker buildx imagetools create --tag "${{ env.IMAGE_NAME }}:latest" "${IMAGES[@]}"

- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:latest
1 change: 1 addition & 0 deletions .github/workflows/chapter-2-2-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
cd:
name: cd
runs-on: ubuntu-latest
timeout-minutes: 5
# GitHub Container Registry にイメージを push するための権限を付与する
permissions:
contents: read
Expand Down
56 changes: 0 additions & 56 deletions .github/workflows/chapter-2-3-cd-action.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Chapter 3 ワークフロー内で利用可能な値(コンテキスト).
---
name: Chapter 3 (1) - Context
name: Chapter 3 (1) - Contexts

on:
pull_request:
paths:
- '.github/workflows/chapter-3-1-context.yaml'
- '.github/workflows/chapter-3-1-contexts.yaml'
workflow_dispatch:

permissions: {}
Expand Down Expand Up @@ -52,7 +52,8 @@ jobs:
# runner コンテキストには主に、GitHub Actions の実行環境に関する情報が格納されています
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "$RUNNER_CONTEXT"
run: |
echo "runner: $RUNNER_CONTEXT"

- uses: actions/checkout@v7
# steps コンテキストを利用するには、id を指定する必要があります
Expand All @@ -62,19 +63,25 @@ jobs:
# steps コンテキストには、同じジョブ内で実行されたステップの情報が格納されています
run: |
# actions/checkout のステータスを表示
echo "${{ steps.checkout.conclusion }}"
echo "steps.checkout.conclusion: ${{ steps.checkout.conclusion }}"

- name: job コンテキストの表示
# job コンテキストには、同じジョブ内で実行されたステップの情報が格納されています
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: |
echo "${{ job.status }}"
echo "${{ toJson(job) }}"
echo "job.status: ${{ job.status }}"
echo "job: $JOB_CONTEXT"

- name: その他のコンテキストの表示
# - see: https://docs.github.com/ja/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs
env:
MATRIX_CONTEXT: ${{ toJson(matrix) }}
NEEDS_CONTEXT: ${{ toJson(needs) }}
ENV_CONTEXT: ${{ toJson(env) }}
INPUTS_CONTEXT: ${{ toJson(inputs) }}
run: |
echo "${{ toJson(matrix) }}"
echo "${{ toJson(needs) }}"
echo "${{ toJson(runner.os) }}"
echo "${{ toJson(env) }}"
echo "${{ toJson(inputs) }}"
echo "matrix: $MATRIX_CONTEXT"
echo "needs: $NEEDS_CONTEXT"
echo "env: $ENV_CONTEXT"
echo "inputs: $INPUTS_CONTEXT"
2 changes: 1 addition & 1 deletion .github/workflows/chapter-3-2-artifacts.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Chapter 3 ジョブの成果物の保存、次のジョブへの受け渡し.
---
name: Chapter 3 (2) - Artiafacts
name: Chapter 3 (2) - Saving and restoring artifacts

on:
pull_request:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Chapter 3 キャッシュ活用によるCIの高速化.
---
name: Chapter 3 (4) - Cache
name: Chapter 3 (4) - Accelerating CI using caching

on:
pull_request:
paths:
- '.github/workflows/chapter-3-4-cache.yaml'
- '.github/workflows/chapter-3-4-caching.yaml'
workflow_dispatch:

permissions: {}
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
- uses: actions/checkout@v7
# https://github.com/actions/setup-go#caching-dependency-files-and-build-outputs
# const primaryKey = `setup-go-${platform}-${arch}-${linuxVersion}go-${versionSpec}-${fileHash}`;
# fileHash のデフォルトは `go.mod` のハッシュ値だそうで
# fileHash のデフォルトは `go.mod` のハッシュ値だそうで
# `cache-dependency-path`を指定すると `go.sum` のハッシュ値を利用することができます。
- uses: actions/setup-go@v7
with:
Expand Down Expand Up @@ -76,11 +76,11 @@ jobs:
~/go/pkg/mod
# キーを指定することで、キャッシュ範囲を制御できます。
key: |
${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}-${{ github.run_id }}
${{ runner.os }}-${{ runner.arch }}-go-cache-${{ hashFiles('**/go.sum') }}-${{ github.run_id }}
# キーに `github.run_id` 含めたため実行単位が変わるとキャッシュがヒットしなくなるため
# restore-keys を指定して、キャッシュのヒット率を上げます。
restore-keys: |
${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}-
${{ runner.os }}-${{ runner.arch }}-go-cache-${{ hashFiles('**/go.sum') }}-
# 依存関係のキャッシュがヒットした場合、go mod download はスキップされます。
- run: go mod download
# キャッシュのセーブは、actions/cache のキャッシュキーが変化した場合にのみ行われます。
Expand Down Expand Up @@ -185,16 +185,17 @@ jobs:
run:
working-directory: './chapters/dotnet/HelloWorld/'
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
NUGET_PACKAGES: '${{ github.workspace }}/.nuget/packages'
steps:
- uses: actions/checkout@v7
- uses: actions/cache@v6
with:
path: ~/.nuget/packages
path: ${{ env.NUGET_PACKAGES }}
# キーを指定することで、キャッシュ範囲を制御できます。
key: |
${{ runner.os }}-nuget-cache-${{ hashFiles('**/packages.lock.json') }}-${{ github.run_id }}
${{ runner.os }}-${{ runner.arch }}-nuget-cache-${{ hashFiles('**/packages.lock.json') }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-nuget-cache-
${{ runner.os }}-${{ runner.arch }}-nuget-cache-
- uses: actions/setup-dotnet@v6
with:
dotnet-version: '10.x'
Expand All @@ -203,7 +204,8 @@ jobs:

build-join:
runs-on: ubuntu-latest
needs: [build-go-cache, build-node-yarn, build-node-pnpm, build-dotnet-cache]
needs:
[build-go-cache, build-node-yarn, build-node-pnpm, build-dotnet-cache]
permissions:
contents: read
steps:
Expand Down
Loading
Loading