{"id":19782372,"url":"https://github.com/krysopath/semver","last_synced_at":"2025-04-30T22:30:51.718Z","repository":{"id":49003985,"uuid":"373433931","full_name":"krysopath/semver","owner":"krysopath","description":"a pipeline util for parsing semantic versions","archived":false,"fork":false,"pushed_at":"2024-05-07T11:25:47.000Z","size":58,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-21T03:13:32.727Z","etag":null,"topics":["gitlab","go","parse","pipelines","semver","stdin"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krysopath.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-03T08:23:38.000Z","updated_at":"2024-05-07T11:25:51.000Z","dependencies_parsed_at":"2024-06-21T02:04:44.771Z","dependency_job_id":"5c0d2780-6162-4f8c-aa28-376ab374a546","html_url":"https://github.com/krysopath/semver","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krysopath%2Fsemver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krysopath%2Fsemver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krysopath%2Fsemver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krysopath%2Fsemver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krysopath","download_url":"https://codeload.github.com/krysopath/semver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224225286,"owners_count":17276435,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gitlab","go","parse","pipelines","semver","stdin"],"created_at":"2024-11-12T06:04:58.369Z","updated_at":"2024-11-12T06:04:59.592Z","avatar_url":"https://github.com/krysopath.png","language":"Go","readme":"# semver\n\n\u003e semantic versions in pipelines\n\n\n`semver` was created to serve as reliable pipeline helper. Born out of\nnecessity and distrust towards regex.\n\n\n## Installation\n\n```\ngo install github.com/krysopath/semver/cmd/semver@v1\n```\n\nor\n\n```\nGO111MODULE=on go get github.com/krysopath/semver/cmd/semver@v1\n```\n\n## Usage\n\nParse tags from git:\n```\n$ git tag | head -n1 | semver | jq\n{\n  \"canonical\": \"v0.2.0\",\n  \"major\": \"v0\",\n  \"majorminor\": \"v0.2\",\n  \"prerelease\": \"\",\n  \"build\": \"\",\n  \"source\": \"v0.2.0\"\n}\n```\n\nParse semantic version from stdin:\n```\n$ echo \"v0.1.23-alpha2+9999\" | semver | jq\n{\n  \"build\": \"+9999\",\n  \"canonical\": \"v0.1.23-alpha2\",\n  \"major\": \"v0\",\n  \"majorminor\": \"v0.1\",\n  \"prerelease\": \"-alpha2\"\n}\n```\n\n\nWhen run inside Gitlab Runners, can execute without stdin:\n```\n$ export CI_COMMIT_TAG=v1.22.4-some+123\n$ semver | jq\n{\n  \"build\": \"+123\",\n  \"canonical\": \"v1.22.4-some\",\n  \"major\": \"v1\",\n  \"majorminor\": \"v1.22\",\n  \"prerelease\": \"-some\"\n}\n```\n\nWhen you dont like json, but shell:\n```\n$ eval $(echo v3.2.1-yolo22 | ./semver -format=eval)\n$ echo $MAJORMINOR\nv3.2\n```\n\n\n## In pipelines\n\n```\n# lets use the great jq to create nobrain parseable \nexport SEMVER=\"$(echo $CI_COMMIT_TAG | semver)\"\n\n# lets record the -prerelease+build as SUFFIX\nexport SUFFIX=\"$(echo $SEMVER | jq -r .prerelease)$(echo $SEMVER | jq -r .build)\"\n\n# lets create the semvers, appending SUFFIX (for edgecase, you know)\nexport MAJORMINOR=\"$(echo $SEMVER | jq -r .majorminor)$SUFFIX\"\nexport MAJOR=\"$(echo $SEMVER | jq -r .major)$SUFFIX\"\nexport CANONICAL=\"$(echo $SEMVER | jq -r .canonical)\"\n\n# tag one distinct artifact with these three versions\ndocker tag $CI_IMAGE_TAG \"$CI_REGISTRY_IMAGE:$MAJORMINOR\"\ndocker tag $CI_IMAGE_TAG \"$CI_REGISTRY_IMAGE:$MAJOR\"\ndocker tag $CI_IMAGE_TAG \"$CI_REGISTRY_IMAGE:$CANONICAL\"\n```\n\n\u003e docker e.g. as standin for any artifact\n\n\n\u003e Above snippet can be used as is in gitlab\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrysopath%2Fsemver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrysopath%2Fsemver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrysopath%2Fsemver/lists"}