{"id":13706911,"url":"https://github.com/codacy/git-version","last_synced_at":"2025-04-07T05:16:14.712Z","repository":{"id":40680416,"uuid":"145121307","full_name":"codacy/git-version","owner":"codacy","description":"Git versioning used in Codacy","archived":false,"fork":false,"pushed_at":"2023-05-30T10:58:01.000Z","size":151,"stargazers_count":134,"open_issues_count":31,"forks_count":47,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-31T04:06:28.482Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codacy.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-08-17T13:04:04.000Z","updated_at":"2025-02-08T21:13:08.000Z","dependencies_parsed_at":"2024-01-14T20:30:01.372Z","dependency_job_id":null,"html_url":"https://github.com/codacy/git-version","commit_stats":{"total_commits":94,"total_committers":15,"mean_commits":6.266666666666667,"dds":0.7127659574468085,"last_synced_commit":"80c816f11db8dea5e3a81025f598193015b51832"},"previous_names":[],"tags_count":68,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codacy%2Fgit-version","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codacy%2Fgit-version/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codacy%2Fgit-version/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codacy%2Fgit-version/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codacy","download_url":"https://codeload.github.com/codacy/git-version/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247595335,"owners_count":20963943,"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":[],"created_at":"2024-08-02T22:01:12.242Z","updated_at":"2025-04-07T05:16:14.670Z","avatar_url":"https://github.com/codacy.png","language":"Crystal","funding_links":[],"categories":["Crystal"],"sub_categories":[],"readme":"# git-version\n\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/c811f6b557ee4e44ad373084015ba0b3)](https://www.codacy.com/gh/codacy/git-version?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=codacy/git-version\u0026amp;utm_campaign=Badge_Grade)\n[![CircleCI](https://circleci.com/gh/codacy/git-version.svg?style=svg)](https://circleci.com/gh/codacy/git-version)\n[![](https://images.microbadger.com/badges/version/codacy/git-version.svg)](https://microbadger.com/images/codacy/git-version \"Get your own version badge on microbadger.com\")\n\nThe goal of this tool is to have a simple versioning system that we can use to track the different releases. The tool prints the current version (e.g. to be used for tagging) depending on the git history and commit messages.\n\nThe versioning scheme is assumed to be __Semver__ based.\n\n## Usage\n\n```yaml\n# .github/workflows/version.yml\nname: Git Version\n\non:\n  push:\n    branches:\n      - master\n\njobs:\n  lint:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout Code\n        uses: actions/checkout@v3\n        with:\n          ref: ${{ github.head_ref }}   # checkout the correct branch name\n          fetch-depth: 0                # fetch the whole repo history\n\n      - name: Git Version\n        id: version\n        uses: codacy/git-version@2.7.1\n      \n      - name: Use the version\n        run: |\n          echo ${{ steps.version.outputs.version }}\n      - name: Use the previous version\n        run: |\n          echo ${{ steps.version.outputs.previous-version }}\n```\n\n### Mono-Repo\n\nYou can use git-version to version different modules in a mono-repo structure.\nThis can be achieved by using different `prefixes` and `log-path` filters for\ndifferent modules.\n\nAssuming the following directory structure, we can use git-version to generate\nversion with prefix `module1-x.x.x` for changes in the `module1/` directory\nand  `module2-x.x.x` for changes in the `module2/` directory.\n\n```sh\n.\n├── Dockerfile\n├── Makefile\n├── README.md\n├── module1\n│   ├── Dockerfile\n│   └── src/\n└── module2\n    ├── Dockerfile\n    └── src/\n```\n\nWith github actions you can create different workflows that are triggered\nwhen changes happen on different directories.\n\n```yaml\n# .github/workflows/module1.yml\nname: Version Module 1\n\non:\n  pull_request:\n    paths:\n      - .github/workflows/module1.yml\n      - module1/**\n  push:\n    paths:\n      - .github/workflows/module1.yml\n      - module1/**\n    branches:\n      - master\n\njobs:\n  lint:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout Code\n        uses: actions/checkout@v3\n        with:\n          ref: ${{ github.head_ref }}   # checkout the correct branch name\n          fetch-depth: 0                # fetch the whole repo history\n\n      - name: Git Version\n        uses: codacy/git-version@2.5.4\n        with:\n          prefix: module1-\n          log-path: module1/\n```\n\n```yaml\n# .github/workflows/module2.yml\nname: Version Module 2\n\non:\n  pull_request:\n    paths:\n      - .github/workflows/module2.yml\n      - module2/**\n  push:\n    paths:\n      - .github/workflows/module2.yml\n      - module2/**\n    branches:\n      - master\n\njobs:\n  lint:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout Code\n        uses: actions/checkout@v3\n        with:\n          ref: ${{ github.head_ref }}   # checkout the correct branch name\n          fetch-depth: 0                # fetch the whole repo history\n\n      - name: Git Version\n        uses: codacy/git-version@2.5.4\n        with:\n          prefix: module2-\n          log-path: module2/\n```\n\n## Versioning Model\n\nCreates a version with the format `MAJOR.MINOR.PATCH`\n\n_To use this you need to be in the working dir of a git project:_\n```\n$ ./git-version\n1.0.0\n```\n\nVersions are incremented since the last tag. The patch version is incremented by default, unless there is at least one commit since the last tag, containing a minor or major identifier (defaults to `feature:` or `breaking:`) in the message.\n\nOn branches other than the master/main and development branch (default to `master` and `dev`) the version is a variation of the latest common tag with the master/main branch, and has the following format:\n\n`{MAJOR}.{MINOR}.{PATCH}-{sanitized-branch-name}.{commits-distance}.{hash}`\n\nOn the development branch the format is the following:\n\n`{MAJOR}.{MINOR}.{PATCH}-SNAPSHOT.{hash}`\n\n_Example:_\n```\n---A---B---C \u003c= Master (tag: 1.0.1)        L \u003c= Master (git-version: 1.0.2)\n            \\                             /\n             D---E---F---G---H---I---J---K \u003c= Foo (git-version: 1.0.2-foo.8.5e30d83)\n```\n\n_Example2 (with dev branch):_\n```\n---A---B---C \u003c= Master (tag: 1.0.1)        L \u003c= Master (git-version: 1.0.2)\n            \\                             / \u003c= Fast-forward merges to master (same commit id)\n             C                           L \u003c= Dev (git-version: 1.0.2-SNAPSHOT.5e30d83)\n              \\                         /\n               E---F---G---H---I---J---K \u003c= Foo (new_version: 1.0.1-foo.7.5e30d83)\n```\n\n_Example3 (with breaking message):_\n```\n---A---B---C \u003c= Master (tag: 1.0.1)        L \u003c= Master (git-version: 2.0.0)\n            \\                             /\n             D---E---F---G---H---I---J---K \u003c= Foo (git-version: 2.0.0-foo.8.5e30d83)\n                                         \\\\\n                                         message: \"breaking: removed api parameter\"\n```\n\n### Configuration\n\nYou can configure the action with various inputs, a list of which has been provided below:\n\n| Name             | Description                                                                                     | Default Value |\n|------------------|-------------------------------------------------------------------------------------------------|---------------|\n| tool-version     | The version of the tool to run                                                                  | latest        |\n| release-branch   | The name of the master/main branch                                                              | master        |\n| dev-branch       | The name of the development branch                                                              | dev           |\n| minor-identifier | The string used to identify a minor release (wrap with '/' to match using a regular expression) | feature:      |\n| major-identifier | The string used to identify a major release (wrap with '/' to match using a regular expression) | breaking:     |\n| prefix           | The prefix used for the version name                                                            |               |\n| log-paths        | The paths used to calculate changes (comma-separated)                                           |               |\n\n## Requirements\n\nTo use this tool you will need to install a few dependencies:\n\nUbuntu:\n```\nsudo apt-get install \\\n  libevent-dev \\\n  git\n```\n\nFedora:\n```\nsudo dnf -y install \\\n  libevent-devel \\\n  git\n```\n\nAlpine:\n```\napk add --update --no-cache --force-overwrite \\\n  gc-dev pcre-dev libevent-dev \\\n  git\n```\n\nOsX:\n```\nbrew install \\\n  libevent \\\n  git\n```\n\n\n## CircleCI\n\nUse this image directly on CircleCI for simple steps\n\n```\nversion: 2\njobs:\n  build:\n    machine: true\n    working_directory: /app\n    steps:\n      - checkout\n      - run:\n          name: get new version\n          command: |\n            NEW_VERSION=$(docker run --rm -v $(pwd):/repo codacy/git-version)\n            echo $NEW_VERSION\n```\n\n## Build and Publish\n\nThe pipeline in `circleci` can deploy this for you when the code is pushed to the remote.\n\nTo compile locally you need to install [crystal](https://crystal-lang.org/install/) and possibly [all required libraries](https://github.com/crystal-lang/crystal/wiki/All-required-libraries)\n\nYou can also run everything locally using the makefile.\n\nTo get the list of available commands:\n```\n$ make help\n```\n\n## Credits\n\nGreat inspiration for this tool has been taken from: [GitVersion](https://github.com/GitTools/GitVersion)\n\n## What is Codacy\n\n[Codacy](https://www.codacy.com/) is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.\n\n### Among Codacy’s features\n\n- Identify new Static Analysis issues\n- Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)\n- Auto-comments on Commits and Pull Requests\n- Integrations with Slack, HipChat, Jira, YouTrack\n- Track issues in Code Style, Security, Error Proneness, Performance, Unused Code and other categories\n\nCodacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.\n\nCodacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.\n\n## Free for Open Source\n\nCodacy is free for Open Source projects.\n\n## License\n\ngit-version is available under the Apache 2 license. See the [LICENSE](./LICENSE) file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodacy%2Fgit-version","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodacy%2Fgit-version","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodacy%2Fgit-version/lists"}