-
Notifications
You must be signed in to change notification settings - Fork 4
199 lines (145 loc) · 6.18 KB
/
python-publish.yml
File metadata and controls
199 lines (145 loc) · 6.18 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
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
# 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, 'release') && github.actor == 'KulikDM'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
token: ${{ secrets.GIT_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install dependencies
run: |
set -euo pipefail
pip install --upgrade pip setuptools wheel
pip install bump-my-version build twine
- name: Configure Git
run: |
git config --global user.name "${{ secrets.GIT_USER }}"
git config --global user.email "${{ secrets.GIT_EMAIL }}"
- name: Bump version
run: |
set -euo pipefail
COMMIT_MSG="${{ github.event.head_commit.message }}"
echo "Commit message: $COMMIT_MSG"
if [[ "$COMMIT_MSG" =~ patch ]]; then
BUMP_TYPE="patch"
elif [[ "$COMMIT_MSG" =~ minor ]]; then
BUMP_TYPE="minor"
elif [[ "$COMMIT_MSG" =~ major ]]; then
BUMP_TYPE="major"
else
echo "No bump type found, defaulting to patch."
BUMP_TYPE="patch"
fi
echo "Bumping version type: $BUMP_TYPE"
bump-my-version bump "$BUMP_TYPE" \
--no-tag \
--commit \
--message "Bump version: {current_version} → {new_version} [skip ci]"
- name: Push version bump
run: |
set -euo pipefail
git push --follow-tags
new_version=$(PYTHONPATH=. python -c "import pythresh; print(pythresh.__version__)")
echo "new_version=$new_version" >> $GITHUB_ENV
echo "WORK_DIR=$(pwd)" >> $GITHUB_ENV
- name: Validate new PyPi version
run: |
set -euo pipefail
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"
sleep 1m
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
set -euo pipefail
printf "Preparing to install dependancies\n"
python -m build
printf "\nPackage created locally\n"
twine check --strict dist/*
printf "\nChecks passed\n"
twine upload --verbose dist/*
printf "\nNew PyPi release created\n"
sleep 10m
- name: Validate new Conda version
run: |
set -euo pipefail
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"'"[] | select(.packagetype == "sdist") | .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_TOKEN: ${{ secrets.GIT_TOKEN }}
run: |
set -euo pipefail
printf "Preparing to clone feedstock repository\n"
git clone https://$GIT_USER:$GIT_TOKEN@github.com/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: |
set -euo pipefail
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"