Repository navigation
70 lines (61 loc) · 2.08 KB
/
Copy pathpublish.yml
File metadata and controls
70 lines (61 loc) · 2.08 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
name: Release & Publish
on:
push:
branches: [main]
paths:
- 'reloop_email/**'
- 'pyproject.toml'
- '.github/workflows/publish.yml'
workflow_dispatch:
jobs:
release-and-publish:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
- name: Get version from pyproject.toml
id: version
run: |
VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
echo "📦 Version: $VERSION"
- name: Check if release already exists
id: check
run: |
if gh release view "${{ steps.version.outputs.tag }}" > /dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "⏭️ Release ${{ steps.version.outputs.tag }} already exists, skipping."
else
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "🚀 New release ${{ steps.version.outputs.tag }} will be created."
fi
env:
GH_TOKEN: ${{ github.token }}
- name: Set up Python
if: steps.check.outputs.exists == 'false'
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
if: steps.check.outputs.exists == 'false'
run: |
python -m pip install --upgrade pip
pip install hatch
- name: Build package
if: steps.check.outputs.exists == 'false'
run: hatch build
- name: Publish to PyPI
if: steps.check.outputs.exists == 'false'
uses: pypa/gh-action-pypi-publish@release/v1
- name: Create GitHub Release
if: steps.check.outputs.exists == 'false'
run: |
gh release create "${{ steps.version.outputs.tag }}" \
--title "v${{ steps.version.outputs.version }}" \
--generate-notes \
dist/*
env:
GH_TOKEN: ${{ github.token }}