-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease.sh
84 lines (69 loc) · 2.66 KB
/
release.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
# accept cli params for type of the release and describe if nothin is choosen
RELEASE_TYPE=$1
if [ -z "$RELEASE_TYPE" ]; then
echo "Please provide release type: major, minor or patch"
exit 1
fi
# check if release type is valid
if [ "$RELEASE_TYPE" != "major" ] && [ "$RELEASE_TYPE" != "minor" ] && [ "$RELEASE_TYPE" != "patch" ]; then
echo "Invalid release type. Please provide major, minor or patch"
exit 1
fi
# get last release version from last-release-verion.txt
LAST_VERSION=$(cat last-release-version.txt)
# increment version based on release type
if [ "$RELEASE_TYPE" == "major" ]; then
IFS='.' read -r -a VERSION <<< "$LAST_VERSION"
VERSION=$((VERSION[0] + 1)).0.0
elif [ "$RELEASE_TYPE" == "minor" ]; then
IFS='.' read -r -a VERSION <<< "$LAST_VERSION"
VERSION=${VERSION[0]}.$((VERSION[1] + 1)).0
elif [ "$RELEASE_TYPE" == "patch" ]; then
IFS='.' read -r -a VERSION <<< "$LAST_VERSION"
VERSION=${VERSION[0]}.${VERSION[1]}.$((VERSION[2] + 1))
fi
# confirm that you want to release version
read -p "Releasing version $VERSION - are you sure? (y/n) " -n 1 -r
# check if everything is commited in git repo
if [ -n "$(git status --porcelain)" ]; then
echo "There are uncommited changes. Please commit or stash them before releasing."
exit 1
fi
# read commit changes from last version to current version
# add two new lines to the end of the each line in the commit log
LOG=$(git log --pretty=format:"%h %s" $LAST_VERSION..HEAD)
LOG=$(echo "$LOG" | sed -e 's/$/ /g')
# read yfinance version from requirements.txt
YFINANCE_VERSION=$(grep yfinance requirements.txt | cut -d'=' -f2)
# add to the change log
# current version as a header
# version of yfinance
# all commit logs since last version
echo "## $VERSION" > tmpfile
echo "" >> tmpfile
echo "### Dependencies" >> tmpfile
echo "" >> tmpfile
echo "- yfinance: $YFINANCE_VERSION" >> tmpfile
echo "" >> tmpfile
echo "### Changes" >> tmpfile
echo "" >> tmpfile
echo "$LOG" >> tmpfile
echo "" >> tmpfile
echo "" >> tmpfile
cat CHANGELOG.MD >> tmpfile
mv tmpfile CHANGELOG.MD
# update and push changelog
git add CHANGELOG.MD
git commit -m "Update changelog for version $VERSION"
# create and commit tag with version name
git tag $VERSION
# update and push last-release-version.txt
echo $VERSION > last-release-version.txt
# update all occurence of last version in the README.md to the new version
sed -i "" "s/$LAST_VERSION/$VERSION/g" README.md
git add README.MD
git add last-release-version.txt
git commit -m "Update last release version to $VERSION"
git push origin $VERSION
git push origin main
docker buildx build --platform linux/amd64,linux/arm64 -t yarhrn/yfinance-server:$VERSION -t yarhrn/yfinance-server:latest --push .