Skip to content

Commit 19c746a

Browse files
committed
Mod: バージョンタグをプッシュした際に自動的にlatestタグを設定するように設定
1 parent 92411bd commit 19c746a

1 file changed

Lines changed: 79 additions & 6 deletions

File tree

‎.github/workflows/build-image.yml‎

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
# ========================================
22
# DevContainerベースイメージビルドワークフロー
3+
# セマンティックバージョニング対応版
34
# ========================================
4-
name: Build and Push DevContainer Base Image
5+
name: Build and Push DevContainer Base Image (Semantic Versioning)
56

67
on:
78
push:
89
branches:
910
- master
1011
paths:
1112
- 'Dockerfile'
12-
- '.github/workflows/build-image.yml'
13+
- '.github/workflows/build-image-semver.yml'
14+
tags:
15+
- 'v*.*.*' # v1.0.0 のようなタグをプッシュした時
1316
workflow_dispatch:
17+
inputs:
18+
version:
19+
description: 'Version to release (e.g., v1.0.1)'
20+
required: false
21+
type: string
1422

1523
env:
1624
REGISTRY: ghcr.io
1725
IMAGE_NAME: ${{ github.repository }}
1826

1927
permissions:
20-
contents: read
28+
contents: write
2129
packages: write
2230

2331
jobs:
@@ -26,6 +34,8 @@ jobs:
2634
steps:
2735
- name: Checkout repository
2836
uses: actions/checkout@v4
37+
with:
38+
fetch-depth: 0
2939

3040
- name: Set up Docker Buildx
3141
uses: docker/setup-buildx-action@v3
@@ -44,8 +54,10 @@ jobs:
4454
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4555
tags: |
4656
type=raw,value=latest,enable={{is_default_branch}}
57+
type=semver,pattern={{version}}
58+
type=semver,pattern={{major}}.{{minor}}
59+
type=semver,pattern={{major}}
4760
type=sha,prefix={{branch}}-
48-
type=ref,event=branch
4961
5062
- name: Build and push image
5163
uses: docker/build-push-action@v5
@@ -58,5 +70,66 @@ jobs:
5870
cache-to: type=gha,mode=max
5971
platforms: linux/amd64,linux/arm64
6072

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

Comments
 (0)