-
Notifications
You must be signed in to change notification settings - Fork 1
/
setArtifactVersion.sh
executable file
·38 lines (34 loc) · 1.06 KB
/
setArtifactVersion.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
#!/bin/bash
set -e
appversionFile=${1:-package/.appversion}
verifyReleaseVersion(){
version=$1
tagCount=$(curl -s https://api.github.com/repos/$GITHUB_REPOSITORY/tags | jq --arg tagName "$version" '[.[] | select( .name == $tagName)] | length')
if [ $tagCount -gt 0 ]; then
echo "Error: Version $version already released. Please update your version in $appversionFile"
exit 1
fi
}
setArtifactVersion(){
version=$1
echo "Setting version $version"
echo "ARTIFACT_VERSION=$version" >> $GITHUB_ENV
}
case $GITHUB_REF in
refs/tags/*)
echo "Current action is for tag.."
setArtifactVersion "$GITHUB_REF_NAME"
;;
refs/heads/release-*)
echo "Current action is for release branch.."
version=$(echo $GITHUB_REF_NAME | cut -d '-' -f 2)
verifyReleaseVersion "$version"
setArtifactVersion "$version"-rc
;;
*)
echo "Current action is neither tag nor release branch.."
version=$(cat "$appversionFile")
verifyReleaseVersion "$version"
setArtifactVersion "$version-$GITHUB_RUN_NUMBER"
;;
esac