forked from conda-incubator/conda-store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cut-release-pr.sh
executable file
·128 lines (108 loc) · 3.32 KB
/
cut-release-pr.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# Requirements
# - packages
# - github-activity https://github.com/choldgraf/github-activity
# - jq
# - GITHUB_ACCESS_TOKEN env var set
# - `conda-store-server-dev` conda env is activated
function usage {
echo -e "Usage: ./cut-release-pr.sh -r release_version -c conda_store_ui_version\n"
exit 1
}
function build_and_check () {
# Runs a hatch build, twine check, and checks the version of the package
# Assumes that you are in the directory for the package
#
# args:
# CHECK_TARGET: the name of the package to check
CHECK_TARGET=$1
echo "${CHECK_TARGET}: Checking hatch versions..."
HV=$(hatch version)
if [[ "$HV" == "$RELEASE_VERSION" ]]; then
echo "${CHECK_TARGET}: hatch version matches ${RELEASE_VERSION}"
else
echo "${CHECK_TARGET}: hatch version does not match the requested release version. Something has gone wrong, exiting!"
exit 1
fi
echo "${CHECK_TARGET}: Running build and checking package..."
hatch build
rc=$(twine check dist/*)
if [[ $rc =~ "FAILED" ]]; then
echo "${CHECK_TARGET}: package is not in a good state, exiting!"
exit 1
else
echo "${CHECK_TARGET}: package is in a good state"
fi
echo "${CHECK_TARGET}: cleaning up..."
hatch clean
}
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
usage
exit 0
shift
shift
;;
-r|--release_version)
RELEASE_VERSION="$2"
shift
shift
;;
-c|--conda_store_ui_version)
CONDA_STORE_UI_VERSION="$2"
shift
shift
;;
*)
usage
exit 0
shift
;;
esac
done
CURRENT_DATE=$(date '+%Y-%m-%d')
echo "Today is ${CURRENT_DATE}
Building a release for
* conda-store version ${RELEASE_VERSION}
with
* conda-store-ui version ${CONDA_STORE_UI_VERSION}
"
# prepare repo
git checkout -b release-"$RELEASE_VERSION"
git clean -fxdq
# bump versions
sed -E -r -i "s/__version__ = .+/__version__ = \"$RELEASE_VERSION\"/g" conda-store-server/conda_store_server/__init__.py
sed -E -r -i "s/__version__ = .+/__version__ = \"$RELEASE_VERSION\"/g" conda-store/conda_store/__init__.py
sed -E -r -i "s/CONDA_STORE_UI_VERSION = .+/CONDA_STORE_UI_VERSION = \"$CONDA_STORE_UI_VERSION\"/g" conda-store-server/hatch_build.py
# create changelog
LATEST_TAG=$(curl https://api.github.com/repos/conda-incubator/conda-store/releases | jq -r '.[0].tag_name')
PYTHONWARNINGS="ignore" github-activity conda-incubator/conda-store --since $LATEST_TAG --heading-level=2 > tmp_changes.txt
# remove first line of changes - it's always a message about which GH token is used
sed -n -i '1!p' tmp_changes.txt
# replace the header for the changes with the appropriate title
sed -n -i '1!p' tmp_changes.txt
sed -i "1s/^/## [$RELEASE_VERSION] - $CURRENT_DATE\n/" tmp_changes.txt
# insert changes into changelog
sed -i "/---/r tmp_changes.txt" CHANGELOG.md
# clean up temp file
rm tmp_changes.txt
cd conda-store-server
build_and_check conda-store-server
cd ..
cd conda-store
build_and_check conda-store
cd ..
# add files to git
git add conda-store conda-store-server CHANGELOG.md
git commit -m "REL - $RELEASE_VERSION"
echo "
Finished preparing the release!
Next steps:
* Validate that the changes made are correct
* Follow any testing/validation steps
* Push them changes up to github
git push origin release-"$RELEASE_VERSION"
"