• Stars
    star
    125
  • Rank 276,337 (Top 6 %)
  • Language
    Crystal
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Git versioning used in Codacy

git-version

Codacy Badge CircleCI

The 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.

The versioning scheme is assumed to be Semver based.

Usage

# .github/workflows/version.yml
name: Git Version

on:
  push:
    branches:
      - master

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v3
        with:
          ref: ${{ github.head_ref }}   # checkout the correct branch name
          fetch-depth: 0                # fetch the whole repo history

      - name: Git Version
        id: version
        uses: codacy/[email protected]
      
      - name: Use the version
        run: |
          echo ${{ steps.version.outputs.version }}
      - name: Use the previous version
        run: |
          echo ${{ steps.version.outputs.previous-version }}

Mono-Repo

You can use git-version to version different modules in a mono-repo structure. This can be achieved by using different prefixes and log-path filters for different modules.

Assuming the following directory structure, we can use git-version to generate version with prefix module1-x.x.x for changes in the module1/ directory and module2-x.x.x for changes in the module2/ directory.

.
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ Makefile
β”œβ”€β”€ README.md
β”œβ”€β”€ module1
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── src/
└── module2
    β”œβ”€β”€ Dockerfile
    └── src/

With github actions you can create different workflows that are triggered when changes happen on different directories.

# .github/workflows/module1.yml
name: Version Module 1

on:
  pull_request:
    paths:
      - .github/workflows/module1.yml
      - module1/**
  push:
    paths:
      - .github/workflows/module1.yml
      - module1/**
    branches:
      - master

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v3
        with:
          ref: ${{ github.head_ref }}   # checkout the correct branch name
          fetch-depth: 0                # fetch the whole repo history

      - name: Git Version
        uses: codacy/[email protected]
        with:
          prefix: module1-
          log-path: module1/
# .github/workflows/module2.yml
name: Version Module 2

on:
  pull_request:
    paths:
      - .github/workflows/module2.yml
      - module2/**
  push:
    paths:
      - .github/workflows/module2.yml
      - module2/**
    branches:
      - master

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v3
        with:
          ref: ${{ github.head_ref }}   # checkout the correct branch name
          fetch-depth: 0                # fetch the whole repo history

      - name: Git Version
        uses: codacy/[email protected]
        with:
          prefix: module2-
          log-path: module2/

Versioning Model

Creates a version with the format MAJOR.MINOR.PATCH

To use this you need to be in the working dir of a git project:

$ ./git-version
1.0.0

Versions 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.

On 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:

{MAJOR}.{MINOR}.{PATCH}-{sanitized-branch-name}.{commits-distance}.{hash}

On the development branch the format is the following:

{MAJOR}.{MINOR}.{PATCH}-SNAPSHOT.{hash}

Example:

---A---B---C <= Master (tag: 1.0.1)        L <= Master (git-version: 1.0.2)
            \                             /
             D---E---F---G---H---I---J---K <= Foo (git-version: 1.0.2-foo.8.5e30d83)

Example2 (with dev branch):

---A---B---C <= Master (tag: 1.0.1)        L <= Master (git-version: 1.0.2)
            \                             / <= Fast-forward merges to master (same commit id)
             C                           L <= Dev (git-version: 1.0.2-SNAPSHOT.5e30d83)
              \                         /
               E---F---G---H---I---J---K <= Foo (new_version: 1.0.1-foo.7.5e30d83)

Example3 (with breaking message):

---A---B---C <= Master (tag: 1.0.1)        L <= Master (git-version: 2.0.0)
            \                             /
             D---E---F---G---H---I---J---K <= Foo (git-version: 2.0.0-foo.8.5e30d83)
                                         \\
                                         message: "breaking: removed api parameter"

Configuration

You can configure the action with various inputs, a list of which has been provided below:

Name Description Default Value
tool-version The version of the tool to run latest
release-branch The name of the master/main branch master
dev-branch The name of the development branch dev
minor-identifier The string used to identify a minor release (wrap with '/' to match using a regular expression) feature:
major-identifier The string used to identify a major release (wrap with '/' to match using a regular expression) breaking:
prefix The prefix used for the version name
log-paths The paths used to calculate changes (comma-separated)

Requirements

To use this tool you will need to install a few dependencies:

Ubuntu:

sudo apt-get install \
  libevent-dev \
  git

Fedora:

sudo dnf -y install \
  libevent-devel \
  git

Alpine:

apk add --update --no-cache --force-overwrite \
  gc-dev pcre-dev libevent-dev \
  git

OsX:

brew install \
  libevent \
  git

CircleCI

Use this image directly on CircleCI for simple steps

version: 2
jobs:
  build:
    machine: true
    working_directory: /app
    steps:
      - checkout
      - run:
          name: get new version
          command: |
            NEW_VERSION=$(docker run --rm -v $(pwd):/repo codacy/git-version)
            echo $NEW_VERSION

Build and Publish

The pipeline in circleci can deploy this for you when the code is pushed to the remote.

To compile locally you need to install crystal and possibly all required libraries

You can also run everything locally using the makefile.

To get the list of available commands:

$ make help

Credits

Great inspiration for this tool has been taken from: GitVersion

What is Codacy

Codacy 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.

Among Codacy’s features

  • Identify new Static Analysis issues
  • Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)
  • Auto-comments on Commits and Pull Requests
  • Integrations with Slack, HipChat, Jira, YouTrack
  • Track issues in Code Style, Security, Error Proneness, Performance, Unused Code and other categories

Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.

Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.

Free for Open Source

Codacy is free for Open Source projects.

License

git-version is available under the Apache 2 license. See the LICENSE file for more info.

More Repositories

1

tools-for-code-review-engineers

A list of tools to improve the git workflow for code review engineers.
658
star
2

codacy-coverage-reporter

Multi-language coverage reporter for Codacy
Scala
130
star
3

codacy-analysis-cli

The Codacy Analysis CLI is a command line interface that enables you to execute Codacy code analysis locally.
Scala
90
star
4

helm-ssm

Injects values from AWS SSM parameters on the values.yaml file
Go
64
star
5

codacy-analysis-cli-action

GitHub Action for the codacy-analysis-cli
53
star
6

codacy-coverage-reporter-action

GitHub Action for the codacy-coverage-reporter
52
star
7

codacy-scalameta

Codacy tool for Scalameta
Scala
34
star
8

docs

Codacy documentation
Python
19
star
9

sbt-codacy-coverage

Sbt plugin for uploading Scala code coverage to Codacy https://www.codacy.com
Scala
18
star
10

codacy-pylint

Pylint tool for Codacy
Python
16
star
11

codacy-eslint

Codacy tool for Eslint
TypeScript
13
star
12

ruby-codacy-coverage

DEPRECATED Post coverage results to Codacy
Ruby
13
star
13

chart

Codacy Helm chart and self-hosted infrastructure quickstart
Makefile
12
star
14

bitbucket-scala-client

Simple Bitbucket Scala Client
Scala
10
star
15

codacy-bandit

Bandit Python Tool for Codacy
Scala
9
star
16

codacy-api-scala

Scala wrapper for the Codacy API
Scala
6
star
17

codacy-plugins-test

Testing interface for external docker tools
Scala
6
star
18

codacy-sonar-csharp

Docker engine for SonarC# code analyzer
C#
6
star
19

codacy-codesniffer

Codacy tool for PHP Codesniffer
Scala
6
star
20

csharp-codacy-coverage

DEPRECATED C# coverage reporter for Codacy
C#
6
star
21

codacy-rubocop

Codacy Tool for Rubocop
Ruby
5
star
22

codacy-phpmd

PHP Mess Detector Tool for Codacy
Scala
5
star
23

codacy-checkstyle

Codacy Tool for Checkstyle
Scala
4
star
24

ytool

A simple tool to set values in yaml files preserving format and comments.
Python
4
star
25

codacy-stylelint

Codacy Tool for Stylelint
Scala
4
star
26

codacy-metrics-scala-seed

Simple framework to help integrate metrics tools in Codacy
Scala
3
star
27

qa-frontend-challenge

TypeScript
3
star
28

codacy-metrics-sonar-csharp

Docker engine for metrics support on SonarC# code analyzer
C#
3
star
29

codacy-meta

Meta repository about general issues and plannings for Codacy OSS projects.
3
star
30

codacy-engine-scala-seed

Helpers to create Codacy engines in Scala
Scala
3
star
31

codacy-gorevive

Codacy Tool for Golang Revive
Go
3
star
32

base

Codacy Docker Base
Makefile
3
star
33

codacy-github-graphql

Library with Apollo compiled queries and models for GitHub API V4
Scala
3
star
34

pulse-user-docs

HTML
3
star
35

codacy-sqlint

Codacy Tool for Sqlint
Scala
3
star
36

codacy-detekt

Codacy Tool for Detekt
Scala
3
star
37

akka-typed

Akka typed actors sample
Scala
2
star
38

codacy-brakeman

Codacy Tool for Brakeman
Scala
2
star
39

codacy-scalastyle

Scalastyle Scala Tool for Codacy
Scala
2
star
40

codacy-orbs

Codacy CircleCI Orbs
Shell
2
star
41

stash-scala-client

Simple Stash Scala Client
Scala
2
star
42

codacy-duplication-flay

Codacy Duplication tool for Flay
Ruby
2
star
43

codacy-engine-golang-seed

Go
2
star
44

Unity.Project

C#
2
star
45

codacy-pmd

PMD Tool for Codacy
Java
2
star
46

codacy-clang-tidy

Codacy's reporter for clang-tidy
Scala
2
star
47

codacy-usage-report

Go
2
star
48

helm-poll

An Helm plugin to poll for a release status.
Go
2
star
49

codacy-plugins-api

A dependency free api for Codacy Tools
Scala
2
star
50

codacy-engine-typescript-seed

Library to write Codacy tools in Typescript
TypeScript
2
star
51

codacy-findbugs

Codacy Tool for Findbugs
Scala
1
star
52

pulse-event-cli

Command line interface to push events to the pulse service
Go
1
star
53

codacy-meta-repo

Shell
1
star
54

codacy-prospector

Codacy Tool for Prospector
Python
1
star
55

codacy-metrics-scalastyle

Scala
1
star
56

codacy-people-csv

Script to download people in your Codacy organization
Scala
1
star
57

ci-base

Base docker image used by Codacy in Continuous Integration environments such as CircleCI.
Makefile
1
star
58

codacy-duplication-pmdcpd

Codacy Duplication Tool for PMD
Scala
1
star
59

env4config

Load Environment variables first as default with Typesafe Config
Scala
1
star
60

codacy-checkov

Codacy tool for Checkov
SuperCollider
1
star
61

codacy-engine-csharp-seed

Helpers to create Codacy engines in C#
C#
1
star
62

codacy-public-template

1
star
63

ssm2eb

A simple tool to get ssm parameters to an .ebextensions file
Python
1
star
64

codacy-macros

Scala and Play Framework macros
Scala
1
star
65

codacy-hadolint

Codacy Docker container for Hadolint tool
Scala
1
star
66

codacy-api-typescript

Typescript wrapper for the Codacy API
TypeScript
1
star
67

About

Codacy - Ship high-quality code on more than 40 programming languages.
1
star
68

codacy-tailor

Tailor Swift Tool for Codacy
Swift
1
star
69

codacy-metrics-cloc

Cloc docker wrapper for Codacy integration
Scala
1
star
70

ci-aws

Docker image with awscli installed
Python
1
star
71

codacy-tsqllint

Codacy tool for TSQLLint
C#
1
star
72

codacy-aligncheck

Codacy Tool for Aligncheck
Scala
1
star
73

codacy-metrics-pmd

Java
1
star
74

elasticsearch-curator

Elasticsearch curator docker image
Dockerfile
1
star
75

codacy-eslint-legacy

Codacy Tool for ESLint (Legacy Version)
TypeScript
1
star
76

codacy-duplication-scala-seed

Library to integrate duplication tools in Codacy
Scala
1
star
77

ssmeb

Go
1
star
78

codacy-roslyn

Codacy tool for Unity Roslyn Analyzers
Scala
1
star
79

codacy-duplication-jscpd

Codacy duplication tool for jscpd
Scala
1
star