Repository navigation
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·55 lines (45 loc) · 1.53 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·55 lines (45 loc) · 1.53 KB
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
#!/bin/bash
# Release a new version: bump the version on the current branch (usually develop), merge it into
# main and push both. CI then publishes to PyPI and creates the v<version> tag and GitHub release.
#
# Usage: ./release.sh <version>
set -e
PACKAGE="pyos"
REMOTE="muhrin"
RELEASE_BRANCH="main"
VERSION_FILE="src/${PACKAGE}/version.py"
version=$1
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+([a-z0-9.]*)$ ]]; then
echo "Usage: $0 <version> (e.g. 0.2.0)"
exit 1
fi
if [[ -n $(git status --porcelain --untracked-files=no) ]]; then
echo "There are uncommitted changes, please commit or stash them first"
exit 1
fi
current_branch=$(git rev-parse --abbrev-ref HEAD)
while true; do
read -p "Release version ${version} from ${current_branch}? " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
set -x
sed -i "s/^__version__ = .*/__version__ = \"${version}\"/" $VERSION_FILE
git add $VERSION_FILE
git commit -m "Release ${version}"
# Merge into the release branch (creating it if needed)
git fetch $REMOTE
if git show-ref --verify --quiet refs/heads/$RELEASE_BRANCH; then
git checkout $RELEASE_BRANCH
elif git show-ref --verify --quiet refs/remotes/$REMOTE/$RELEASE_BRANCH; then
git checkout -b $RELEASE_BRANCH --track $REMOTE/$RELEASE_BRANCH
else
git checkout -b $RELEASE_BRANCH
fi
git merge --no-edit $current_branch
git checkout $current_branch
# Pushing the release branch triggers the publish job
git push $REMOTE $RELEASE_BRANCH $current_branch