-
Notifications
You must be signed in to change notification settings - Fork 9
93 lines (81 loc) · 2.39 KB
/
publish.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
name: Tag new versions
on:
push:
branches: [main]
workflow_dispatch:
jobs:
version-check:
name: Check dynamic version
outputs:
v: ${{ steps.get_version.outputs.v }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: pyproject.toml
- name: Install Python 3.13
run: uv python install 3.13
- name: Get version string
id: get_version
run: |
uv run --no-project - <<EOF
import os
import subprocess
from pathlib import Path
from aoc_wim import __version__
rc = subprocess.run(["git", "tag", "-l", __version__], check=True, capture_output=True)
if rc.stdout:
print(f"version {__version__} is already tagged")
else:
print(f"version {__version__} is new")
path = Path(os.environ["GITHUB_OUTPUT"])
path.write_text(f"v={__version__}\n")
EOF
version-tag:
name: Tag new versions
runs-on: ubuntu-latest
needs: version-check
if: needs.version-check.outputs.v
steps:
- name: Create tag ${{ needs.version-check.outputs.v }}
uses: actions/github-script@v5
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ needs.version-check.outputs.v }}',
sha: context.sha
})
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
needs: version-tag
if: needs.version-check.outputs.v
environment:
name: pypi
url: https://pypi.org/p/advent-of-code-wim
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: pyproject.toml
- name: Install Python 3.13
run: uv python install 3.13
- name: Build package
run: |
uv venv
uv pip install build
.venv/bin/pyproject-build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1