Skip to content

Commit c2add2d

Browse files
author
Daniel Reigada
authored
Merge pull request #37 from codacy/feat/log-path
add log-path tests
2 parents 61e2fac + b084e4c commit c2add2d

File tree

6 files changed

+323
-43
lines changed

6 files changed

+323
-43
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ fmt: ## format the crystal sources
1616

1717
build: ## compiles from crystal sources
1818
mkdir -p bin
19-
$(CRYSTAL) build $(CRYSTAL_FLAGS) src/entrypoint/git-version.cr -o bin/git-version
19+
$(CRYSTAL) build $(CRYSTAL_FLAGS) src/main.cr -o bin/git-version
2020

2121
.PHONY: buildStatic
2222
buildStatic: ## compiles from crystal sources into static binary
2323
mkdir -p bin
24-
docker run --rm -it -v $(PWD):/app -w /app durosoft/crystal-alpine:latest crystal build $(CRYSTAL_FLAGS) $(CRYSTAL_STATIC_FLAGS) src/entrypoint/git-version.cr -o bin/git-version
24+
docker run --rm -it -v $(PWD):/app -w /app durosoft/crystal-alpine:latest crystal build $(CRYSTAL_FLAGS) $(CRYSTAL_STATIC_FLAGS) src/main.cr -o bin/git-version
2525

2626
.PHONY: docker
2727
docker: build docker_build ## compiles from sources and produce the docker image

README.md

Lines changed: 137 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,116 @@
44
[![CircleCI](https://circleci.com/gh/codacy/git-version.svg?style=svg)](https://circleci.com/gh/codacy/git-version)
55
[![](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")
66

7-
Git versioning used in Codacy.
7+
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.
88

9-
The goal is to have a simple versioning system for our internal projects that we can use to track the different releases.
9+
The versioning scheme is assumed to be __Semver__ based.
1010

11-
This tool returns in standard output the current version (e.g. to be used for tagging) depending on the git history and commit messages.
11+
## Usage
1212

13-
The versioning scheme is assumed to be __Semver__.
13+
```yaml
14+
# .github/workflows/version.yml
15+
name: Git Version
1416

15-
## Requirements
16-
17-
To use this tool you will need to install a few dependencies:
17+
on:
18+
push:
19+
branches:
20+
- master
1821

19-
Ubuntu:
20-
```
21-
sudo apt-get install \
22-
libevent-dev \
23-
git
24-
```
22+
jobs:
23+
lint:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout Code
27+
uses: actions/checkout@v2
28+
29+
- name: Git Version
30+
uses: codacy/[email protected]
31+
```
32+
33+
### Mono-Repo
34+
35+
You can use git-version to version different modules in a mono-repo structure.
36+
This can be achieved by using different `prefixes` and `log-path` filters for
37+
different modules.
38+
39+
Assuming the following directory structure, we can use git-version to generate
40+
version with prefix `module1-x.x.x` for changes in the `module1/` directory
41+
and `module2-x.x.x` for changes in the `module2/` directory.
42+
43+
```sh
44+
.
45+
├── Dockerfile
46+
├── Makefile
47+
├── README.md
48+
├── module1
49+
│ ├── Dockerfile
50+
│ └── src/
51+
└── module2
52+
├── Dockerfile
53+
└── src/
54+
```
55+
56+
With github actions you can create different workflows that are triggered
57+
when changes happen on different directories.
58+
59+
```yaml
60+
# .github/workflows/module1.yml
61+
name: Version Module 1
62+
63+
on:
64+
pull_request:
65+
paths:
66+
- .github/workflows/module1.yml
67+
- module1/**
68+
push:
69+
paths:
70+
- .github/workflows/module1.yml
71+
- module1/**
72+
branches:
73+
- master
2574
26-
Fedora:
27-
```
28-
sudo dnf -y install \
29-
libevent-devel \
30-
git
31-
```
75+
jobs:
76+
lint:
77+
runs-on: ubuntu-latest
78+
steps:
79+
- name: Checkout Code
80+
uses: actions/checkout@v2
81+
82+
- name: Git Version
83+
uses: codacy/[email protected]
84+
with:
85+
prefix: module1-
86+
log-path: module1/
87+
```
88+
89+
```yaml
90+
# .github/workflows/module2.yml
91+
name: Version Module 2
92+
93+
on:
94+
pull_request:
95+
paths:
96+
- .github/workflows/module2.yml
97+
- module2/**
98+
push:
99+
paths:
100+
- .github/workflows/module2.yml
101+
- module2/**
102+
branches:
103+
- master
32104
33-
Alpine:
34-
```
35-
apk add --update --no-cache --force-overwrite \
36-
gc-dev pcre-dev libevent-dev \
37-
git
38-
```
105+
jobs:
106+
lint:
107+
runs-on: ubuntu-latest
108+
steps:
109+
- name: Checkout Code
110+
uses: actions/checkout@v2
39111
40-
OsX:
41-
```
42-
brew install \
43-
libevent \
44-
git
112+
- name: Codacy Git Version
113+
uses: codacy/[email protected]
114+
with:
115+
prefix: module2-
116+
log-path: module2/
45117
```
46118

47119
## Versioning Model
@@ -54,13 +126,13 @@ $ ./git-version
54126
1.0.0
55127
```
56128
57-
Versions are incremented since last tag. The patch version is incremented by default, unless there is at least one commit since the last tag, containing `feature:` or `breaking:` in the message.
129+
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 `feature:` or `breaking:` in the message.
58130
59131
On branches other than master and `dev` the version is a variation of the latest common tag with master, and has the following format:
60132
61133
`{MAJOR}.{MINOR}.{PATCH}-{sanitized-branch-name}.{commits-distance}.{hash}`
62134
63-
On the `dev` branch the format is following:
135+
On the `dev` branch the format is the following:
64136
65137
`{MAJOR}.{MINOR}.{PATCH}-SNAPSHOT.{hash}`
66138
@@ -89,6 +161,39 @@ _Example3 (with breaking message):_
89161
message: "breaking: removed api parameter"
90162
```
91163
164+
## Requirements
165+
166+
To use this tool you will need to install a few dependencies:
167+
168+
Ubuntu:
169+
```
170+
sudo apt-get install \
171+
libevent-dev \
172+
git
173+
```
174+
175+
Fedora:
176+
```
177+
sudo dnf -y install \
178+
libevent-devel \
179+
git
180+
```
181+
182+
Alpine:
183+
```
184+
apk add --update --no-cache --force-overwrite \
185+
gc-dev pcre-dev libevent-dev \
186+
git
187+
```
188+
189+
OsX:
190+
```
191+
brew install \
192+
libevent \
193+
git
194+
```
195+
196+
92197
## CircleCI
93198
94199
Use this image directly on CircleCI for simple steps

action.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Codacy Git Version
1+
name: Git Version
22
author: "Codacy"
33
description: 'Semver versioning based on the git history and commit messages of your repository.'
44
branding:
@@ -16,10 +16,10 @@ inputs:
1616
prefix:
1717
description: 'The prefix to use in the version'
1818
required: false
19-
# log-paths:
20-
# description: 'The paths to be used to calculate changes (comma-separated)'
21-
# required: false
22-
# default: ./
19+
log-paths:
20+
description: 'The paths to be used to calculate changes (comma-separated)'
21+
required: false
22+
default: ./
2323
outputs:
2424
version:
2525
description: 'The version'

0 commit comments

Comments
 (0)