-
Notifications
You must be signed in to change notification settings - Fork 6
209 lines (197 loc) · 6.37 KB
/
release.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
name: release
on:
push:
branches:
- "main"
- "master"
jobs:
pypi_version:
runs-on: ubuntu-latest
outputs:
latest_version: ${{ steps.get_pypi_version.outputs.latest_version }}
steps:
- name: Fetch information from PyPI
id: get_pypi_version
run: |
response=$(curl -s https://pypi.org/pypi/${{ github.event.repository.name }}/json || echo "{}")
latest_version=$(echo $response | jq --raw-output "select(.releases != null) | .releases | keys_unsorted | last")
if [ -z "$latest_version" ]; then
echo "Package not found on PyPI."
latest_version="0.0.0"
fi
echo "Latest version on PyPI: $latest_version"
echo "latest_version=$latest_version" >> $GITHUB_OUTPUT
build_package:
needs: [pypi_version]
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.version.outputs.new_version }}
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install Hatch
run: |
python -m pip install --upgrade pip setuptools wheel hatch
- name: Compare current version with PyPI version
id: version
run: |
new_version=$(hatch version)
prev_version=${{ needs.pypi_version.outputs.latest_version }}
if [ "$new_version" == "prev_version" ]; then
echo "No version update. Terminating workflow".
exit 1
fi
higher_version=$(printf '%s\n' "$new_version" "$prev_version" | sort -rV | head -n 1)
if [ "$higher_version" != "$new_version" ]; then
echo "Error! Version ${new_version} is lower than latest version ${prev_version} on PyPI"
exit 2
else
echo "The new version ${new_version} is greater than the latest version ${prev_version} on PyPI."
echo "new_version=${new_version}" >> "$GITHUB_OUTPUT"
fi
- name: Build source and wheel distribution
run: |
hatch build
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
# details:
# runs-on: ubuntu-latest
# outputs:
# new_version: ${{ steps.release.outputs.latest_version }}
# suffix: ${{ steps.release.outputs.suffix }}
# tag_name: ${{ steps.release.outputs.tag_name }}
# steps:
# - uses: actions/checkout@v2
#
# - name: Extract tag and Details
# id: release
# run: |
# if [ "${{ github.ref_type }}" = "tag" ]; then
# TAG_NAME=${GITHUB_REF#refs/tags/}
# NEW_VERSION=$(echo $TAG_NAME | awk -F'-' '{print $1}')
# SUFFIX=$(echo $TAG_NAME | grep -oP '[a-z]+[0-9]+' || echo "")
# echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
# echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT"
# echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
# echo "Version is $NEW_VERSION"
# echo "Suffix is $SUFFIX"
# echo "Tag name is $TAG_NAME"
# else
# echo "No tag found"
# exit 1
# fi
#
# check_pypi:
# needs: details
#
# - name: Compare versions and exit if not newer
# run: |
# NEW_VERSION=${{ needs.details.outputs.new_version }}
# LATEST_VERSION=$latest_previous_version
# if [ "$(printf '%s\n' "$LATEST_VERSION" "$NEW_VERSION" | sort -rV | head -n 1)" != "$NEW_VERSION" ] || [ "$NEW_VERSION" == "$LATEST_VERSION" ]; then
# echo "The new version $NEW_VERSION is not greater than the latest version $LATEST_VERSION on PyPI."
# exit 1
# else
# echo "The new version $NEW_VERSION is greater than the latest version $LATEST_VERSION on PyPI."
# fi
#
# setup_and_build:
# needs: [details, check_pypi]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
#
# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: "3.12"
#
# - name: Install Hatch
# run: |
# python -m pip install --upgrade pip setuptools wheel
# pip install hatch
#
# - name: Set project version with Hatch
# run: |
# hatch version ${{ needs.details.outputs.new_version }}
#
# - name: Build source and wheel distribution
# run: |
# hatch build
#
# - name: Upload artifacts
# uses: actions/upload-artifact@v3
# with:
# name: dist
# path: dist/
#
# pypi_publish:
# name: Upload release to PyPI
# needs: [build_package]
# if: needs.build_package.outputs.new_version
# runs-on: ubuntu-latest
# environment:
# name: release
# url: https://pypi.org/p/${{ env.PACKAGE_NAME }}
# permissions:
# id-token: write
# steps:
# - name: Download artifacts
# uses: actions/download-artifact@v3
# with:
# name: dist
# path: dist/
#
# - name: Publish distribution to PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
#
github_tag:
name: Create GitHub tag
needs: [build_package]
if: needs.build_package.outputs.new_version
runs-on: ubuntu-latest
steps:
- name: Create tag
uses: actions/github-script@v7
env:
NEW_TAG: ${{ needs.build_package.outputs.new_version }}
with:
script: |
const { NEW_TAG } = process.env
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ needs.build_package.outputs.new_version }}',
sha: context.sha
})
# github_release:
# name: Create GitHub Tag aRelease
# needs: [build_package]
# runs-on: ubuntu-latest
# permissions:
# contents: write
# steps:
# - name: Checkout Code
# uses: actions/checkout@v3
# with:
# fetch-depth: 0
#
# - name: Download artifacts
# uses: actions/download-artifact@v3
# with:
# name: dist
# path: dist/
#
# - name: Create GitHub Release
# id: create_release
# env:
# GH_TOKEN: ${{ github.token }}
# run: |
# tag_name = ${{ needs.build_package.outputs.new_version }}
# gh release create ${tag_name} dist/* --title ${tag_name} --generate-notes