|
1 | 1 | name: publish-on-semrel |
| 2 | + |
2 | 3 | on: |
3 | 4 | workflow_run: |
4 | 5 | workflows: ["semantic-release"] |
5 | 6 | types: [completed] |
6 | 7 | workflow_dispatch: |
7 | 8 | inputs: |
8 | 9 | tag: |
9 | | - description: "Tag a publicar (p.ej. v0.4.35). Vacío = último release" |
| 10 | + description: "Tag a publicar (ej. v0.4.35)" |
10 | 11 | required: false |
11 | | - default: "" |
12 | | -permissions: |
13 | | - contents: read |
14 | | - packages: write |
15 | | - id-token: write |
16 | | -concurrency: |
17 | | - group: publish-${{ github.event_name }}-${{ github.run_id }} |
18 | | - cancel-in-progress: false |
| 12 | + type: string |
| 13 | + |
19 | 14 | jobs: |
20 | 15 | publish: |
21 | | - if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success') }} |
| 16 | + if: > |
| 17 | + (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || |
| 18 | + (github.event_name == 'workflow_dispatch') |
22 | 19 | runs-on: ubuntu-latest |
23 | | - environment: pypi |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + packages: write |
| 23 | + id-token: write |
24 | 24 | steps: |
25 | | - - uses: actions/checkout@v4 |
| 25 | + - name: Checkout (con tags) |
| 26 | + uses: actions/checkout@v4 |
26 | 27 | with: |
27 | 28 | fetch-depth: 0 |
28 | 29 |
|
29 | | - # Obtener tag del último release |
30 | | - - uses: actions/github-script@v7 |
31 | | - id: latest |
32 | | - with: |
33 | | - script: | |
34 | | - const { data } = await github.repos.getLatestRelease({ owner: context.repo.owner, repo: context.repo.repo }); |
35 | | - core.setOutput('tag', data.tag_name); |
36 | | -
|
37 | | - - name: Resolver TAG de publicación |
| 30 | + - name: Resolver TAG |
38 | 31 | id: tag |
39 | 32 | shell: bash |
40 | 33 | run: | |
41 | | - if [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && [[ -n "${{ github.event.inputs.tag }}" ]]; then |
| 34 | + if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" && -n "${{ github.event.inputs.tag }}" ]]; then |
42 | 35 | TAG="${{ github.event.inputs.tag }}" |
43 | 36 | else |
44 | | - TAG="${{ steps.latest.outputs.tag }}" |
| 37 | + git fetch --tags --force |
| 38 | + TAG="$(git tag -l 'v*' --sort=-v:refname | head -n1)" |
45 | 39 | fi |
46 | | - echo "TAG=$TAG" >> "$GITHUB_ENV" |
| 40 | + echo "TAG=$TAG" | tee -a "$GITHUB_ENV" |
47 | 41 | echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
48 | | - echo "Publicando tag: $TAG" |
| 42 | + echo "Publicando TAG=$TAG" |
49 | 43 |
|
50 | | - - name: Sincronizar version de pyproject.toml con TAG |
51 | | - shell: bash |
| 44 | + - name: Setup Python |
| 45 | + uses: actions/setup-python@v5 |
| 46 | + with: |
| 47 | + python-version: '3.12' |
| 48 | + |
| 49 | + - name: Build sdist & wheel |
52 | 50 | run: | |
53 | | - python - <<'PY' |
54 | | - import os, re, pathlib |
55 | | - tag = os.environ["TAG"].lstrip('v') |
56 | | - p = pathlib.Path("pyproject.toml") |
57 | | - t = p.read_text() |
58 | | - t = re.sub(r'(?m)^(\s*version\s*=\s*")\d+\.\d+\.\d+(")', rf"\1{tag}\2", t) |
59 | | - p.write_text(t) |
60 | | - print("Set version ->", tag) |
61 | | - PY |
| 51 | + python -m pip install -U pip build |
| 52 | + python -m build |
62 | 53 |
|
63 | | - # Build & push GHCR |
64 | | - - name: Set IMAGE |
65 | | - run: echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV" |
| 54 | + - name: Publish to PyPI (OIDC) |
| 55 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 56 | + with: |
| 57 | + packages-dir: dist |
| 58 | + skip-existing: true |
66 | 59 |
|
67 | | - - uses: docker/setup-qemu-action@v3 |
68 | | - - uses: docker/setup-buildx-action@v3 |
69 | | - - uses: docker/login-action@v3 |
| 60 | + - name: Login GHCR |
| 61 | + uses: docker/login-action@v3 |
70 | 62 | with: |
71 | 63 | registry: ghcr.io |
72 | 64 | username: ${{ github.actor }} |
73 | 65 | password: ${{ secrets.GITHUB_TOKEN }} |
74 | 66 |
|
75 | | - - name: Build & Push container |
76 | | - uses: docker/build-push-action@v6 |
| 67 | + - name: Setup Buildx |
| 68 | + uses: docker/setup-buildx-action@v3 |
| 69 | + |
| 70 | + - name: Build & Push image |
| 71 | + uses: docker/build-push-action@v5 |
77 | 72 | with: |
78 | 73 | context: . |
79 | | - file: ./Dockerfile |
80 | | - platforms: linux/amd64 |
81 | 74 | push: true |
82 | | - provenance: false |
83 | | - tags: ${{ env.IMAGE }}:${{ steps.tag.outputs.tag }},${{ env.IMAGE }}:latest |
84 | | - |
85 | | - # Build & publish PyPI (OIDC) |
86 | | - - uses: actions/setup-python@v5 |
87 | | - with: |
88 | | - python-version: "3.12" |
89 | | - |
90 | | - - name: Build sdist/wheel |
91 | | - run: | |
92 | | - python -m pip install -U pip build |
93 | | - python -m build |
94 | | -
|
95 | | - - name: Publish to PyPI (Trusted Publisher) |
96 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
97 | | - with: |
98 | | - skip-existing: true |
99 | | - verbose: true |
100 | | - env: |
101 | | - PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring |
| 75 | + tags: ghcr.io/${{ github.repository }}:${{ env.TAG }} |
| 76 | + platforms: linux/amd64 |
0 commit comments