Skip to content

Commit 0cd4885

Browse files
committed
automatic pypi release
1 parent 0a9e2d3 commit 0cd4885

2 files changed

Lines changed: 144 additions & 38 deletions

File tree

.github/workflows/publishpypi.yml

Lines changed: 143 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,148 @@
1-
"name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI
1+
name: release
22

3-
on: push
3+
on:
4+
push:
5+
tags:
6+
- "[0-9]+.[0-9]+.[0-9]+"
7+
- "[0-9]+.[0-9]+.[0-9]+a[0-9]+"
8+
- "[0-9]+.[0-9]+.[0-9]+b[0-9]+"
9+
- "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
10+
11+
env:
12+
PACKAGE_NAME: "yake"
13+
OWNER: "LIAAD"
414

515
jobs:
6-
build-n-publish:
7-
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
16+
unit-test:
17+
uses: LIAAD/yake/.github/workflows/test.yml
18+
19+
details:
20+
runs-on: ubuntu-latest
21+
needs: unit-test
22+
outputs:
23+
new_version: ${{ steps.release.outputs.new_version }}
24+
suffix: ${{ steps.release.outputs.suffix }}
25+
tag_name: ${{ steps.release.outputs.tag_name }}
26+
steps:
27+
- name: Check Ref Type
28+
if: github.ref_type != 'tag'
29+
run: echo "This is not a tag; exiting"; exit 1
30+
31+
- name: Extract tag and Details
32+
id: release
33+
run: |
34+
TAG_NAME=${GITHUB_REF#refs/tags/}
35+
NEW_VERSION=$(echo $TAG_NAME | awk -F'-' '{print $1}')
36+
SUFFIX=$(echo $TAG_NAME | grep -oP '[a-z]+[0-9]+' || echo "")
37+
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
38+
echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT"
39+
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
40+
41+
- name: Debug Outputs
42+
if: env.RUNNER_DEBUG
43+
run: |
44+
echo "Version is ${{ steps.release.outputs.new_version }}"
45+
echo "Suffix is ${{ steps.release.outputs.suffix }}"
46+
echo "Tag name is ${{ steps.release.outputs.tag_name }}"
47+
48+
check_pypi:
49+
needs: details
850
runs-on: ubuntu-latest
951
steps:
10-
- uses: actions/checkout@master
11-
- name: Set up Python 3.9
12-
uses: actions/setup-python@v1
13-
with:
14-
python-version: 3.9
15-
- name: Install pypa/build
16-
run: >-
17-
python -m
18-
pip install
19-
build
20-
--user
21-
- name: Build a binary wheel and a source tarball
22-
run: >-
23-
python -m
24-
build
25-
--sdist
26-
--wheel
27-
--outdir dist/
28-
.
29-
- name: Publish distribution 📦 to Test PyPI
30-
uses: pypa/gh-action-pypi-publish@release/v1
31-
with:
32-
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
33-
repository_url: https://test.pypi.org/legacy/
34-
skip_existing: true
35-
- name: Publish distribution 📦 to PyPI
36-
if: startsWith(github.ref, 'refs/tags')
37-
uses: pypa/gh-action-pypi-publish@release/v1
38-
with:
39-
password: ${{ secrets.PYPI_API_TOKEN }}
40-
"
41-
42-
#não está a funcionar pq não tenho as secret keys
52+
- name: Fetch information from PyPI
53+
run: |
54+
response=$(curl -s https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json || echo "{}")
55+
latest_previous_version=$(echo $response | grep -oP '"releases":\{"\K[^"]+' | sort -rV | head -n 1)
56+
if [ -z "$latest_previous_version" ]; then
57+
echo "Package not found on PyPI."
58+
latest_previous_version="0.0.0"
59+
fi
60+
echo "Latest version on PyPI: $latest_previous_version"
61+
echo "latest_previous_version=$latest_previous_version" >> $GITHUB_ENV
62+
63+
- name: Compare versions and exit if not newer
64+
run: |
65+
NEW_VERSION=${{ needs.details.outputs.new_version }}
66+
LATEST_VERSION=$latest_previous_version
67+
if [ "$(printf '%s\n' "$LATEST_VERSION" "$NEW_VERSION" | sort -rV | head -n 1)" != "$NEW_VERSION" ] || [ "$NEW_VERSION" == "$LATEST_VERSION" ]; then
68+
echo "The new version $NEW_VERSION is not greater than the latest version $LATEST_VERSION on PyPI."
69+
exit 1
70+
else
71+
echo "The new version $NEW_VERSION is greater than the latest version $LATEST_VERSION on PyPI."
72+
fi
73+
74+
setup_and_build:
75+
needs: [details, check_pypi]
76+
runs-on: ubuntu-latest
77+
steps:
78+
- uses: actions/checkout@v4
79+
80+
- name: Set up Python
81+
uses: actions/setup-python@v5
82+
83+
- name: Install uv
84+
uses: astral-sh/setup-uv@v4
85+
86+
- name: Bump version
87+
run: |
88+
NEW_VERSION="${{ needs.details.outputs.new_version }}"
89+
sed -i "s/version = \"[0-9]*\.[0-9]*\.[0-9]*\"/version = \"$NEW_VERSION\"/" $GITHUB_WORKSPACE/pyproject.toml
90+
91+
- name: Install dependencies
92+
run: uv sync
93+
94+
- name: Build source and wheel distribution
95+
run: uv build
96+
97+
- name: Upload artifacts
98+
uses: actions/upload-artifact@v4
99+
with:
100+
name: dist
101+
path: dist/
102+
103+
pypi_publish:
104+
name: Upload release to PyPI
105+
needs: [setup_and_build, details]
106+
runs-on: ubuntu-latest
107+
environment:
108+
name: release
109+
permissions:
110+
id-token: write
111+
steps:
112+
- name: Download artifacts
113+
uses: actions/download-artifact@v4
114+
with:
115+
name: dist
116+
path: dist/
117+
118+
- name: Install uv
119+
uses: astral-sh/setup-uv@v4
120+
121+
- name: Publish to PyPI
122+
run: uv publish
123+
124+
github_release:
125+
name: Create GitHub Release
126+
needs: [setup_and_build, details]
127+
runs-on: ubuntu-latest
128+
env:
129+
TAG_NAME: ${{ needs.details.outputs.tag_name }}
130+
permissions:
131+
contents: write
132+
steps:
133+
- name: Checkout Code
134+
uses: actions/checkout@v4
135+
with:
136+
fetch-depth: 0
137+
138+
- name: Download artifacts
139+
uses: actions/download-artifact@v4
140+
with:
141+
name: dist
142+
path: dist/
143+
144+
- name: Create GitHub Release
145+
id: create_release
146+
run: gh release create ${{ env.TAG_NAME }} dist/* --title "Release ${{ env.TAG_NAME }}" --generate-notes
147+
env:
148+
GH_TOKEN: ${{ github.token }}

yake/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
__author__ = """vitordouzi"""
66
__email__ = "vitordouzi@gmail.com"
7-
__version__ = "0.4.8"
7+
__version__ = "0.6.0"
88

99
from yake.core.yake import KeywordExtractor as KeywordExtractor

0 commit comments

Comments
 (0)