forked from WiktorJ/github-tag-action
-
Notifications
You must be signed in to change notification settings - Fork 3
/
entrypoint.sh
executable file
·68 lines (50 loc) · 1.64 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
#!/bin/bash
set -e
if [ -z "$GITHUB_TOKEN" ]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi
default_semvar_bump=${BUMP:-minor}
with_v=${WITH_V:-true}
repo_fullname=$(jq -r ".repository.full_name" "$GITHUB_EVENT_PATH")
git remote set-url origin https://x-access-token:[email protected]/$repo_fullname.git
git config --global user.email "[email protected]"
git config --global user.name "GitHub Merge Action"
set -o xtrace
git fetch origin $BRANCH
git checkout $BRANCH
# get latest tag
tag=$(git tag --sort=-creatordate | head -n 1)
echo "tag before latest check: $tag"
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 [ "$tag" == "latest" ]; then
tag=$(git tag --sort=-creatordate | head -n 2 | tail -n 1)
fi
echo "tag before update: $tag"
# if there are none or it's still latest or v, start tags at 0.0.0
if [ -z "$tag" ] || [ "$tag" == "latest" ] || [ "$tag" == "v" ]; then
echo "Tag does not mmatch semver scheme X.Y.Z(-PRERELEASE)(+BUILD). Changing to 0.0.0'"
tag="0.0.0"
fi
new=$(semver bump $default_semvar_bump $tag);
if [ "$new" != "none" ]; then
# prefix with 'v'
if $with_v; then
new="v$new"
fi
echo "new tag: $new"
# push new tag ref to github
dt=$(date '+%Y-%m-%dT%H:%M:%SZ')
full_name=$GITHUB_REPOSITORY
echo "$dt: **pushing tag $new to repo $full_name"
git tag -a -m "release: ${new}" $new $commit
fi
git push origin :refs/tags/latest
git tag -fa -m "latest release" latest $commit
git push --follow-tag