Repository navigation
79 lines (68 loc) · 2.41 KB
/
Copy pathrelease.yml
File metadata and controls
79 lines (68 loc) · 2.41 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
name: Release
on:
push:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
jobs:
release:
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/template-python/
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
with:
python-version: "3.12"
- name: Read package version
id: version
run: |
VERSION="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
- name: Check if version is already published to PyPI
id: pypi-check
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
if curl --fail --silent --show-error "https://pypi.org/pypi/template-python/$VERSION/json" >/dev/null; then
echo "template-python==$VERSION is already on PyPI; skipping package upload"
echo "published=true" >> "$GITHUB_OUTPUT"
else
echo "published=false" >> "$GITHUB_OUTPUT"
fi
- name: Build the package
if: steps.pypi-check.outputs.published != 'true'
run: uv build
- name: Check if GitHub release already exists
id: github-release-check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.version.outputs.tag }}
run: |
if gh api "repos/$GITHUB_REPOSITORY/releases/tags/$TAG" >/dev/null 2>&1; then
echo "GitHub release $TAG already exists; skipping release creation"
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Create GitHub release and tag
if: steps.github-release-check.outputs.exists != 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
target_commitish: ${{ github.sha }}
name: ${{ steps.version.outputs.tag }}
generate_release_notes: true
- name: Publish to PyPI
if: steps.pypi-check.outputs.published != 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist