File tree Expand file tree Collapse file tree 2 files changed +41
-29
lines changed Expand file tree Collapse file tree 2 files changed +41
-29
lines changed Original file line number Diff line number Diff line change 11name : publish-pypi
22on :
33 release :
4- types : [published] # se dispara cuando semantic-release crea el release
5- workflow_dispatch : # también manual si lo necesitas
4+ types : [published]
5+
66permissions :
7- id-token : write
87 contents : read
8+ id-token : write
9+
10+ env :
11+ PIP_DISABLE_PIP_VERSION_CHECK : " 1"
12+
913jobs :
10- build-and-publish :
14+ pypi :
15+ if : startsWith(github.event.release.tag_name, 'v')
1116 runs-on : ubuntu-latest
1217 environment : pypi
1318 steps :
1419 - uses : actions/checkout@v4
1520 - uses : actions/setup-python@v5
16- with : { python-version: '3.12' }
17- - run : python -m pip install --upgrade pip build
18- - run : python -m build
19- - name : Publish to PyPI (OIDC)
20- uses : pypa/gh-action-pypi-publish@release/v1
2121 with :
22- skip-existing : true
22+ python-version : ' 3.x'
23+ - run : python -m pip install -U pip build
24+ - name : Sync version from tag into pyproject.toml
25+ env :
26+ TAG : ${{ github.event.release.tag_name }}
27+ run : |
28+ VER="${TAG#v}"
29+ export VER
30+ python - <<'PY'
31+ import os, re, pathlib
32+ ver = os.environ["VER"]
33+ p = pathlib.Path("pyproject.toml")
34+ t = p.read_text(encoding="utf-8")
35+ t = re.sub(r'(?m)^(\s*version\s*=\s*")\d+\.\d+\.\d+(")', rf'\1{ver}\2', t)
36+ p.write_text(t, encoding="utf-8")
37+ print("pyproject.toml version ->", ver)
38+ PY
39+ - run : python -m build
40+ - uses : pypa/gh-action-pypi-publish@release/v1
Original file line number Diff line number Diff line change 11name : release
22on :
3- push :
4- tags :
5- - ' v*' # only version tags
3+ release :
4+ types : [published]
65
76permissions :
87 contents : read
98 packages : write
109
1110jobs :
1211 ghcr :
12+ if : startsWith(github.event.release.tag_name, 'v')
1313 runs-on : ubuntu-latest
1414 steps :
1515 - uses : actions/checkout@v4
16-
17- - name : Set image name (lowercase)
18- shell : bash
19- run : echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
20-
2116 - uses : docker/setup-buildx-action@v3
2217 - uses : docker/login-action@v3
2318 with :
2419 registry : ghcr.io
2520 username : ${{ github.actor }}
2621 password : ${{ secrets.GITHUB_TOKEN }}
27-
28- - uses : docker/build-push-action@v6
29- with :
30- context : .
31- file : ./Dockerfile
32- platforms : linux/amd64
33- push : true
34- provenance : false
35- tags : |
36- ${{ env.IMAGE }}:latest
37- ${{ env.IMAGE }}:${{ github.ref_name }}
22+ - name : Set env
23+ run : |
24+ echo "TAG=${{ github.event.release.tag_name }}" >> "$GITHUB_ENV"
25+ echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
26+ - name : Build & push (amd64+arm64)
27+ run : |
28+ docker buildx build \
29+ --platform linux/amd64,linux/arm64 \
30+ -t "$IMAGE:$TAG" -t "$IMAGE:latest" \
31+ --push .
You can’t perform that action at this time.
0 commit comments