-
Notifications
You must be signed in to change notification settings - Fork 5
210 lines (149 loc) · 6.65 KB
/
python-publish.yml
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# This workflow will increment the release version number
# Validates new version
# Publishes to PyPi
# Validates new release
# Publishes to Conda
# Creates new GitHub release
name: Publish Release
on:
push:
branches:
- main
jobs:
release:
if: contains(github.event.head_commit.message, 'bump') && github.actor == 'KulikDM'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Increment version number
run: |
printf "Reading the current version from the file\n"
current_version=$(grep -oP "__version__ = '\K(\d+\.\d+\.\d+)" pythresh/version.py)
if [[ -z $current_version ]]; then
current_version="0.0.0"
printf "\nIssue fetching current version $current_version\n"
exit 1
fi
printf "\nIncrementing the version number\n"
IFS='.' read -r -a version_parts <<< "$current_version"
patch=$(( ${version_parts[2]} + 1 ))
printf "\nHandling version part overflow\n"
if (( patch > 9 )); then
patch=0
minor=$(( ${version_parts[1]} + 1 ))
if (( minor > 9 )); then
minor=0
major=$(( ${version_parts[0]} + 1 ))
else
major=${version_parts[0]}
fi
else
minor=${version_parts[1]}
major=${version_parts[0]}
fi
new_version="${major}.${minor}.$patch"
printf "\nUpdating the file with the new version number\n"
sed -i "s/__version__ = '${current_version}'/__version__ = '${new_version}'/" pythresh/version.py
echo "new_version=$new_version" >> $GITHUB_ENV
echo "WORK_DIR=$(pwd)" >> $GITHUB_ENV
printf "\nNew version updated from $current_version to $new_version\n"
- name: Validate new PyPi version
run: |
printf "Getting lastest pypi information\n"
url="https://pypi.org/pypi/pythresh/json"
current_pypi_version=$(curl -s "$url" | jq -r '.info.version')
printf "\nValidating version update\n"
if [ "$current_pypi_version" == "${{ env.new_version }}" ]; then
printf "\nCurrent PyPi version $current_pypi_version matches ${{ env.new_version }}\n"
exit 1
fi
printf "\nNew version validated\n"
- name: Commit and push changes
env:
GIT_USER: ${{ secrets.GIT_USER }}
GIT_EMAIL: ${{ secrets.GIT_EMAIL }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
run: |
printf "Preparing to commit\n"
git config --global user.name $GIT_USER
git config --global user.email $GIT_EMAIL
git commit -a -m "Updated to version ${{ env.new_version }}"
printf "\nPushing the changes to the repository\n"
git push origin main
printf "\nNew version commited\n"
sleep 1m
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
printf "Preparing to install dependancies\n"
python -m pip install --upgrade pip setuptools wheel twine
python setup.py sdist
printf "\nPackage created locally\n"
twine upload dist/*
printf "\nNew PyPi release created\n"
sleep 10m
- name: Validate new Conda version
run: |
printf "Getting lastest pypi information\n"
url="https://pypi.org/pypi/pythresh/json"
latest_version=$(curl -s "$url" | jq -r '.info.version')
latest_sha256=$(curl -s "$url" | jq -r '.releases."'"$latest_version"'"[0].digests."sha256"')
echo "Validating version update"
if [ "$latest_version" != "${{ env.new_version }}" ]; then
printf "\nNew Conda version $latest_version does not match new PyPi version ${{ env.new_version }}\n"
exit 1
fi
echo "latest_version=$latest_version" >> $GITHUB_ENV
echo "latest_sha256=$latest_sha256" >> $GITHUB_ENV
printf "\nNew PyPi version validated\n"
- name: Update Conda feedstock repository
env:
GIT_USER: ${{ secrets.GIT_USER }}
GIT_EMAIL: ${{ secrets.GIT_EMAIL }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
run: |
printf "Preparing to clone feedstock repository\n"
git config --global user.name $GIT_USER
git config --global user.email $GIT_EMAIL
git clone https://$GIT_USER:[email protected]/conda-forge/pythresh-feedstock.git
cd pythresh-feedstock
printf "\nReading the original meta.yaml file\n"
meta_yaml=$(cat recipe/meta.yaml)
printf "\nUpdating the version and sha256\n"
updated_meta_yaml=$(echo "{% set name = \"pythresh\" %}" && echo "{% set version = \"${{ env.latest_version }}\" %}" && tail -n +3 recipe/meta.yaml | sed -E "s/sha256: .*$/sha256: ${{ env.latest_sha256 }}/")
printf "\nWriting the updated meta.yaml file\n"
echo "$updated_meta_yaml" > recipe/meta.yaml
printf "\nCommitting the changes\n"
git add recipe/meta.yaml
git commit -m "Update to version ${{ env.latest_version }}"
printf "\nPushing the changes to the repository"
git push origin main
printf "\nNew Conda release created\n"
- name: Create GitHub release
env:
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
run: |
printf "Preparing to create new GitHub release\n"
cd "${{ env.WORK_DIR }}"
TAG_NAME="v${{ env.latest_version }}"
RELEASE_TITLE=$TAG_NAME
printf "\nCreating release notes\n"
RELEASE_NOTES="## What's Changed"$'\n'
while IFS= read -r line; do
RELEASE_NOTES+="* $line"$'\n'
done < <(grep -A 1 "v<${{ env.latest_version }}>," CHANGES.txt | grep -o -- "-- .*" | sed -e "s/^-- //")
RELEASE_NOTES=$(echo "$RELEASE_NOTES" | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')
printf "\nPosting new release\n"
JSON_DATA="{ \"tag_name\": \"$TAG_NAME\", \"name\": \"$RELEASE_TITLE\", \"body\": \"$RELEASE_NOTES\", \"draft\": false, \"prerelease\": false }"
curl -X POST "https://api.github.com/repos/KulikDM/pythresh/releases" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GIT_TOKEN" \
-d "$JSON_DATA"
printf "\nNew release posted succesfully\n"