Skip to content

Commit 51fa970

Browse files
ci(release): enable dispatch + post-semrel publish (PyPI OIDC + GHCR) (#83)
1 parent 68d1afa commit 51fa970

File tree

1 file changed

+31
-43
lines changed

1 file changed

+31
-43
lines changed

.github/workflows/publish-pypi.yml

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,76 @@
11
name: publish-pypi
2-
32
on:
43
workflow_dispatch:
54
inputs:
65
tag:
7-
description: "Tag a publicar (por defecto: último v*)"
6+
description: "Release tag (vX.Y.Z). Dejar vacío para detectar último."
87
required: false
8+
type: string
99
workflow_run:
10-
workflows: ["semantic-release"]
10+
workflows: [semantic-release]
1111
types: [completed]
12+
branches: [main]
1213

1314
permissions:
14-
id-token: write
1515
contents: read
16+
id-token: write
1617
packages: write
17-
attestations: write
1818

1919
jobs:
2020
publish:
21-
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
22-
environment: pypi
21+
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success') }}
2322
runs-on: ubuntu-latest
23+
environment: pypi
2424
steps:
2525
- name: Checkout con tags
2626
uses: actions/checkout@v4
27-
with: { fetch-depth: 0 }
27+
with: {fetch-depth: 0}
2828

2929
- name: Resolver TAG
3030
id: tag
3131
shell: bash
3232
run: |
33-
if [[ -n "${{ github.event.inputs.tag }}" ]]; then
34-
TAG="${{ github.event.inputs.tag }}"
35-
elif [[ "${GITHUB_REF}" == refs/tags/* ]]; then
36-
TAG="${GITHUB_REF#refs/tags/}"
33+
git fetch --tags --force --prune >/dev/null 2>&1
34+
if [[ -n "${{ inputs.tag }}" ]]; then
35+
T="${{ inputs.tag }}"
36+
elif [[ -n "${{ github.event.workflow_run.head_branch }}" ]]; then
37+
T="$(git tag -l 'v*' --sort=-v:refname | head -n1)"
3738
else
38-
TAG="$(git tag -l 'v*' --sort=-v:refname | head -n1)"
39+
T="$(git tag -l 'v*' --sort=-v:refname | head -n1)"
3940
fi
40-
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
41-
echo "TAG=${TAG}"
41+
echo "tag=$T" >> "$GITHUB_OUTPUT"
42+
echo "TAG=$T" >> "$GITHUB_ENV"
43+
echo "Using tag: $T"
44+
45+
- name: Sincronizar versión de pyproject con TAG
46+
shell: bash
47+
run: |
48+
want="${TAG#v}"
49+
sed -i -E "s/^version *= *\"[^\"]+\"/version = \"$want\"/" pyproject.toml
50+
echo "pyproject version -> $(grep -E '^version *= *\"' -m1 pyproject.toml)"
4251
4352
- name: Setup Python
4453
uses: actions/setup-python@v5
45-
with: { python-version: '3.x' }
54+
with: {python-version: '3.x'}
4655

4756
- name: Build sdist & wheel
4857
run: |
4958
python -m pip install -U pip build
5059
python -m build
5160
52-
- name: Verificar version == tag
53-
shell: bash
54-
run: |
55-
WANT="${{ steps.tag.outputs.tag#v }}"
56-
ACTUAL=$(python - <<'PY'
57-
import re, pathlib
58-
t=pathlib.Path("pyproject.toml").read_text()
59-
print(re.search(r'(?m)^\s*version\s*=\s*"([0-9.]+)"', t).group(1))
60-
PY
61-
)
62-
echo "want=$WANT actual=$ACTUAL"
63-
test "$WANT" = "$ACTUAL"
64-
65-
- name: Publicar en PyPI (OIDC)
61+
- name: Publish to PyPI (OIDC)
6662
uses: pypa/gh-action-pypi-publish@release/v1
6763
with:
6864
skip-existing: true
6965

7066
- name: Login GHCR
71-
uses: docker/login-action@v3
72-
with:
73-
registry: ghcr.io
74-
username: ${{ github.actor }}
75-
password: ${{ secrets.GITHUB_TOKEN }}
76-
77-
- name: Setup Buildx
78-
uses: docker/setup-buildx-action@v3
67+
run: echo "${{ github.token }}" | docker login ghcr.io -u $ --password-stdin
7968

80-
- name: Build & Push image
69+
- name: Build & Push image (amd64,arm64)
8170
shell: bash
8271
run: |
83-
REPO="${GITHUB_REPOSITORY,,}"
84-
TAG="${{ steps.tag.outputs.tag }}"
72+
repo_lower="$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')"
73+
docker buildx create --use --name drd-builder || true
8574
docker buildx build --platform linux/amd64,linux/arm64 \
86-
-t ghcr.io/$REPO:$TAG \
87-
-t ghcr.io/$REPO:latest \
75+
-t "ghcr.io/${repo_lower}:${TAG}" \
8876
--push .

0 commit comments

Comments
 (0)