-
Notifications
You must be signed in to change notification settings - Fork 7
/
create_release.sh
59 lines (51 loc) · 1.79 KB
/
create_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
#!/bin/bash
set -ex
export VERSION=$1
export RELEASE_NAME=$(basename "$GITHUB_REPO")
## Create Release
export RELEASE_URL=$(curl -H\
"Authorization: token $GITHUB_TOKEN"\
-d "{\"tag_name\": \"$VERSION\", \"target_commitsh\": \"$VERSION\", \"name\": \"$VERSION\", \"body\": \"Release $VERSION\" }"\
-H "Content-Type: application/json"\
-X POST\
https://api.github.com/repos/"$GITHUB_REPO"/releases \
| grep \"url\" | grep releases | sed -e 's/.*\(https.*\)\"\,/\1/' | sed -e 's/api/uploads/')
## Build TF modules that require source building
function create_zip_file() {
BUILD_DIR=/tmp/${RELEASE_NAME}
DESTINATION_DIR=${PWD}/dist
rm -rf "${DESTINATION_DIR}"
mkdir -p "${BUILD_DIR}" "${DESTINATION_DIR}"
cp -r modules "${BUILD_DIR}"
cp -- *tf "${BUILD_DIR}"
cd "${BUILD_DIR}"
sed -i "s/VERSION_SUB/${VERSION}/g" variables.tf
zip -r9 "${RELEASE_NAME}".zip .
mv "${RELEASE_NAME}".zip "${DESTINATION_DIR}"/.
cd "$DESTINATION_DIR"
rm -rf "${BUILD_DIR}"
}
function create_wheel() {
pip install -r requirements_dev.txt
python -m build --wheel --outdir . .
}
#### Release package
create_zip_file
### Post the release
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" --data-binary "@${RELEASE_NAME}.zip" \
-H "Content-type: application/octet-stream" \
"$RELEASE_URL"/assets?name="${RELEASE_NAME}".zip
### Create and post the wheel
cd ../
create_wheel
content=$(cat ./dmrpp_generator/version.py)
[[ $content =~ ([0-9]+.[0-9]+.[0-9]+) ]]
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"$RELEASE_URL/assets?name=dmrpp_generator-${BASH_REMATCH[1]}-py3-none-any.whl" \
--data-binary "@dmrpp_generator-${BASH_REMATCH[1]}-py3-none-any.whl"