@@ -101,3 +101,159 @@ execute_process(
101101``` dockerfile
102102RUN pip install git-version-utils
103103RUN source <(git-version --property env) && echo "Building $BUILD_VERSION"
104+ ```
105+
106+ ## Docker CI Container
107+
108+ A pre-built Docker image with ` git-version-utils ` is available at
109+ ` ghcr.io/synacker/git-version-utils ` .
110+
111+ The image is based on ` python:3.13-slim ` and includes ` git ` + ` git-version-utils ` .
112+ It is designed to be used as the ** job container** in CI pipelines.
113+
114+ ### Usage
115+
116+ ``` bash
117+ # Run git-version inside the container
118+ docker run --rm \
119+ -v $( pwd) :/workspace -w /workspace \
120+ ghcr.io/synacker/git-version-utils:latest \
121+ git-version --safe-directory ' *' --property env
122+ ```
123+
124+ ### GitHub Actions — Job Outputs
125+
126+ Use ` container: ` to run the job inside the image, then parse ` git-version --property env `
127+ into ` $GITHUB_OUTPUT ` . Downstream jobs consume the values via ` needs.set-version.outputs.* ` .
128+
129+ ``` yaml
130+ name : CI with job outputs
131+
132+ on :
133+ push :
134+ branches : [main, "release/*"]
135+
136+ jobs :
137+ set-version :
138+ runs-on : ubuntu-latest
139+ container :
140+ image : ghcr.io/synacker/git-version-utils:latest
141+ options : --workdir /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}
142+ outputs :
143+ BUILD_VERSION : ${{ steps.git_version.outputs.BUILD_VERSION }}
144+ BUILD_VERSION_MAJOR : ${{ steps.git_version.outputs.BUILD_VERSION_MAJOR }}
145+ BUILD_VERSION_MINOR : ${{ steps.git_version.outputs.BUILD_VERSION_MINOR }}
146+ BUILD_VERSION_PATCH : ${{ steps.git_version.outputs.BUILD_VERSION_PATCH }}
147+ BUILD_VERSION_BUILD : ${{ steps.git_version.outputs.BUILD_VERSION_BUILD }}
148+ BUILD_VERSION_TAG : ${{ steps.git_version.outputs.BUILD_VERSION_TAG }}
149+ BUILD_VERSION_FULL : ${{ steps.git_version.outputs.BUILD_VERSION_FULL }}
150+ BUILD_VERSION_EXTENDED : ${{ steps.git_version.outputs.BUILD_VERSION_EXTENDED }}
151+ BUILD_VERSION_SHORT : ${{ steps.git_version.outputs.BUILD_VERSION_SHORT }}
152+ BUILD_VERSION_COMMIT : ${{ steps.git_version.outputs.BUILD_VERSION_COMMIT }}
153+ BUILD_VERSION_BRANCH : ${{ steps.git_version.outputs.BUILD_VERSION_BRANCH }}
154+ BUILD_VERSION_DEFAULT_BRANCH : ${{ steps.git_version.outputs.BUILD_VERSION_DEFAULT_BRANCH }}
155+ BUILD_VERSION_RELEASE_BRANCHES : ${{ steps.git_version.outputs.BUILD_VERSION_RELEASE_BRANCHES }}
156+
157+ steps :
158+ - uses : actions/checkout@v6.0.3
159+ with :
160+ fetch-depth : 0
161+
162+ - name : Extract version info
163+ id : git_version
164+ run : |
165+ while IFS='=' read -r key value; do
166+ echo "$key=$value" >> "$GITHUB_OUTPUT"
167+ done < <(git-version --property env)
168+
169+ build :
170+ runs-on : ubuntu-latest
171+ needs : set-version
172+ steps :
173+ - uses : actions/checkout@v6.0.3
174+
175+ - name : Use version info
176+ run : |
177+ echo "Building version: ${{ needs.set-version.outputs.BUILD_VERSION }}"
178+ echo "Tag: ${{ needs.set-version.outputs.BUILD_VERSION_TAG }}"
179+ ` ` `
180+
181+ ### GitHub Actions — Env File Artifact
182+
183+ A simpler approach: write the version info to a file and share it as an artifact.
184+
185+ ` ` ` yaml
186+ name : CI with env file
187+
188+ on :
189+ push :
190+ branches : [main, "release/*"]
191+
192+ jobs :
193+ set-version :
194+ runs-on : ubuntu-latest
195+ container :
196+ image : ghcr.io/synacker/git-version-utils:latest
197+ options : --workdir /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}
198+ steps :
199+ - uses : actions/checkout@v6.0.3
200+ with :
201+ fetch-depth : 0
202+
203+ - name : Generate version.env
204+ run : git-version --property env > version.env
205+
206+ - name : Upload version env file
207+ uses : actions/upload-artifact@v4
208+ with :
209+ name : version-env
210+ path : version.env
211+
212+ build :
213+ runs-on : ubuntu-latest
214+ needs : set-version
215+ steps :
216+ - uses : actions/checkout@v6.0.3
217+
218+ - name : Download version env file
219+ uses : actions/download-artifact@v4
220+ with :
221+ name : version-env
222+
223+ - name : Load version and use it
224+ run : |
225+ source version.env
226+ echo "Building version: $BUILD_VERSION"
227+ echo "Tag: $BUILD_VERSION_TAG"
228+ ` ` `
229+
230+ ### GitLab CI
231+
232+ Use the image directly and share version info via
233+ [dotenv artifacts](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportsdotenv).
234+
235+ ` ` ` yaml
236+ stages :
237+ - set-version
238+ - build
239+
240+ set-version :
241+ stage : set-version
242+ image : ghcr.io/synacker/git-version-utils:latest
243+ variables :
244+ GIT_DEPTH : 0
245+ script :
246+ - git-version --property env > version.env
247+ artifacts :
248+ reports :
249+ dotenv : version.env
250+
251+ build :
252+ stage : build
253+ image : python:3.13-slim
254+ needs :
255+ - job : set-version
256+ artifacts : true
257+ script :
258+ - echo "Building version : $BUILD_VERSION"
259+ - echo "Tag : $BUILD_VERSION_TAG"
0 commit comments