forked from aurestic/incremental-tag
-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
85 lines (69 loc) · 2.33 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
set -eu
# Set up .netrc file with GitHub credentials
git_setup ( ) {
git config --global user.email "[email protected]"
git config --global user.name "Incremental tag GitHub Action"
}
echo "###################"
echo "Tagging Parameters"
echo "###################"
echo "flag_branch: ${INPUT_FLAG_BRANCH}"
echo "message: ${INPUT_MESSAGE}"
echo "prev_tag: ${INPUT_PREV_TAG}"
echo "update_odoo_module_version: ${INPUT_UPDATE_ODOO_MODULE_VERSION}"
echo "GITHUB_ACTOR: ${GITHUB_ACTOR}"
echo "GITHUB_TOKEN: ${GITHUB_TOKEN}"
echo "HOME: ${HOME}"
echo "###################"
echo ""
echo "Start process..."
echo "1) Setting up git machine..."
git_setup
echo "2) Updating repository tags..."
git fetch origin --tags --quiet
last_tag=""
if [ "${INPUT_FLAG_BRANCH}" = true ];then
branch=$(git rev-parse --abbrev-ref HEAD)
echo "branch: ${branch}";
last_tag=`git describe --tags $(git rev-list --tags) --always|egrep "${INPUT_PREV_TAG}${branch}\.[0-9]*\.[0-9]*$"|sort -V -r|head -n 1`
echo "Last tag: ${last_tag}";
else
last_tag=`git describe --tags $(git rev-list --tags --max-count=1)`
echo "Last tag: ${last_tag}";
fi
if [ -z "${last_tag}" ];then
if [ "${INPUT_FLAG_BRANCH}" != false ];then
last_tag="${INPUT_PREV_TAG}${branch}.1.0";
else
last_tag="${INPUT_PREV_TAG}0.1.0";
fi
echo "Default Last tag: ${last_tag}";
fi
next_tag="${last_tag%.*}.$((${last_tag##*.}+1))"
echo "3) Next tag: ${next_tag}";
if [ "${INPUT_UPDATE_ODOO_MODULE_VERSION}" = true ];then
echo "4) Upload tag for Odoo module...";
git checkout --quiet "${GITHUB_SHA}";
for file in '__openerp__.py' '__manifest__.py';do
if [ ! -f "${file}" ];then
continue
fi
echo "Updating file version ${file}..."
new_version=`echo ${next_tag}|sed "s,^v\(.*\),\1,g"`
sed -i "s,\(\s*.version.*:\).*,\1 \"${new_version}\"\,,g" ${file}
git add ${file}
done
git commit --allow-empty -m "${INPUT_MESSAGE}"
tag_commit=`git rev-parse --verify HEAD`
echo "5) Forcing tag update..."
git tag ${next_tag}
echo "6) Forcing tag push..."
git push --tags
else
echo "4) Forcing tag update..."
git tag -a ${next_tag} -m "${INPUT_MESSAGE}" "${GITHUB_SHA}" -f
echo "5) Forcing tag push..."
git push --tags -f
fi
echo "::set-output name=tag::$next_tag"