forked from anothrNick/github-tag-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·92 lines (75 loc) · 1.93 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
86
87
88
89
90
91
92
#!/bin/bash
# config
default_semvar_bump=${DEFAULT_BUMP:-minor}
with_v=${WITH_V:-false}
release_branches=${RELEASE_BRANCHES:-master}
custom_tag=${CUSTOM_TAG}
pre_release="true"
IFS=',' read -ra branch <<< "$release_branches"
for b in "${branch[@]}"; do
echo "Is $b a match for ${GITHUB_REF#'refs/heads/'}"
if [[ "${GITHUB_REF#'refs/heads/'}" =~ $b ]]
then
pre_release="false"
fi
done
echo "pre_release = $pre_release"
# get latest tag
tag=$(git describe --tags `git rev-list --tags --max-count=1`)
tag_commit=$(git rev-list -n 1 $tag)
# get current commit hash for tag
commit=$(git rev-parse HEAD)
if [ "$tag_commit" == "$commit" ]; then
echo "No new commits since previous tag. Skipping..."
exit 0
fi
# if there are none, start tags at 0.0.0
if [ -z "$tag" ]
then
log=$(git log --pretty=oneline)
tag=0.0.0
else
log=$(git log $tag..HEAD --pretty=oneline)
fi
# get commit logs and determine home to bump the version
# supports #major, #minor, #patch (anything else will be 'minor')
case "$log" in
*#major* ) new=$(semver bump major $tag);;
*#minor* ) new=$(semver bump minor $tag);;
*#patch* ) new=$(semver bump patch $tag);;
* ) new=$(semver bump `echo $default_semvar_bump` $tag);;
esac
# prefix with 'v'
if $with_v
then
new="v$new"
fi
if $pre_release
then
new="$new-${commit:0:7}"
fi
if [ ! -z $custom_tag ]
then
new="$custom_tag"
fi
echo $new
# set output
echo ::set-output name=new_tag::$new
if $pre_release
then
echo "This branch is not a release branch. Skipping the tag creation."
exit 0
fi
# push new tag ref to github
dt=$(date '+%Y-%m-%dT%H:%M:%SZ')
full_name=$GITHUB_REPOSITORY
git_refs_url=$(jq .repository.git_refs_url $GITHUB_EVENT_PATH | tr -d '"' | sed 's/{\/sha}//g')
echo "$dt: **pushing tag $new to repo $full_name"
curl -s -X POST $git_refs_url \
-H "Authorization: token $GITHUB_TOKEN" \
-d @- << EOF
{
"ref": "refs/tags/$new",
"sha": "$commit"
}
EOF