11# ========================================
22# DevContainerベースイメージビルドワークフロー
3- # セマンティックバージョニング対応版
3+ # 手動実行専用 - バージョン指定版
44# ========================================
5- name : Build and Push DevContainer Base Image (Semantic Versioning )
5+ name : Build and Release (Manual )
66
77on :
8- push :
9- branches :
10- - master
11- paths :
12- - ' Dockerfile'
13- - ' .github/workflows/build-image-semver.yml'
14- tags :
15- - ' v*.*.*' # v1.0.0 のようなタグをプッシュした時
168 workflow_dispatch :
179 inputs :
1810 version :
19- description : ' Version to release (e.g., v1.0.1 )'
20- required : false
11+ description : ' バージョン番号 (例: v1.0.3 または 1.0.3 )'
12+ required : true
2113 type : string
14+ create_release :
15+ description : ' GitHub Releaseを作成する'
16+ required : false
17+ type : boolean
18+ default : true
2219
2320env :
2421 REGISTRY : ghcr.io
3734 with :
3835 fetch-depth : 0
3936
37+ - name : Validate and normalize version
38+ id : version
39+ run : |
40+ VERSION="${{ github.event.inputs.version }}"
41+
42+ # v プレフィックスを追加(なければ)
43+ if [[ ! "$VERSION" =~ ^v ]]; then
44+ VERSION="v${VERSION}"
45+ fi
46+
47+ # バージョン形式のバリデーション
48+ if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
49+ echo "❌ エラー: バージョン形式が不正です"
50+ echo " 正しい形式: v1.0.3 または 1.0.3"
51+ echo " 入力された値: ${{ github.event.inputs.version }}"
52+ exit 1
53+ fi
54+
55+ echo "version=${VERSION}" >> $GITHUB_OUTPUT
56+ echo "version_short=${VERSION#v}" >> $GITHUB_OUTPUT
57+ echo "📌 バージョン: ${VERSION}"
58+
59+ - name : Check if tag already exists
60+ run : |
61+ VERSION="${{ steps.version.outputs.version }}"
62+
63+ if git ls-remote --tags origin | grep -q "refs/tags/${VERSION}$"; then
64+ echo "⚠️ 警告: タグ ${VERSION} は既に存在します"
65+ echo " 既存のタグを上書きします"
66+ else
67+ echo "✅ タグ ${VERSION} は新規作成されます"
68+ fi
69+
4070 - name : Set up Docker Buildx
4171 uses : docker/setup-buildx-action@v3
4272
@@ -53,10 +83,10 @@ jobs:
5383 with :
5484 images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
5585 tags : |
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}}
86+ type=raw,value=latest
87+ type=raw,value=${{ steps. version.outputs.version_short }}
88+ type=semver,pattern={{major}}.{{minor}},value=${{ steps.version.outputs.version }}
89+ type=semver,pattern={{major}},value=${{ steps.version.outputs.version }}
6090 type=sha,prefix=sha-
6191
6292 - name : Build and push image
@@ -70,48 +100,44 @@ jobs:
70100 cache-to : type=gha,mode=max
71101 platforms : linux/amd64,linux/arm64
72102
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-
94103 - name : Create and push version tag
95- if : success() && !startsWith(github.ref, 'refs/tags/')
104+ if : success()
96105 run : |
97106 VERSION="${{ steps.version.outputs.version }}"
98107
99108 git config user.name "github-actions[bot]"
100109 git config user.email "github-actions[bot]@users.noreply.github.com"
101110
111+ # 既存のタグを削除(ローカル)
112+ git tag -d "${VERSION}" 2>/dev/null || true
113+
102114 # バージョンタグを作成
103115 git tag -a "${VERSION}" -m "Release ${VERSION}"
104- git push origin "${VERSION}"
105116
106- # latestタグも更新
117+ # リモートにプッシュ(既存のタグがあれば上書き)
118+ git push origin "${VERSION}" --force
119+
120+ echo "✅ バージョンタグ ${VERSION} を作成しました"
121+
122+ - name : Update latest tag
123+ if : success()
124+ run : |
125+ git config user.name "github-actions[bot]"
126+ git config user.email "github-actions[bot]@users.noreply.github.com"
127+
128+ # 既存のlatestタグを削除(ローカル)
107129 git tag -d latest 2>/dev/null || true
108- git tag -a latest -m "Latest release: ${VERSION}"
130+
131+ # 現在のコミットにlatestタグを設定
132+ git tag -a latest -m "Latest release: ${{ steps.version.outputs.version }}"
133+
134+ # リモートのlatestタグを強制更新
109135 git push origin latest --force
110136
111- echo "✅ タグ ${VERSION} と latest を作成しました "
137+ echo "✅ latestタグを更新しました "
112138
113139 - name : Create GitHub Release
114- if : success() && !startsWith( github.ref, 'refs/tags/')
140+ if : success() && github.event.inputs.create_release == 'true'
115141 uses : actions/create-release@v1
116142 env :
117143 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -121,15 +147,57 @@ jobs:
121147 body : |
122148 ## DevContainer Base Image ${{ steps.version.outputs.version }}
123149
124- ### Docker Image
150+ ### 🐳 Docker Image
151+
125152 ```bash
126- docker pull ghcr.io/${{ github.repository }}:${{ steps.version.outputs.version }}
153+ # 完全バージョン指定
154+ docker pull ghcr.io/${{ github.repository }}:${{ steps.version.outputs.version_short }}
155+
156+ # 最新版
127157 docker pull ghcr.io/${{ github.repository }}:latest
128158 ```
129159
130- ### Changes
131- - Automated build from commit ${{ github.sha }}
160+ ### 📦 使用方法
161+
162+ **devcontainer.json**
163+ ```json
164+ {
165+ "image": "ghcr.io/${{ github.repository }}:${{ steps.version.outputs.version_short }}",
166+ "remoteUser": "vscode"
167+ }
168+ ```
169+
170+ ### 📋 変更内容
171+
172+ 詳細は [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/master/CHANGELOG.md) を参照してください。
132173
133- See [CHANGELOG.md](CHANGELOG.md) for details.
174+ ### 🔗 関連リンク
175+
176+ - [Docker Image](https://github.com/${{ github.repository }}/pkgs/container/devcontainer-base)
177+ - [コミット履歴](https://github.com/${{ github.repository }}/commits/${{ steps.version.outputs.version }})
134178 draft : false
135179 prerelease : false
180+
181+ - name : Summary
182+ if : success()
183+ run : |
184+ VERSION="${{ steps.version.outputs.version }}"
185+ echo "========================================="
186+ echo "✅ リリース完了!"
187+ echo "========================================="
188+ echo ""
189+ echo "📌 バージョン: ${VERSION}"
190+ echo ""
191+ echo "🐳 Dockerイメージ:"
192+ echo " - ghcr.io/${{ github.repository }}:latest"
193+ echo " - ghcr.io/${{ github.repository }}:${{ steps.version.outputs.version_short }}"
194+ echo ""
195+ echo "🏷️ Gitタグ:"
196+ echo " - ${VERSION}"
197+ echo " - latest"
198+ echo ""
199+ if [[ "${{ github.event.inputs.create_release }}" == "true" ]]; then
200+ echo "📦 GitHub Release:"
201+ echo " https://github.com/${{ github.repository }}/releases/tag/${VERSION}"
202+ fi
203+ echo ""
0 commit comments