Skip to content

Commit c512e2e

Browse files
committed
Update publishpypi.yml
1 parent 764ab0e commit c512e2e

1 file changed

Lines changed: 40 additions & 157 deletions

File tree

.github/workflows/publishpypi.yml

Lines changed: 40 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,187 +1,70 @@
1-
name: release
1+
# This workflow will upload a Python Package to PyPI when a release is created
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
210

311
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]+"
1012
release:
1113
types: [published]
1214

13-
env:
14-
PACKAGE_NAME: "yake"
15-
OWNER: "LIAAD"
15+
permissions:
16+
contents: read
1617

1718
jobs:
18-
unit-test:
19-
runs-on: ubuntu-latest
20-
strategy:
21-
matrix:
22-
python-version: ["3.8", "3.9", "3.10", "3.11"]
23-
steps:
24-
- uses: actions/checkout@v4
25-
26-
- name: Set up Python ${{ matrix.python-version }}
27-
uses: actions/setup-python@v5
28-
with:
29-
python-version: ${{ matrix.python-version }}
30-
31-
- name: Install uv
32-
uses: astral-sh/setup-uv@v4
33-
34-
- name: Install dependencies
35-
run: |
36-
uv sync
37-
uv sync --extra dev
38-
39-
- name: Run tests
40-
run: uv run pytest
41-
42-
details:
43-
runs-on: ubuntu-latest
44-
needs: unit-test
45-
outputs:
46-
new_version: ${{ steps.release.outputs.new_version }}
47-
suffix: ${{ steps.release.outputs.suffix }}
48-
tag_name: ${{ steps.release.outputs.tag_name }}
49-
steps:
50-
- name: Check Ref Type and Debug
51-
run: |
52-
echo "Event name: ${{ github.event_name }}"
53-
echo "Ref type: ${{ github.ref_type }}"
54-
echo "Ref: ${{ github.ref }}"
55-
echo "SHA: ${{ github.sha }}"
56-
if [[ "${{ github.ref_type }}" != "tag" ]]; then
57-
echo "This is not a tag; exiting"
58-
exit 1
59-
fi
60-
echo "This is a tag - proceeding"
61-
62-
- name: Extract tag and Details
63-
id: release
64-
run: |
65-
if [[ "${{ github.event_name }}" == "release" ]]; then
66-
TAG_NAME="${{ github.event.release.tag_name }}"
67-
else
68-
TAG_NAME=${GITHUB_REF#refs/tags/}
69-
fi
70-
NEW_VERSION=$(echo $TAG_NAME | awk -F'-' '{print $1}')
71-
SUFFIX=$(echo $TAG_NAME | grep -oP '[a-z]+[0-9]+' || echo "")
72-
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
73-
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
74-
echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT"
75-
echo "Processing tag: $TAG_NAME"
76-
echo "Version: $NEW_VERSION"
77-
78-
- name: Debug Outputs
79-
if: env.RUNNER_DEBUG
80-
run: |
81-
echo "Version is ${{ steps.release.outputs.new_version }}"
82-
echo "Suffix is ${{ steps.release.outputs.suffix }}"
83-
echo "Tag name is ${{ steps.release.outputs.tag_name }}"
84-
85-
check_pypi:
86-
needs: details
19+
release-build:
8720
runs-on: ubuntu-latest
88-
steps:
89-
- name: Fetch information from PyPI
90-
run: |
91-
response=$(curl -s https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json || echo "{}")
92-
latest_previous_version=$(echo $response | jq -r '.releases | keys | .[]' 2>/dev/null | sort -rV | head -n 1 || echo "0.0.0")
93-
if [ -z "$latest_previous_version" ] || [ "$latest_previous_version" == "null" ]; then
94-
echo "Package not found on PyPI."
95-
latest_previous_version="0.0.0"
96-
fi
97-
echo "Latest version on PyPI: $latest_previous_version"
98-
echo "latest_previous_version=$latest_previous_version" >> $GITHUB_ENV
9921

100-
- name: Compare versions and exit if not newer
101-
run: |
102-
NEW_VERSION=${{ needs.details.outputs.new_version }}
103-
LATEST_VERSION=$latest_previous_version
104-
if [ "$(printf '%s\n' "$LATEST_VERSION" "$NEW_VERSION" | sort -rV | head -n 1)" != "$NEW_VERSION" ] || [ "$NEW_VERSION" == "$LATEST_VERSION" ]; then
105-
echo "The new version $NEW_VERSION is not greater than the latest version $LATEST_VERSION on PyPI."
106-
exit 1
107-
else
108-
echo "The new version $NEW_VERSION is greater than the latest version $LATEST_VERSION on PyPI."
109-
fi
110-
111-
setup_and_build:
112-
needs: [details, check_pypi]
113-
runs-on: ubuntu-latest
11422
steps:
11523
- uses: actions/checkout@v4
11624

117-
- name: Set up Python
118-
uses: actions/setup-python@v5
25+
- uses: actions/setup-python@v5
11926
with:
120-
python-version: "3.10" # Especifica uma versão
27+
python-version: "3.x"
12128

122-
- name: Install uv
123-
uses: astral-sh/setup-uv@v4
124-
125-
- name: Bump version
29+
- name: Build release distributions
12630
run: |
127-
NEW_VERSION="${{ needs.details.outputs.new_version }}"
128-
sed -i "s/version = \"[0-9]*\.[0-9]*\.[0-9]*\"/version = \"$NEW_VERSION\"/" pyproject.toml
129-
130-
- name: Install dependencies
131-
run: uv sync
31+
# NOTE: put your own distribution build steps here.
32+
python -m pip install build
33+
python -m build
13234
133-
- name: Build source and wheel distribution
134-
run: uv build
135-
136-
- name: Upload artifacts
35+
- name: Upload distributions
13736
uses: actions/upload-artifact@v4
13837
with:
139-
name: dist
38+
name: release-dists
14039
path: dist/
14140

142-
pypi_publish:
143-
name: Upload release to PyPI
144-
needs: [setup_and_build, details]
41+
pypi-publish:
14542
runs-on: ubuntu-latest
146-
environment:
147-
name: release
43+
needs:
44+
- release-build
14845
permissions:
46+
# IMPORTANT: this permission is mandatory for trusted publishing
14947
id-token: write
150-
steps:
151-
- name: Download artifacts
152-
uses: actions/download-artifact@v4
153-
with:
154-
name: dist
155-
path: dist/
156-
157-
- name: Install uv
158-
uses: astral-sh/setup-uv@v4
15948

160-
- name: Publish to PyPI
161-
run: uv publish
49+
# Dedicated environments with protections for publishing are strongly recommended.
50+
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
51+
environment:
52+
name: pypi
53+
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
54+
url: https://pypi.org/p/yake
55+
#
56+
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string
57+
# ALTERNATIVE: exactly, uncomment the following line instead:
58+
# url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
16259

163-
github_release:
164-
name: Create GitHub Release
165-
needs: [setup_and_build, details]
166-
runs-on: ubuntu-latest
167-
env:
168-
TAG_NAME: ${{ needs.details.outputs.tag_name }}
169-
permissions:
170-
contents: write
17160
steps:
172-
- name: Checkout Code
173-
uses: actions/checkout@v4
174-
with:
175-
fetch-depth: 0
176-
177-
- name: Download artifacts
61+
- name: Retrieve release distributions
17862
uses: actions/download-artifact@v4
17963
with:
180-
name: dist
64+
name: release-dists
18165
path: dist/
18266

183-
- name: Create GitHub Release
184-
id: create_release
185-
run: gh release create ${{ env.TAG_NAME }} dist/* --title "Release ${{ env.TAG_NAME }}" --generate-notes
186-
env:
187-
GH_TOKEN: ${{ github.token }}
67+
- name: Publish release distributions to PyPI
68+
uses: pypa/gh-action-pypi-publish@release/v1
69+
with:
70+
packages-dir: dist/

0 commit comments

Comments
 (0)