Skip to content

publish-pypi

publish-pypi #28

Workflow file for this run

name: publish-pypi
on:
workflow_dispatch:
inputs:
tag:
description: "Release tag (vX.Y.Z). Dejar vacío para detectar último."
required: false
type: string
workflow_run:
workflows: [semantic-release]
types: [completed]
branches: [main]
permissions:
contents: read
id-token: write
packages: write
jobs:
publish:
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success') }}
runs-on: ubuntu-latest
environment: pypi
steps:
- name: Checkout con tags
uses: actions/checkout@v4
with: {fetch-depth: 0}
- name: Resolver TAG
id: tag
shell: bash
run: |
git fetch --tags --force --prune >/dev/null 2>&1
if [[ -n "${{ inputs.tag }}" ]]; then
T="${{ inputs.tag }}"
elif [[ -n "${{ github.event.workflow_run.head_branch }}" ]]; then
T="$(git tag -l 'v*' --sort=-v:refname | head -n1)"
else
T="$(git tag -l 'v*' --sort=-v:refname | head -n1)"
fi
echo "tag=$T" >> "$GITHUB_OUTPUT"
echo "TAG=$T" >> "$GITHUB_ENV"
echo "Using tag: $T"
- name: Sincronizar versión de pyproject con TAG
shell: bash
run: |
want="${TAG#v}"
sed -i -E "s/^version *= *\"[^\"]+\"/version = \"$want\"/" pyproject.toml
echo "pyproject version -> $(grep -E '^version *= *\"' -m1 pyproject.toml)"
- name: Setup Python
uses: actions/setup-python@v5
with: {python-version: '3.x'}
- name: Build sdist & wheel
run: |
python -m pip install -U pip build
python -m build
- name: Publish to PyPI (OIDC)
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
- name: Login GHCR
run: echo "${{ github.token }}" | docker login ghcr.io -u $ --password-stdin
- name: Build & Push image (amd64,arm64)
shell: bash
run: |
repo_lower="$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')"
docker buildx create --use --name drd-builder || true
docker buildx build --platform linux/amd64,linux/arm64 \
-t "ghcr.io/${repo_lower}:${TAG}" \
--push .