|
1 | 1 | # ======================================== |
2 | 2 | # DevContainerベースイメージビルドワークフロー |
| 3 | +# セマンティックバージョニング対応版 |
3 | 4 | # ======================================== |
4 | | -name: Build and Push DevContainer Base Image |
| 5 | +name: Build and Push DevContainer Base Image (Semantic Versioning) |
5 | 6 |
|
6 | 7 | on: |
7 | 8 | push: |
8 | 9 | branches: |
9 | 10 | - master |
10 | 11 | paths: |
11 | 12 | - 'Dockerfile' |
12 | | - - '.github/workflows/build-image.yml' |
| 13 | + - '.github/workflows/build-image-semver.yml' |
| 14 | + tags: |
| 15 | + - 'v*.*.*' # v1.0.0 のようなタグをプッシュした時 |
13 | 16 | workflow_dispatch: |
| 17 | + inputs: |
| 18 | + version: |
| 19 | + description: 'Version to release (e.g., v1.0.1)' |
| 20 | + required: false |
| 21 | + type: string |
14 | 22 |
|
15 | 23 | env: |
16 | 24 | REGISTRY: ghcr.io |
17 | 25 | IMAGE_NAME: ${{ github.repository }} |
18 | 26 |
|
19 | 27 | permissions: |
20 | | - contents: read |
| 28 | + contents: write |
21 | 29 | packages: write |
22 | 30 |
|
23 | 31 | jobs: |
|
26 | 34 | steps: |
27 | 35 | - name: Checkout repository |
28 | 36 | uses: actions/checkout@v4 |
| 37 | + with: |
| 38 | + fetch-depth: 0 |
29 | 39 |
|
30 | 40 | - name: Set up Docker Buildx |
31 | 41 | uses: docker/setup-buildx-action@v3 |
|
44 | 54 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
45 | 55 | tags: | |
46 | 56 | type=raw,value=latest,enable={{is_default_branch}} |
| 57 | + type=semver,pattern={{version}} |
| 58 | + type=semver,pattern={{major}}.{{minor}} |
| 59 | + type=semver,pattern={{major}} |
47 | 60 | type=sha,prefix={{branch}}- |
48 | | - type=ref,event=branch |
49 | 61 |
|
50 | 62 | - name: Build and push image |
51 | 63 | uses: docker/build-push-action@v5 |
|
58 | 70 | cache-to: type=gha,mode=max |
59 | 71 | platforms: linux/amd64,linux/arm64 |
60 | 72 |
|
61 | | - - name: Image digest |
62 | | - run: echo "Image pushed with digest ${{ steps.meta.outputs.digest }}" |
| 73 | + - name: Get version from tag or generate |
| 74 | + id: version |
| 75 | + run: | |
| 76 | + if [[ "${{ github.ref }}" == refs/tags/v* ]]; then |
| 77 | + # タグからバージョンを取得 |
| 78 | + VERSION="${GITHUB_REF#refs/tags/}" |
| 79 | + elif [[ -n "${{ github.event.inputs.version }}" ]]; then |
| 80 | + # 手動入力からバージョンを取得 |
| 81 | + VERSION="${{ github.event.inputs.version }}" |
| 82 | + else |
| 83 | + # 最新のタグを取得して自動インクリメント |
| 84 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0.0") |
| 85 | + echo "Latest tag: ${LATEST_TAG}" |
| 86 | + |
| 87 | + # バージョン番号を抽出してパッチバージョンをインクリメント |
| 88 | + VERSION=$(echo "${LATEST_TAG}" | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g') |
| 89 | + fi |
| 90 | + |
| 91 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 92 | + echo "📌 バージョン: ${VERSION}" |
| 93 | +
|
| 94 | + - name: Create and push version tag |
| 95 | + if: success() && !startsWith(github.ref, 'refs/tags/') |
| 96 | + run: | |
| 97 | + VERSION="${{ steps.version.outputs.version }}" |
| 98 | + |
| 99 | + git config user.name "github-actions[bot]" |
| 100 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 101 | + |
| 102 | + # バージョンタグを作成 |
| 103 | + git tag -a "${VERSION}" -m "Release ${VERSION}" |
| 104 | + git push origin "${VERSION}" |
| 105 | + |
| 106 | + # latestタグも更新 |
| 107 | + git tag -d latest 2>/dev/null || true |
| 108 | + git tag -a latest -m "Latest release: ${VERSION}" |
| 109 | + git push origin latest --force |
| 110 | + |
| 111 | + echo "✅ タグ ${VERSION} と latest を作成しました" |
| 112 | +
|
| 113 | + - name: Create GitHub Release |
| 114 | + if: success() && !startsWith(github.ref, 'refs/tags/') |
| 115 | + uses: actions/create-release@v1 |
| 116 | + env: |
| 117 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 118 | + with: |
| 119 | + tag_name: ${{ steps.version.outputs.version }} |
| 120 | + release_name: Release ${{ steps.version.outputs.version }} |
| 121 | + body: | |
| 122 | + ## DevContainer Base Image ${{ steps.version.outputs.version }} |
| 123 | + |
| 124 | + ### Docker Image |
| 125 | + ```bash |
| 126 | + docker pull ghcr.io/${{ github.repository }}:${{ steps.version.outputs.version }} |
| 127 | + docker pull ghcr.io/${{ github.repository }}:latest |
| 128 | + ``` |
| 129 | + |
| 130 | + ### Changes |
| 131 | + - Automated build from commit ${{ github.sha }} |
| 132 | + |
| 133 | + See [CHANGELOG.md](CHANGELOG.md) for details. |
| 134 | + draft: false |
| 135 | + prerelease: false |
0 commit comments