Skip to content

Commit 4b3bf72

Browse files
ci(release): trigger GHCR & PyPI on GitHub Release; sync version from tag (#74)
1 parent 608f672 commit 4b3bf72

File tree

2 files changed

+41
-29
lines changed

2 files changed

+41
-29
lines changed

.github/workflows/publish-pypi.yml

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
name: publish-pypi
22
on:
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+
66
permissions:
7-
id-token: write
87
contents: read
8+
id-token: write
9+
10+
env:
11+
PIP_DISABLE_PIP_VERSION_CHECK: "1"
12+
913
jobs:
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

.github/workflows/release.yml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
11
name: release
22
on:
3-
push:
4-
tags:
5-
- 'v*' # only version tags
3+
release:
4+
types: [published]
65

76
permissions:
87
contents: read
98
packages: write
109

1110
jobs:
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 .

0 commit comments

Comments
 (0)