Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/krysopath/semver
a pipeline util for parsing semantic versions
https://github.com/krysopath/semver
gitlab go parse pipelines semver stdin
Last synced: about 1 month ago
JSON representation
a pipeline util for parsing semantic versions
- Host: GitHub
- URL: https://github.com/krysopath/semver
- Owner: krysopath
- License: mit
- Created: 2021-06-03T08:23:38.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-05-07T11:25:47.000Z (8 months ago)
- Last Synced: 2024-06-21T03:13:32.727Z (6 months ago)
- Topics: gitlab, go, parse, pipelines, semver, stdin
- Language: Go
- Homepage:
- Size: 56.6 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# semver
> semantic versions in pipelines
`semver` was created to serve as reliable pipeline helper. Born out of
necessity and distrust towards regex.## Installation
```
go install github.com/krysopath/semver/cmd/semver@v1
```or
```
GO111MODULE=on go get github.com/krysopath/semver/cmd/semver@v1
```## Usage
Parse tags from git:
```
$ git tag | head -n1 | semver | jq
{
"canonical": "v0.2.0",
"major": "v0",
"majorminor": "v0.2",
"prerelease": "",
"build": "",
"source": "v0.2.0"
}
```Parse semantic version from stdin:
```
$ echo "v0.1.23-alpha2+9999" | semver | jq
{
"build": "+9999",
"canonical": "v0.1.23-alpha2",
"major": "v0",
"majorminor": "v0.1",
"prerelease": "-alpha2"
}
```When run inside Gitlab Runners, can execute without stdin:
```
$ export CI_COMMIT_TAG=v1.22.4-some+123
$ semver | jq
{
"build": "+123",
"canonical": "v1.22.4-some",
"major": "v1",
"majorminor": "v1.22",
"prerelease": "-some"
}
```When you dont like json, but shell:
```
$ eval $(echo v3.2.1-yolo22 | ./semver -format=eval)
$ echo $MAJORMINOR
v3.2
```## In pipelines
```
# lets use the great jq to create nobrain parseable
export SEMVER="$(echo $CI_COMMIT_TAG | semver)"# lets record the -prerelease+build as SUFFIX
export SUFFIX="$(echo $SEMVER | jq -r .prerelease)$(echo $SEMVER | jq -r .build)"# lets create the semvers, appending SUFFIX (for edgecase, you know)
export MAJORMINOR="$(echo $SEMVER | jq -r .majorminor)$SUFFIX"
export MAJOR="$(echo $SEMVER | jq -r .major)$SUFFIX"
export CANONICAL="$(echo $SEMVER | jq -r .canonical)"# tag one distinct artifact with these three versions
docker tag $CI_IMAGE_TAG "$CI_REGISTRY_IMAGE:$MAJORMINOR"
docker tag $CI_IMAGE_TAG "$CI_REGISTRY_IMAGE:$MAJOR"
docker tag $CI_IMAGE_TAG "$CI_REGISTRY_IMAGE:$CANONICAL"
```> docker e.g. as standin for any artifact
> Above snippet can be used as is in gitlab