Skip to content

Commit cc639d2

Browse files
committed
add pre-commit to update version in Constants.php
1 parent 2e5e2ae commit cc639d2

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

.githooks/pre-commit

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
platform='unknown'
4+
unamestr=`uname`
5+
if [[ "$unamestr" == 'Linux' ]]; then
6+
platform='linux'
7+
elif [[ "$unamestr" == 'FreeBSD' ]]; then
8+
platform='freebsd'
9+
elif [[ "$unamestr" == 'Darwin' ]]; then
10+
platform='osx'
11+
fi
12+
13+
14+
function get_git_tag {
15+
git describe --tags `git rev-list --tags --max-count=1`
16+
}
17+
18+
git_tag=$(get_git_tag)
19+
20+
if [[ $platform == 'linux' ]]; then
21+
sed -i -E "s/v[0-9]+\.[0-9]+\.[0-9]/$git_tag/" `git rev-parse --show-toplevel`/src/Constants.php
22+
else
23+
sed -i "" -E "s/v[0-9]+\.[0-9]+\.[0-9]/$git_tag/" `git rev-parse --show-toplevel`/src/Constants.php
24+
fi
25+
git add `git rev-parse --show-toplevel`/src/Constants.php
26+
27+
echo 'Note: version number updated in src/Constants.php'

composer.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,13 @@
4040
"symfony/var-dumper": "^5.2",
4141
"phpunit/phpunit": "8.5.13",
4242
"clean/phpdoc-md": "^0.19.1"
43+
},
44+
"scripts": {
45+
"post-install-cmd": [
46+
"./post-install.sh"
47+
],
48+
"post-update-cmd": [
49+
"./post-install.sh"
50+
]
4351
}
44-
}
52+
}

docs/contribute.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ After the merge, don't forget to delete to branch.
8787

8888
```bash
8989
git checkout main && git pull
90-
git describe --tags # to verify what is the current tag
90+
git describe --tags `git rev-list --tags --max-count=1` # to verify what is the current tag
9191
gh release create --draft vx.x.x --title vx.x.x
9292
```

post-install.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
git config core.hooksPath `git rev-parse --show-toplevel`/.githooks
2+
echo "Git pre-commit hook is installed. This hook fixes the src/Constants.php version for each commits."

src/Constants.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ class Constants
1717
/** @var string The URL of the CrowdSec Central API */
1818
public const CAPI_URL = 'https://api.crowdsec.net/v2/';
1919

20+
/** @var string The last version of this library */
21+
public const VERSION = 'v0.6.0';
22+
2023
/** @var string The user agent used to send request to LAPI or CAPI */
21-
public const BASE_USER_AGENT = 'PHP CrowdSec Bouncer/1.0.0';
24+
public const BASE_USER_AGENT = 'PHP CrowdSec Bouncer/'.self::VERSION;
2225

2326
/** @var int The timeout when calling LAPI or CAPI */
2427
public const API_TIMEOUT = 1;

0 commit comments

Comments
 (0)