-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_release.sh
executable file
·142 lines (103 loc) · 2.61 KB
/
build_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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
#
# script to manage versions and comments used for `git tag`, `build.yml` file
# for Github Actions, `pyproject.toml` file used by `poetry` for the current
# project.
#
#
YAML_FILE='.github/workflows/build.yml'
PYPROJECT_TOML='pyproject.toml'
STATUS=0
check_version_input () {
# check version tag
res=$(echo $NEW_VERSION_TAG | grep -e [0-9]\.[0-9]\.[0-9])
if [[ ! -z $res ]]; then
STATUS=0
else
STATUS=1
echo "Enter correct version. Syntax: [0-9].[0-9].[0-9]."
echo -e "Example: $0 0.1.0\n"
fi
}
change_tag_build_yaml () {
# changes version on YAML file
status_check_code
echo "File: $YAML_FILE"
sed s"/v[0-9]\.[0-9]\.[0-9]/v$1/" $YAML_FILE -i $YAML_FILE
status_get_exit_code
}
change_version_pyproject () {
# change version of TOML file
status_check_code
echo "File: $PYPROJECT_TOML"
sed s"/version = \"[0-9]\.[0-9]\.[0-9]\"/version = \"$1\"/" $PYPROJECT_TOML -i $PYPROJECT_TOML
status_get_exit_code
}
build_requirements () {
# generates requirements.txt
status_check_code
echo "Get related Python packages, requirements.txt".
poetry export --without-hashes --format=requirements.txt --output requirements.txt
status_get_exit_code
}
git_new_tag () {
# git create tag and push
status_check_code
CURRENT_TAG="v$1"
MESSAGE="$CURRENT_TAG $(date +"%D %H:%M:%S.%N")"
echo "Creating new tag - $CURRENT_TAG"
git tag -a $CURRENT_TAG -m "$MESSAGE"
git push origin $CURRENT_TAG
status_get_exit_code
}
git_push_changes_repository () {
# adds, commits and push changes
status_check_code
echo "git_push_changes_repository - $NEW_VERSION_TAG"
if [[ -z "$1" ]]; then
COMMENT="new changes submitted - v$NEW_VERSION_TAG"
else
COMMENT="$1"
fi
git add .
git commit -m "$COMMENT"
git push origin main --force
status_get_exit_code
}
status_get_exit_code () {
# checks status code of last command and
# sets status for this scripts.
if [ $? == 0 ]; then
STATUS=0
else
STATUS=1
fi
}
status_check_code () {
# checks STATUS of script and sets exit code
if [ $STATUS == 1 ]; then
exit 1
fi
}
#
# main code
#
if [ $# -eq 1 ] || [ $# -eq 2 ]; then
NEW_VERSION_TAG="$1"
COMMIT_PUSH="$2"
check_version_input
if [ $STATUS == 0 ]; then
echo -e "\nTag: $NEW_VERSION_TAG, Commit: $COMMIT_PUSH\n"
change_tag_build_yaml $NEW_VERSION_TAG
change_version_pyproject $NEW_VERSION_TAG
build_requirements
git_push_changes_repository "$COMMIT_PUSH"
git_new_tag $NEW_VERSION_TAG
exit 0
else
exit 1
fi
else
echo 'Need only 1 or 2 arguments: 1 = Version, 2 = Comment Commit Git Push'
echo
fi