git-version-utils 0.1.0.0__tar.gz → 0.2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- git_version_utils-0.2.0.0/PKG-INFO +271 -0
- git_version_utils-0.2.0.0/README.md +259 -0
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/src/git_version/_version.py +2 -2
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/src/git_version/cli.py +11 -1
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/src/git_version/core.py +9 -1
- git_version_utils-0.2.0.0/src/git_version_utils.egg-info/PKG-INFO +271 -0
- git_version_utils-0.1.0.0/PKG-INFO +0 -115
- git_version_utils-0.1.0.0/README.md +0 -103
- git_version_utils-0.1.0.0/src/git_version_utils.egg-info/PKG-INFO +0 -115
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/MANIFEST.in +0 -0
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/pyproject.toml +0 -0
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/setup.cfg +0 -0
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/setup.py +0 -0
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/src/git_version/__init__.py +0 -0
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/src/git_version_utils.egg-info/SOURCES.txt +0 -0
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/src/git_version_utils.egg-info/dependency_links.txt +0 -0
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/src/git_version_utils.egg-info/entry_points.txt +0 -0
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/src/git_version_utils.egg-info/top_level.txt +0 -0
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/tests/test_git_version.py +0 -0
- {git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/tools/write_version.py +0 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: git-version-utils
|
|
3
|
+
Version: 0.2.0.0
|
|
4
|
+
Summary: Extract version information from a Git repository and output as environment variables
|
|
5
|
+
Author-email: Mikhail Milovidov <synacker@yandex.ru>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/synacker/git_version_utils
|
|
8
|
+
Project-URL: Repository, https://github.com/synacker/git_version_utils
|
|
9
|
+
Keywords: git,version,build,ci,cd
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# git-version-utils
|
|
14
|
+
|
|
15
|
+
Extract version information from a Git repository and output as environment variables.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install git-version-utils
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### CLI
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Print all version info
|
|
29
|
+
git-version
|
|
30
|
+
|
|
31
|
+
# Output as environment variables (useful with `source` or `eval`)
|
|
32
|
+
git-version --property env
|
|
33
|
+
|
|
34
|
+
# Custom prefix for environment variables
|
|
35
|
+
git-version --prefix MYAPP --property env
|
|
36
|
+
|
|
37
|
+
# Custom tag pattern
|
|
38
|
+
git-version --tag-pattern "release-*" --property env
|
|
39
|
+
|
|
40
|
+
# Get a single property
|
|
41
|
+
git-version --property version
|
|
42
|
+
git-version --property version_major
|
|
43
|
+
git-version --property commit
|
|
44
|
+
|
|
45
|
+
# Specify repository path
|
|
46
|
+
git-version --repo /path/to/repo --property env
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Python API
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from git_version import GitVersion
|
|
53
|
+
|
|
54
|
+
gv = GitVersion(repo_path="/path/to/repo", tag_pattern="v[0-9]*")
|
|
55
|
+
|
|
56
|
+
print(gv.version) # "1.2.3.42"
|
|
57
|
+
print(gv.version_major) # "1"
|
|
58
|
+
print(gv.version_minor) # "2"
|
|
59
|
+
print(gv.version_patch) # "3"
|
|
60
|
+
print(gv.build) # "42"
|
|
61
|
+
print(gv.tag) # "v1.2.3"
|
|
62
|
+
print(gv.branch) # "main"
|
|
63
|
+
print(gv.short) # "a1b2c3"
|
|
64
|
+
print(gv.full) # "1.2.3.42-a1b2c3"
|
|
65
|
+
print(gv.commit) # "a1b2c3d4e5f6..."
|
|
66
|
+
|
|
67
|
+
# Get all as environment variables
|
|
68
|
+
env_vars = gv.env(prefix="BUILD_VERSION")
|
|
69
|
+
for key, value in env_vars.items():
|
|
70
|
+
print(f"{key}={value}")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Environment Variables Output
|
|
74
|
+
|
|
75
|
+
With default prefix `BUILD_VERSION`:
|
|
76
|
+
|
|
77
|
+
| Variable | Example | Description |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| `BUILD_VERSION` | `1.2.3.42` | Full version: `<semver>.<build>` |
|
|
80
|
+
| `BUILD_VERSION_MAJOR` | `1` | Major version component |
|
|
81
|
+
| `BUILD_VERSION_MINOR` | `2` | Minor version component |
|
|
82
|
+
| `BUILD_VERSION_PATCH` | `3` | Patch version component |
|
|
83
|
+
| `BUILD_VERSION_BUILD` | `42` | Commits since last tag |
|
|
84
|
+
| `BUILD_VERSION_TAG` | `v1.2.3` | Latest matching git tag |
|
|
85
|
+
| `BUILD_VERSION_FULL` | `1.2.3.42-a1b2c3` | Version with commit hash |
|
|
86
|
+
| `BUILD_VERSION_EXTENDED` | `1.2.3.42-a1b2c3` | Full if build>0, else version |
|
|
87
|
+
| `BUILD_VERSION_SHORT` | `a1b2c3` | Short 6-char commit hash |
|
|
88
|
+
| `BUILD_VERSION_COMMIT` | `a1b2c3d4...` | Full 40-char commit hash |
|
|
89
|
+
| `BUILD_VERSION_BRANCH` | `main` | Current branch name |
|
|
90
|
+
| `BUILD_VERSION_DEFAULT_BRANCH` | `master` | Default branch from git config |
|
|
91
|
+
|
|
92
|
+
## CI/CD Integration
|
|
93
|
+
|
|
94
|
+
### Shell (source)
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
source <(git-version --property env)
|
|
98
|
+
echo "$BUILD_VERSION"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### CMake
|
|
102
|
+
|
|
103
|
+
```cmake
|
|
104
|
+
execute_process(
|
|
105
|
+
COMMAND git-version --property env
|
|
106
|
+
OUTPUT_VARIABLE GIT_VERSION_ENV
|
|
107
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
108
|
+
)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Docker
|
|
112
|
+
|
|
113
|
+
```dockerfile
|
|
114
|
+
RUN pip install git-version-utils
|
|
115
|
+
RUN source <(git-version --property env) && echo "Building $BUILD_VERSION"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Docker CI Container
|
|
119
|
+
|
|
120
|
+
A pre-built Docker image with `git-version-utils` is available at
|
|
121
|
+
`ghcr.io/synacker/git-version-utils`.
|
|
122
|
+
|
|
123
|
+
The image is based on `python:3.13-slim` and includes `git` + `git-version-utils`.
|
|
124
|
+
It is designed to be used as the **job container** in CI pipelines.
|
|
125
|
+
|
|
126
|
+
### Usage
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Run git-version inside the container
|
|
130
|
+
docker run --rm \
|
|
131
|
+
-v $(pwd):/workspace -w /workspace \
|
|
132
|
+
ghcr.io/synacker/git-version-utils:latest \
|
|
133
|
+
git-version --safe-directory '*' --property env
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### GitHub Actions — Job Outputs
|
|
137
|
+
|
|
138
|
+
Use `container:` to run the job inside the image, then parse `git-version --property env`
|
|
139
|
+
into `$GITHUB_OUTPUT`. Downstream jobs consume the values via `needs.set-version.outputs.*`.
|
|
140
|
+
|
|
141
|
+
```yaml
|
|
142
|
+
name: CI with job outputs
|
|
143
|
+
|
|
144
|
+
on:
|
|
145
|
+
push:
|
|
146
|
+
branches: [main, "release/*"]
|
|
147
|
+
|
|
148
|
+
jobs:
|
|
149
|
+
set-version:
|
|
150
|
+
runs-on: ubuntu-latest
|
|
151
|
+
container:
|
|
152
|
+
image: ghcr.io/synacker/git-version-utils:latest
|
|
153
|
+
options: --workdir /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}
|
|
154
|
+
outputs:
|
|
155
|
+
BUILD_VERSION: ${{ steps.git_version.outputs.BUILD_VERSION }}
|
|
156
|
+
BUILD_VERSION_MAJOR: ${{ steps.git_version.outputs.BUILD_VERSION_MAJOR }}
|
|
157
|
+
BUILD_VERSION_MINOR: ${{ steps.git_version.outputs.BUILD_VERSION_MINOR }}
|
|
158
|
+
BUILD_VERSION_PATCH: ${{ steps.git_version.outputs.BUILD_VERSION_PATCH }}
|
|
159
|
+
BUILD_VERSION_BUILD: ${{ steps.git_version.outputs.BUILD_VERSION_BUILD }}
|
|
160
|
+
BUILD_VERSION_TAG: ${{ steps.git_version.outputs.BUILD_VERSION_TAG }}
|
|
161
|
+
BUILD_VERSION_FULL: ${{ steps.git_version.outputs.BUILD_VERSION_FULL }}
|
|
162
|
+
BUILD_VERSION_EXTENDED: ${{ steps.git_version.outputs.BUILD_VERSION_EXTENDED }}
|
|
163
|
+
BUILD_VERSION_SHORT: ${{ steps.git_version.outputs.BUILD_VERSION_SHORT }}
|
|
164
|
+
BUILD_VERSION_COMMIT: ${{ steps.git_version.outputs.BUILD_VERSION_COMMIT }}
|
|
165
|
+
BUILD_VERSION_BRANCH: ${{ steps.git_version.outputs.BUILD_VERSION_BRANCH }}
|
|
166
|
+
BUILD_VERSION_DEFAULT_BRANCH: ${{ steps.git_version.outputs.BUILD_VERSION_DEFAULT_BRANCH }}
|
|
167
|
+
BUILD_VERSION_RELEASE_BRANCHES: ${{ steps.git_version.outputs.BUILD_VERSION_RELEASE_BRANCHES }}
|
|
168
|
+
|
|
169
|
+
steps:
|
|
170
|
+
- uses: actions/checkout@v6.0.3
|
|
171
|
+
with:
|
|
172
|
+
fetch-depth: 0
|
|
173
|
+
|
|
174
|
+
- name: Extract version info
|
|
175
|
+
id: git_version
|
|
176
|
+
run: |
|
|
177
|
+
while IFS='=' read -r key value; do
|
|
178
|
+
echo "$key=$value" >> "$GITHUB_OUTPUT"
|
|
179
|
+
done < <(git-version --property env)
|
|
180
|
+
|
|
181
|
+
build:
|
|
182
|
+
runs-on: ubuntu-latest
|
|
183
|
+
needs: set-version
|
|
184
|
+
steps:
|
|
185
|
+
- uses: actions/checkout@v6.0.3
|
|
186
|
+
|
|
187
|
+
- name: Use version info
|
|
188
|
+
run: |
|
|
189
|
+
echo "Building version: ${{ needs.set-version.outputs.BUILD_VERSION }}"
|
|
190
|
+
echo "Tag: ${{ needs.set-version.outputs.BUILD_VERSION_TAG }}"
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### GitHub Actions — Env File Artifact
|
|
194
|
+
|
|
195
|
+
A simpler approach: write the version info to a file and share it as an artifact.
|
|
196
|
+
|
|
197
|
+
```yaml
|
|
198
|
+
name: CI with env file
|
|
199
|
+
|
|
200
|
+
on:
|
|
201
|
+
push:
|
|
202
|
+
branches: [main, "release/*"]
|
|
203
|
+
|
|
204
|
+
jobs:
|
|
205
|
+
set-version:
|
|
206
|
+
runs-on: ubuntu-latest
|
|
207
|
+
container:
|
|
208
|
+
image: ghcr.io/synacker/git-version-utils:latest
|
|
209
|
+
options: --workdir /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}
|
|
210
|
+
steps:
|
|
211
|
+
- uses: actions/checkout@v6.0.3
|
|
212
|
+
with:
|
|
213
|
+
fetch-depth: 0
|
|
214
|
+
|
|
215
|
+
- name: Generate version.env
|
|
216
|
+
run: git-version --property env > version.env
|
|
217
|
+
|
|
218
|
+
- name: Upload version env file
|
|
219
|
+
uses: actions/upload-artifact@v4
|
|
220
|
+
with:
|
|
221
|
+
name: version-env
|
|
222
|
+
path: version.env
|
|
223
|
+
|
|
224
|
+
build:
|
|
225
|
+
runs-on: ubuntu-latest
|
|
226
|
+
needs: set-version
|
|
227
|
+
steps:
|
|
228
|
+
- uses: actions/checkout@v6.0.3
|
|
229
|
+
|
|
230
|
+
- name: Download version env file
|
|
231
|
+
uses: actions/download-artifact@v4
|
|
232
|
+
with:
|
|
233
|
+
name: version-env
|
|
234
|
+
|
|
235
|
+
- name: Load version and use it
|
|
236
|
+
run: |
|
|
237
|
+
source version.env
|
|
238
|
+
echo "Building version: $BUILD_VERSION"
|
|
239
|
+
echo "Tag: $BUILD_VERSION_TAG"
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### GitLab CI
|
|
243
|
+
|
|
244
|
+
Use the image directly and share version info via
|
|
245
|
+
[dotenv artifacts](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportsdotenv).
|
|
246
|
+
|
|
247
|
+
```yaml
|
|
248
|
+
stages:
|
|
249
|
+
- set-version
|
|
250
|
+
- build
|
|
251
|
+
|
|
252
|
+
set-version:
|
|
253
|
+
stage: set-version
|
|
254
|
+
image: ghcr.io/synacker/git-version-utils:latest
|
|
255
|
+
variables:
|
|
256
|
+
GIT_DEPTH: 0
|
|
257
|
+
script:
|
|
258
|
+
- git-version --property env > version.env
|
|
259
|
+
artifacts:
|
|
260
|
+
reports:
|
|
261
|
+
dotenv: version.env
|
|
262
|
+
|
|
263
|
+
build:
|
|
264
|
+
stage: build
|
|
265
|
+
image: python:3.13-slim
|
|
266
|
+
needs:
|
|
267
|
+
- job: set-version
|
|
268
|
+
artifacts: true
|
|
269
|
+
script:
|
|
270
|
+
- echo "Building version: $BUILD_VERSION"
|
|
271
|
+
- echo "Tag: $BUILD_VERSION_TAG"
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# git-version-utils
|
|
2
|
+
|
|
3
|
+
Extract version information from a Git repository and output as environment variables.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install git-version-utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### CLI
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Print all version info
|
|
17
|
+
git-version
|
|
18
|
+
|
|
19
|
+
# Output as environment variables (useful with `source` or `eval`)
|
|
20
|
+
git-version --property env
|
|
21
|
+
|
|
22
|
+
# Custom prefix for environment variables
|
|
23
|
+
git-version --prefix MYAPP --property env
|
|
24
|
+
|
|
25
|
+
# Custom tag pattern
|
|
26
|
+
git-version --tag-pattern "release-*" --property env
|
|
27
|
+
|
|
28
|
+
# Get a single property
|
|
29
|
+
git-version --property version
|
|
30
|
+
git-version --property version_major
|
|
31
|
+
git-version --property commit
|
|
32
|
+
|
|
33
|
+
# Specify repository path
|
|
34
|
+
git-version --repo /path/to/repo --property env
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Python API
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from git_version import GitVersion
|
|
41
|
+
|
|
42
|
+
gv = GitVersion(repo_path="/path/to/repo", tag_pattern="v[0-9]*")
|
|
43
|
+
|
|
44
|
+
print(gv.version) # "1.2.3.42"
|
|
45
|
+
print(gv.version_major) # "1"
|
|
46
|
+
print(gv.version_minor) # "2"
|
|
47
|
+
print(gv.version_patch) # "3"
|
|
48
|
+
print(gv.build) # "42"
|
|
49
|
+
print(gv.tag) # "v1.2.3"
|
|
50
|
+
print(gv.branch) # "main"
|
|
51
|
+
print(gv.short) # "a1b2c3"
|
|
52
|
+
print(gv.full) # "1.2.3.42-a1b2c3"
|
|
53
|
+
print(gv.commit) # "a1b2c3d4e5f6..."
|
|
54
|
+
|
|
55
|
+
# Get all as environment variables
|
|
56
|
+
env_vars = gv.env(prefix="BUILD_VERSION")
|
|
57
|
+
for key, value in env_vars.items():
|
|
58
|
+
print(f"{key}={value}")
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Environment Variables Output
|
|
62
|
+
|
|
63
|
+
With default prefix `BUILD_VERSION`:
|
|
64
|
+
|
|
65
|
+
| Variable | Example | Description |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| `BUILD_VERSION` | `1.2.3.42` | Full version: `<semver>.<build>` |
|
|
68
|
+
| `BUILD_VERSION_MAJOR` | `1` | Major version component |
|
|
69
|
+
| `BUILD_VERSION_MINOR` | `2` | Minor version component |
|
|
70
|
+
| `BUILD_VERSION_PATCH` | `3` | Patch version component |
|
|
71
|
+
| `BUILD_VERSION_BUILD` | `42` | Commits since last tag |
|
|
72
|
+
| `BUILD_VERSION_TAG` | `v1.2.3` | Latest matching git tag |
|
|
73
|
+
| `BUILD_VERSION_FULL` | `1.2.3.42-a1b2c3` | Version with commit hash |
|
|
74
|
+
| `BUILD_VERSION_EXTENDED` | `1.2.3.42-a1b2c3` | Full if build>0, else version |
|
|
75
|
+
| `BUILD_VERSION_SHORT` | `a1b2c3` | Short 6-char commit hash |
|
|
76
|
+
| `BUILD_VERSION_COMMIT` | `a1b2c3d4...` | Full 40-char commit hash |
|
|
77
|
+
| `BUILD_VERSION_BRANCH` | `main` | Current branch name |
|
|
78
|
+
| `BUILD_VERSION_DEFAULT_BRANCH` | `master` | Default branch from git config |
|
|
79
|
+
|
|
80
|
+
## CI/CD Integration
|
|
81
|
+
|
|
82
|
+
### Shell (source)
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
source <(git-version --property env)
|
|
86
|
+
echo "$BUILD_VERSION"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### CMake
|
|
90
|
+
|
|
91
|
+
```cmake
|
|
92
|
+
execute_process(
|
|
93
|
+
COMMAND git-version --property env
|
|
94
|
+
OUTPUT_VARIABLE GIT_VERSION_ENV
|
|
95
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Docker
|
|
100
|
+
|
|
101
|
+
```dockerfile
|
|
102
|
+
RUN pip install git-version-utils
|
|
103
|
+
RUN 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"
|
|
@@ -22,6 +22,12 @@ def main() -> None:
|
|
|
22
22
|
default="v[0-9]*",
|
|
23
23
|
help="Glob pattern to match version tags (default: v[0-9]*)",
|
|
24
24
|
)
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
"--safe-directory",
|
|
27
|
+
default=None,
|
|
28
|
+
help="Pass ``-c safe.directory=<value>`` to git commands. "
|
|
29
|
+
"Use ``'*'`` to allow all directories (useful in Docker containers).",
|
|
30
|
+
)
|
|
25
31
|
parser.add_argument(
|
|
26
32
|
"--property", "-P",
|
|
27
33
|
choices=[
|
|
@@ -34,7 +40,11 @@ def main() -> None:
|
|
|
34
40
|
)
|
|
35
41
|
args = parser.parse_args()
|
|
36
42
|
|
|
37
|
-
gv = GitVersion(
|
|
43
|
+
gv = GitVersion(
|
|
44
|
+
repo_path=args.repo,
|
|
45
|
+
tag_pattern=args.tag_pattern,
|
|
46
|
+
safe_directory=args.safe_directory,
|
|
47
|
+
)
|
|
38
48
|
|
|
39
49
|
if args.property == "env":
|
|
40
50
|
for key, value in gv.env(prefix=args.prefix).items():
|
|
@@ -13,6 +13,8 @@ class GitVersion:
|
|
|
13
13
|
tag_pattern: Glob pattern to match version tags (default: "v[0-9]*").
|
|
14
14
|
release_branches: List of branch patterns considered as release branches.
|
|
15
15
|
Defaults to [default_branch, "release/*"].
|
|
16
|
+
safe_directory: Pass ``-c safe.directory=<value>`` to every git command.
|
|
17
|
+
Use ``"*"`` to allow all directories (useful in Docker containers).
|
|
16
18
|
"""
|
|
17
19
|
|
|
18
20
|
def __init__(
|
|
@@ -20,16 +22,22 @@ class GitVersion:
|
|
|
20
22
|
repo_path: str | None = None,
|
|
21
23
|
tag_pattern: str = "v[0-9]*",
|
|
22
24
|
release_branches: list[str] | None = None,
|
|
25
|
+
safe_directory: str | None = None,
|
|
23
26
|
):
|
|
24
27
|
self.repo_path = os.path.abspath(repo_path or os.getcwd())
|
|
25
28
|
self.tag_pattern = tag_pattern
|
|
26
29
|
self._release_branches = release_branches
|
|
30
|
+
self._safe_directory = safe_directory
|
|
27
31
|
|
|
28
32
|
def _git(self, *args: str) -> str:
|
|
29
33
|
"""Execute a git command safely and return stripped stdout."""
|
|
30
34
|
try:
|
|
35
|
+
cmd = ["git", "-C", self.repo_path]
|
|
36
|
+
if self._safe_directory is not None:
|
|
37
|
+
cmd.extend(["-c", f"safe.directory={self._safe_directory}"])
|
|
38
|
+
cmd.extend(args)
|
|
31
39
|
result = subprocess.run(
|
|
32
|
-
|
|
40
|
+
cmd,
|
|
33
41
|
capture_output=True,
|
|
34
42
|
text=True,
|
|
35
43
|
check=True,
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: git-version-utils
|
|
3
|
+
Version: 0.2.0.0
|
|
4
|
+
Summary: Extract version information from a Git repository and output as environment variables
|
|
5
|
+
Author-email: Mikhail Milovidov <synacker@yandex.ru>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/synacker/git_version_utils
|
|
8
|
+
Project-URL: Repository, https://github.com/synacker/git_version_utils
|
|
9
|
+
Keywords: git,version,build,ci,cd
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# git-version-utils
|
|
14
|
+
|
|
15
|
+
Extract version information from a Git repository and output as environment variables.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install git-version-utils
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### CLI
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Print all version info
|
|
29
|
+
git-version
|
|
30
|
+
|
|
31
|
+
# Output as environment variables (useful with `source` or `eval`)
|
|
32
|
+
git-version --property env
|
|
33
|
+
|
|
34
|
+
# Custom prefix for environment variables
|
|
35
|
+
git-version --prefix MYAPP --property env
|
|
36
|
+
|
|
37
|
+
# Custom tag pattern
|
|
38
|
+
git-version --tag-pattern "release-*" --property env
|
|
39
|
+
|
|
40
|
+
# Get a single property
|
|
41
|
+
git-version --property version
|
|
42
|
+
git-version --property version_major
|
|
43
|
+
git-version --property commit
|
|
44
|
+
|
|
45
|
+
# Specify repository path
|
|
46
|
+
git-version --repo /path/to/repo --property env
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Python API
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from git_version import GitVersion
|
|
53
|
+
|
|
54
|
+
gv = GitVersion(repo_path="/path/to/repo", tag_pattern="v[0-9]*")
|
|
55
|
+
|
|
56
|
+
print(gv.version) # "1.2.3.42"
|
|
57
|
+
print(gv.version_major) # "1"
|
|
58
|
+
print(gv.version_minor) # "2"
|
|
59
|
+
print(gv.version_patch) # "3"
|
|
60
|
+
print(gv.build) # "42"
|
|
61
|
+
print(gv.tag) # "v1.2.3"
|
|
62
|
+
print(gv.branch) # "main"
|
|
63
|
+
print(gv.short) # "a1b2c3"
|
|
64
|
+
print(gv.full) # "1.2.3.42-a1b2c3"
|
|
65
|
+
print(gv.commit) # "a1b2c3d4e5f6..."
|
|
66
|
+
|
|
67
|
+
# Get all as environment variables
|
|
68
|
+
env_vars = gv.env(prefix="BUILD_VERSION")
|
|
69
|
+
for key, value in env_vars.items():
|
|
70
|
+
print(f"{key}={value}")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Environment Variables Output
|
|
74
|
+
|
|
75
|
+
With default prefix `BUILD_VERSION`:
|
|
76
|
+
|
|
77
|
+
| Variable | Example | Description |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| `BUILD_VERSION` | `1.2.3.42` | Full version: `<semver>.<build>` |
|
|
80
|
+
| `BUILD_VERSION_MAJOR` | `1` | Major version component |
|
|
81
|
+
| `BUILD_VERSION_MINOR` | `2` | Minor version component |
|
|
82
|
+
| `BUILD_VERSION_PATCH` | `3` | Patch version component |
|
|
83
|
+
| `BUILD_VERSION_BUILD` | `42` | Commits since last tag |
|
|
84
|
+
| `BUILD_VERSION_TAG` | `v1.2.3` | Latest matching git tag |
|
|
85
|
+
| `BUILD_VERSION_FULL` | `1.2.3.42-a1b2c3` | Version with commit hash |
|
|
86
|
+
| `BUILD_VERSION_EXTENDED` | `1.2.3.42-a1b2c3` | Full if build>0, else version |
|
|
87
|
+
| `BUILD_VERSION_SHORT` | `a1b2c3` | Short 6-char commit hash |
|
|
88
|
+
| `BUILD_VERSION_COMMIT` | `a1b2c3d4...` | Full 40-char commit hash |
|
|
89
|
+
| `BUILD_VERSION_BRANCH` | `main` | Current branch name |
|
|
90
|
+
| `BUILD_VERSION_DEFAULT_BRANCH` | `master` | Default branch from git config |
|
|
91
|
+
|
|
92
|
+
## CI/CD Integration
|
|
93
|
+
|
|
94
|
+
### Shell (source)
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
source <(git-version --property env)
|
|
98
|
+
echo "$BUILD_VERSION"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### CMake
|
|
102
|
+
|
|
103
|
+
```cmake
|
|
104
|
+
execute_process(
|
|
105
|
+
COMMAND git-version --property env
|
|
106
|
+
OUTPUT_VARIABLE GIT_VERSION_ENV
|
|
107
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
108
|
+
)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Docker
|
|
112
|
+
|
|
113
|
+
```dockerfile
|
|
114
|
+
RUN pip install git-version-utils
|
|
115
|
+
RUN source <(git-version --property env) && echo "Building $BUILD_VERSION"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Docker CI Container
|
|
119
|
+
|
|
120
|
+
A pre-built Docker image with `git-version-utils` is available at
|
|
121
|
+
`ghcr.io/synacker/git-version-utils`.
|
|
122
|
+
|
|
123
|
+
The image is based on `python:3.13-slim` and includes `git` + `git-version-utils`.
|
|
124
|
+
It is designed to be used as the **job container** in CI pipelines.
|
|
125
|
+
|
|
126
|
+
### Usage
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Run git-version inside the container
|
|
130
|
+
docker run --rm \
|
|
131
|
+
-v $(pwd):/workspace -w /workspace \
|
|
132
|
+
ghcr.io/synacker/git-version-utils:latest \
|
|
133
|
+
git-version --safe-directory '*' --property env
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### GitHub Actions — Job Outputs
|
|
137
|
+
|
|
138
|
+
Use `container:` to run the job inside the image, then parse `git-version --property env`
|
|
139
|
+
into `$GITHUB_OUTPUT`. Downstream jobs consume the values via `needs.set-version.outputs.*`.
|
|
140
|
+
|
|
141
|
+
```yaml
|
|
142
|
+
name: CI with job outputs
|
|
143
|
+
|
|
144
|
+
on:
|
|
145
|
+
push:
|
|
146
|
+
branches: [main, "release/*"]
|
|
147
|
+
|
|
148
|
+
jobs:
|
|
149
|
+
set-version:
|
|
150
|
+
runs-on: ubuntu-latest
|
|
151
|
+
container:
|
|
152
|
+
image: ghcr.io/synacker/git-version-utils:latest
|
|
153
|
+
options: --workdir /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}
|
|
154
|
+
outputs:
|
|
155
|
+
BUILD_VERSION: ${{ steps.git_version.outputs.BUILD_VERSION }}
|
|
156
|
+
BUILD_VERSION_MAJOR: ${{ steps.git_version.outputs.BUILD_VERSION_MAJOR }}
|
|
157
|
+
BUILD_VERSION_MINOR: ${{ steps.git_version.outputs.BUILD_VERSION_MINOR }}
|
|
158
|
+
BUILD_VERSION_PATCH: ${{ steps.git_version.outputs.BUILD_VERSION_PATCH }}
|
|
159
|
+
BUILD_VERSION_BUILD: ${{ steps.git_version.outputs.BUILD_VERSION_BUILD }}
|
|
160
|
+
BUILD_VERSION_TAG: ${{ steps.git_version.outputs.BUILD_VERSION_TAG }}
|
|
161
|
+
BUILD_VERSION_FULL: ${{ steps.git_version.outputs.BUILD_VERSION_FULL }}
|
|
162
|
+
BUILD_VERSION_EXTENDED: ${{ steps.git_version.outputs.BUILD_VERSION_EXTENDED }}
|
|
163
|
+
BUILD_VERSION_SHORT: ${{ steps.git_version.outputs.BUILD_VERSION_SHORT }}
|
|
164
|
+
BUILD_VERSION_COMMIT: ${{ steps.git_version.outputs.BUILD_VERSION_COMMIT }}
|
|
165
|
+
BUILD_VERSION_BRANCH: ${{ steps.git_version.outputs.BUILD_VERSION_BRANCH }}
|
|
166
|
+
BUILD_VERSION_DEFAULT_BRANCH: ${{ steps.git_version.outputs.BUILD_VERSION_DEFAULT_BRANCH }}
|
|
167
|
+
BUILD_VERSION_RELEASE_BRANCHES: ${{ steps.git_version.outputs.BUILD_VERSION_RELEASE_BRANCHES }}
|
|
168
|
+
|
|
169
|
+
steps:
|
|
170
|
+
- uses: actions/checkout@v6.0.3
|
|
171
|
+
with:
|
|
172
|
+
fetch-depth: 0
|
|
173
|
+
|
|
174
|
+
- name: Extract version info
|
|
175
|
+
id: git_version
|
|
176
|
+
run: |
|
|
177
|
+
while IFS='=' read -r key value; do
|
|
178
|
+
echo "$key=$value" >> "$GITHUB_OUTPUT"
|
|
179
|
+
done < <(git-version --property env)
|
|
180
|
+
|
|
181
|
+
build:
|
|
182
|
+
runs-on: ubuntu-latest
|
|
183
|
+
needs: set-version
|
|
184
|
+
steps:
|
|
185
|
+
- uses: actions/checkout@v6.0.3
|
|
186
|
+
|
|
187
|
+
- name: Use version info
|
|
188
|
+
run: |
|
|
189
|
+
echo "Building version: ${{ needs.set-version.outputs.BUILD_VERSION }}"
|
|
190
|
+
echo "Tag: ${{ needs.set-version.outputs.BUILD_VERSION_TAG }}"
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### GitHub Actions — Env File Artifact
|
|
194
|
+
|
|
195
|
+
A simpler approach: write the version info to a file and share it as an artifact.
|
|
196
|
+
|
|
197
|
+
```yaml
|
|
198
|
+
name: CI with env file
|
|
199
|
+
|
|
200
|
+
on:
|
|
201
|
+
push:
|
|
202
|
+
branches: [main, "release/*"]
|
|
203
|
+
|
|
204
|
+
jobs:
|
|
205
|
+
set-version:
|
|
206
|
+
runs-on: ubuntu-latest
|
|
207
|
+
container:
|
|
208
|
+
image: ghcr.io/synacker/git-version-utils:latest
|
|
209
|
+
options: --workdir /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}
|
|
210
|
+
steps:
|
|
211
|
+
- uses: actions/checkout@v6.0.3
|
|
212
|
+
with:
|
|
213
|
+
fetch-depth: 0
|
|
214
|
+
|
|
215
|
+
- name: Generate version.env
|
|
216
|
+
run: git-version --property env > version.env
|
|
217
|
+
|
|
218
|
+
- name: Upload version env file
|
|
219
|
+
uses: actions/upload-artifact@v4
|
|
220
|
+
with:
|
|
221
|
+
name: version-env
|
|
222
|
+
path: version.env
|
|
223
|
+
|
|
224
|
+
build:
|
|
225
|
+
runs-on: ubuntu-latest
|
|
226
|
+
needs: set-version
|
|
227
|
+
steps:
|
|
228
|
+
- uses: actions/checkout@v6.0.3
|
|
229
|
+
|
|
230
|
+
- name: Download version env file
|
|
231
|
+
uses: actions/download-artifact@v4
|
|
232
|
+
with:
|
|
233
|
+
name: version-env
|
|
234
|
+
|
|
235
|
+
- name: Load version and use it
|
|
236
|
+
run: |
|
|
237
|
+
source version.env
|
|
238
|
+
echo "Building version: $BUILD_VERSION"
|
|
239
|
+
echo "Tag: $BUILD_VERSION_TAG"
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### GitLab CI
|
|
243
|
+
|
|
244
|
+
Use the image directly and share version info via
|
|
245
|
+
[dotenv artifacts](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportsdotenv).
|
|
246
|
+
|
|
247
|
+
```yaml
|
|
248
|
+
stages:
|
|
249
|
+
- set-version
|
|
250
|
+
- build
|
|
251
|
+
|
|
252
|
+
set-version:
|
|
253
|
+
stage: set-version
|
|
254
|
+
image: ghcr.io/synacker/git-version-utils:latest
|
|
255
|
+
variables:
|
|
256
|
+
GIT_DEPTH: 0
|
|
257
|
+
script:
|
|
258
|
+
- git-version --property env > version.env
|
|
259
|
+
artifacts:
|
|
260
|
+
reports:
|
|
261
|
+
dotenv: version.env
|
|
262
|
+
|
|
263
|
+
build:
|
|
264
|
+
stage: build
|
|
265
|
+
image: python:3.13-slim
|
|
266
|
+
needs:
|
|
267
|
+
- job: set-version
|
|
268
|
+
artifacts: true
|
|
269
|
+
script:
|
|
270
|
+
- echo "Building version: $BUILD_VERSION"
|
|
271
|
+
- echo "Tag: $BUILD_VERSION_TAG"
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: git-version-utils
|
|
3
|
-
Version: 0.1.0.0
|
|
4
|
-
Summary: Extract version information from a Git repository and output as environment variables
|
|
5
|
-
Author-email: Mikhail Milovidov <synacker@yandex.ru>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/synacker/git_version_utils
|
|
8
|
-
Project-URL: Repository, https://github.com/synacker/git_version_utils
|
|
9
|
-
Keywords: git,version,build,ci,cd
|
|
10
|
-
Requires-Python: >=3.10
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
|
|
13
|
-
# git-version-utils
|
|
14
|
-
|
|
15
|
-
Extract version information from a Git repository and output as environment variables.
|
|
16
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
pip install git-version-utils
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Usage
|
|
24
|
-
|
|
25
|
-
### CLI
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
# Print all version info
|
|
29
|
-
git-version
|
|
30
|
-
|
|
31
|
-
# Output as environment variables (useful with `source` or `eval`)
|
|
32
|
-
git-version --property env
|
|
33
|
-
|
|
34
|
-
# Custom prefix for environment variables
|
|
35
|
-
git-version --prefix MYAPP --property env
|
|
36
|
-
|
|
37
|
-
# Custom tag pattern
|
|
38
|
-
git-version --tag-pattern "release-*" --property env
|
|
39
|
-
|
|
40
|
-
# Get a single property
|
|
41
|
-
git-version --property version
|
|
42
|
-
git-version --property version_major
|
|
43
|
-
git-version --property commit
|
|
44
|
-
|
|
45
|
-
# Specify repository path
|
|
46
|
-
git-version --repo /path/to/repo --property env
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### Python API
|
|
50
|
-
|
|
51
|
-
```python
|
|
52
|
-
from git_version import GitVersion
|
|
53
|
-
|
|
54
|
-
gv = GitVersion(repo_path="/path/to/repo", tag_pattern="v[0-9]*")
|
|
55
|
-
|
|
56
|
-
print(gv.version) # "1.2.3.42"
|
|
57
|
-
print(gv.version_major) # "1"
|
|
58
|
-
print(gv.version_minor) # "2"
|
|
59
|
-
print(gv.version_patch) # "3"
|
|
60
|
-
print(gv.build) # "42"
|
|
61
|
-
print(gv.tag) # "v1.2.3"
|
|
62
|
-
print(gv.branch) # "main"
|
|
63
|
-
print(gv.short) # "a1b2c3"
|
|
64
|
-
print(gv.full) # "1.2.3.42-a1b2c3"
|
|
65
|
-
print(gv.commit) # "a1b2c3d4e5f6..."
|
|
66
|
-
|
|
67
|
-
# Get all as environment variables
|
|
68
|
-
env_vars = gv.env(prefix="BUILD_VERSION")
|
|
69
|
-
for key, value in env_vars.items():
|
|
70
|
-
print(f"{key}={value}")
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## Environment Variables Output
|
|
74
|
-
|
|
75
|
-
With default prefix `BUILD_VERSION`:
|
|
76
|
-
|
|
77
|
-
| Variable | Example | Description |
|
|
78
|
-
|---|---|---|
|
|
79
|
-
| `BUILD_VERSION` | `1.2.3.42` | Full version: `<semver>.<build>` |
|
|
80
|
-
| `BUILD_VERSION_MAJOR` | `1` | Major version component |
|
|
81
|
-
| `BUILD_VERSION_MINOR` | `2` | Minor version component |
|
|
82
|
-
| `BUILD_VERSION_PATCH` | `3` | Patch version component |
|
|
83
|
-
| `BUILD_VERSION_BUILD` | `42` | Commits since last tag |
|
|
84
|
-
| `BUILD_VERSION_TAG` | `v1.2.3` | Latest matching git tag |
|
|
85
|
-
| `BUILD_VERSION_FULL` | `1.2.3.42-a1b2c3` | Version with commit hash |
|
|
86
|
-
| `BUILD_VERSION_EXTENDED` | `1.2.3.42-a1b2c3` | Full if build>0, else version |
|
|
87
|
-
| `BUILD_VERSION_SHORT` | `a1b2c3` | Short 6-char commit hash |
|
|
88
|
-
| `BUILD_VERSION_COMMIT` | `a1b2c3d4...` | Full 40-char commit hash |
|
|
89
|
-
| `BUILD_VERSION_BRANCH` | `main` | Current branch name |
|
|
90
|
-
| `BUILD_VERSION_DEFAULT_BRANCH` | `master` | Default branch from git config |
|
|
91
|
-
|
|
92
|
-
## CI/CD Integration
|
|
93
|
-
|
|
94
|
-
### Shell (source)
|
|
95
|
-
|
|
96
|
-
```bash
|
|
97
|
-
source <(git-version --property env)
|
|
98
|
-
echo "$BUILD_VERSION"
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### CMake
|
|
102
|
-
|
|
103
|
-
```cmake
|
|
104
|
-
execute_process(
|
|
105
|
-
COMMAND git-version --property env
|
|
106
|
-
OUTPUT_VARIABLE GIT_VERSION_ENV
|
|
107
|
-
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
108
|
-
)
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### Docker
|
|
112
|
-
|
|
113
|
-
```dockerfile
|
|
114
|
-
RUN pip install git-version-utils
|
|
115
|
-
RUN source <(git-version --property env) && echo "Building $BUILD_VERSION"
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# git-version-utils
|
|
2
|
-
|
|
3
|
-
Extract version information from a Git repository and output as environment variables.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pip install git-version-utils
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
### CLI
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
# Print all version info
|
|
17
|
-
git-version
|
|
18
|
-
|
|
19
|
-
# Output as environment variables (useful with `source` or `eval`)
|
|
20
|
-
git-version --property env
|
|
21
|
-
|
|
22
|
-
# Custom prefix for environment variables
|
|
23
|
-
git-version --prefix MYAPP --property env
|
|
24
|
-
|
|
25
|
-
# Custom tag pattern
|
|
26
|
-
git-version --tag-pattern "release-*" --property env
|
|
27
|
-
|
|
28
|
-
# Get a single property
|
|
29
|
-
git-version --property version
|
|
30
|
-
git-version --property version_major
|
|
31
|
-
git-version --property commit
|
|
32
|
-
|
|
33
|
-
# Specify repository path
|
|
34
|
-
git-version --repo /path/to/repo --property env
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Python API
|
|
38
|
-
|
|
39
|
-
```python
|
|
40
|
-
from git_version import GitVersion
|
|
41
|
-
|
|
42
|
-
gv = GitVersion(repo_path="/path/to/repo", tag_pattern="v[0-9]*")
|
|
43
|
-
|
|
44
|
-
print(gv.version) # "1.2.3.42"
|
|
45
|
-
print(gv.version_major) # "1"
|
|
46
|
-
print(gv.version_minor) # "2"
|
|
47
|
-
print(gv.version_patch) # "3"
|
|
48
|
-
print(gv.build) # "42"
|
|
49
|
-
print(gv.tag) # "v1.2.3"
|
|
50
|
-
print(gv.branch) # "main"
|
|
51
|
-
print(gv.short) # "a1b2c3"
|
|
52
|
-
print(gv.full) # "1.2.3.42-a1b2c3"
|
|
53
|
-
print(gv.commit) # "a1b2c3d4e5f6..."
|
|
54
|
-
|
|
55
|
-
# Get all as environment variables
|
|
56
|
-
env_vars = gv.env(prefix="BUILD_VERSION")
|
|
57
|
-
for key, value in env_vars.items():
|
|
58
|
-
print(f"{key}={value}")
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## Environment Variables Output
|
|
62
|
-
|
|
63
|
-
With default prefix `BUILD_VERSION`:
|
|
64
|
-
|
|
65
|
-
| Variable | Example | Description |
|
|
66
|
-
|---|---|---|
|
|
67
|
-
| `BUILD_VERSION` | `1.2.3.42` | Full version: `<semver>.<build>` |
|
|
68
|
-
| `BUILD_VERSION_MAJOR` | `1` | Major version component |
|
|
69
|
-
| `BUILD_VERSION_MINOR` | `2` | Minor version component |
|
|
70
|
-
| `BUILD_VERSION_PATCH` | `3` | Patch version component |
|
|
71
|
-
| `BUILD_VERSION_BUILD` | `42` | Commits since last tag |
|
|
72
|
-
| `BUILD_VERSION_TAG` | `v1.2.3` | Latest matching git tag |
|
|
73
|
-
| `BUILD_VERSION_FULL` | `1.2.3.42-a1b2c3` | Version with commit hash |
|
|
74
|
-
| `BUILD_VERSION_EXTENDED` | `1.2.3.42-a1b2c3` | Full if build>0, else version |
|
|
75
|
-
| `BUILD_VERSION_SHORT` | `a1b2c3` | Short 6-char commit hash |
|
|
76
|
-
| `BUILD_VERSION_COMMIT` | `a1b2c3d4...` | Full 40-char commit hash |
|
|
77
|
-
| `BUILD_VERSION_BRANCH` | `main` | Current branch name |
|
|
78
|
-
| `BUILD_VERSION_DEFAULT_BRANCH` | `master` | Default branch from git config |
|
|
79
|
-
|
|
80
|
-
## CI/CD Integration
|
|
81
|
-
|
|
82
|
-
### Shell (source)
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
source <(git-version --property env)
|
|
86
|
-
echo "$BUILD_VERSION"
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### CMake
|
|
90
|
-
|
|
91
|
-
```cmake
|
|
92
|
-
execute_process(
|
|
93
|
-
COMMAND git-version --property env
|
|
94
|
-
OUTPUT_VARIABLE GIT_VERSION_ENV
|
|
95
|
-
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
96
|
-
)
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### Docker
|
|
100
|
-
|
|
101
|
-
```dockerfile
|
|
102
|
-
RUN pip install git-version-utils
|
|
103
|
-
RUN source <(git-version --property env) && echo "Building $BUILD_VERSION"
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: git-version-utils
|
|
3
|
-
Version: 0.1.0.0
|
|
4
|
-
Summary: Extract version information from a Git repository and output as environment variables
|
|
5
|
-
Author-email: Mikhail Milovidov <synacker@yandex.ru>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/synacker/git_version_utils
|
|
8
|
-
Project-URL: Repository, https://github.com/synacker/git_version_utils
|
|
9
|
-
Keywords: git,version,build,ci,cd
|
|
10
|
-
Requires-Python: >=3.10
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
|
|
13
|
-
# git-version-utils
|
|
14
|
-
|
|
15
|
-
Extract version information from a Git repository and output as environment variables.
|
|
16
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
pip install git-version-utils
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Usage
|
|
24
|
-
|
|
25
|
-
### CLI
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
# Print all version info
|
|
29
|
-
git-version
|
|
30
|
-
|
|
31
|
-
# Output as environment variables (useful with `source` or `eval`)
|
|
32
|
-
git-version --property env
|
|
33
|
-
|
|
34
|
-
# Custom prefix for environment variables
|
|
35
|
-
git-version --prefix MYAPP --property env
|
|
36
|
-
|
|
37
|
-
# Custom tag pattern
|
|
38
|
-
git-version --tag-pattern "release-*" --property env
|
|
39
|
-
|
|
40
|
-
# Get a single property
|
|
41
|
-
git-version --property version
|
|
42
|
-
git-version --property version_major
|
|
43
|
-
git-version --property commit
|
|
44
|
-
|
|
45
|
-
# Specify repository path
|
|
46
|
-
git-version --repo /path/to/repo --property env
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### Python API
|
|
50
|
-
|
|
51
|
-
```python
|
|
52
|
-
from git_version import GitVersion
|
|
53
|
-
|
|
54
|
-
gv = GitVersion(repo_path="/path/to/repo", tag_pattern="v[0-9]*")
|
|
55
|
-
|
|
56
|
-
print(gv.version) # "1.2.3.42"
|
|
57
|
-
print(gv.version_major) # "1"
|
|
58
|
-
print(gv.version_minor) # "2"
|
|
59
|
-
print(gv.version_patch) # "3"
|
|
60
|
-
print(gv.build) # "42"
|
|
61
|
-
print(gv.tag) # "v1.2.3"
|
|
62
|
-
print(gv.branch) # "main"
|
|
63
|
-
print(gv.short) # "a1b2c3"
|
|
64
|
-
print(gv.full) # "1.2.3.42-a1b2c3"
|
|
65
|
-
print(gv.commit) # "a1b2c3d4e5f6..."
|
|
66
|
-
|
|
67
|
-
# Get all as environment variables
|
|
68
|
-
env_vars = gv.env(prefix="BUILD_VERSION")
|
|
69
|
-
for key, value in env_vars.items():
|
|
70
|
-
print(f"{key}={value}")
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## Environment Variables Output
|
|
74
|
-
|
|
75
|
-
With default prefix `BUILD_VERSION`:
|
|
76
|
-
|
|
77
|
-
| Variable | Example | Description |
|
|
78
|
-
|---|---|---|
|
|
79
|
-
| `BUILD_VERSION` | `1.2.3.42` | Full version: `<semver>.<build>` |
|
|
80
|
-
| `BUILD_VERSION_MAJOR` | `1` | Major version component |
|
|
81
|
-
| `BUILD_VERSION_MINOR` | `2` | Minor version component |
|
|
82
|
-
| `BUILD_VERSION_PATCH` | `3` | Patch version component |
|
|
83
|
-
| `BUILD_VERSION_BUILD` | `42` | Commits since last tag |
|
|
84
|
-
| `BUILD_VERSION_TAG` | `v1.2.3` | Latest matching git tag |
|
|
85
|
-
| `BUILD_VERSION_FULL` | `1.2.3.42-a1b2c3` | Version with commit hash |
|
|
86
|
-
| `BUILD_VERSION_EXTENDED` | `1.2.3.42-a1b2c3` | Full if build>0, else version |
|
|
87
|
-
| `BUILD_VERSION_SHORT` | `a1b2c3` | Short 6-char commit hash |
|
|
88
|
-
| `BUILD_VERSION_COMMIT` | `a1b2c3d4...` | Full 40-char commit hash |
|
|
89
|
-
| `BUILD_VERSION_BRANCH` | `main` | Current branch name |
|
|
90
|
-
| `BUILD_VERSION_DEFAULT_BRANCH` | `master` | Default branch from git config |
|
|
91
|
-
|
|
92
|
-
## CI/CD Integration
|
|
93
|
-
|
|
94
|
-
### Shell (source)
|
|
95
|
-
|
|
96
|
-
```bash
|
|
97
|
-
source <(git-version --property env)
|
|
98
|
-
echo "$BUILD_VERSION"
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### CMake
|
|
102
|
-
|
|
103
|
-
```cmake
|
|
104
|
-
execute_process(
|
|
105
|
-
COMMAND git-version --property env
|
|
106
|
-
OUTPUT_VARIABLE GIT_VERSION_ENV
|
|
107
|
-
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
108
|
-
)
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### Docker
|
|
112
|
-
|
|
113
|
-
```dockerfile
|
|
114
|
-
RUN pip install git-version-utils
|
|
115
|
-
RUN source <(git-version --property env) && echo "Building $BUILD_VERSION"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/src/git_version_utils.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{git_version_utils-0.1.0.0 → git_version_utils-0.2.0.0}/src/git_version_utils.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|