Skip to content

Commit e6b5f9d

Browse files
build(pypi): set version=0.4.35 (match tag) (#81)
* ci(publish): sync version from tag; GHCR on semrel, PyPI via OIDC (trusted workflow) * build(pypi): set version=0.4.35 (match tag)
1 parent e9d14ea commit e6b5f9d

File tree

3 files changed

+71
-78
lines changed

3 files changed

+71
-78
lines changed

.github/workflows/publish-on-semrel.yml

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,55 @@ on:
77
workflow_dispatch:
88
inputs:
99
tag:
10-
description: "Tag a publicar (ej. v0.4.35)"
10+
description: Tag to publish (e.g. v0.4.36)
1111
required: false
1212
type: string
1313

14+
permissions:
15+
contents: read
16+
packages: write
17+
1418
jobs:
1519
publish:
16-
if: >
17-
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') ||
18-
(github.event_name == 'workflow_dispatch')
20+
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success') }}
1921
runs-on: ubuntu-latest
20-
permissions:
21-
contents: read
22-
packages: write
23-
id-token: write
2422
steps:
25-
- name: Checkout (con tags)
23+
- name: Checkout with tags
2624
uses: actions/checkout@v4
2725
with:
2826
fetch-depth: 0
27+
fetch-tags: true
2928

30-
- name: Resolver TAG
29+
- name: Resolve TAG
3130
id: tag
3231
shell: bash
3332
run: |
34-
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" && -n "${{ github.event.inputs.tag }}" ]]; then
35-
TAG="${{ github.event.inputs.tag }}"
33+
if [[ -n "${{ github.event.inputs.tag }}" ]]; then
34+
echo "TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
3635
else
3736
git fetch --tags --force
38-
TAG="$(git tag -l 'v*' --sort=-v:refname | head -n1)"
37+
TAG=$(git describe --tags --abbrev=0)
38+
echo "TAG=$TAG" >> $GITHUB_ENV
3939
fi
40-
echo "TAG=$TAG" | tee -a "$GITHUB_ENV"
41-
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
42-
echo "Publicando TAG=$TAG"
43-
44-
- name: Setup Python
45-
uses: actions/setup-python@v5
46-
with:
47-
python-version: '3.12'
40+
echo "Resolved TAG=$TAG"
4841
49-
- name: Build sdist & wheel
42+
- name: Sync version from TAG into pyproject.toml
43+
shell: bash
44+
env:
45+
TAG: ${{ env.TAG }}
5046
run: |
51-
python -m pip install -U pip build
52-
python -m build
47+
VER="${TAG#v}"
48+
python - <<'PY'
49+
import os,re,pathlib
50+
ver=os.environ["VER"]
51+
p=pathlib.Path("pyproject.toml")
52+
t=p.read_text()
53+
t=re.sub(r'(?m)^(\s*version\s*=\s*")\d+\.\d+\.\d+(")', rf'\1{ver}\2', t)
54+
p.write_text(t)
55+
print("synced version:", ver)
56+
PY
5357

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
59-
60-
- name: Login GHCR
58+
- name: Login to GHCR
6159
uses: docker/login-action@v3
6260
with:
6361
registry: ghcr.io
@@ -67,10 +65,15 @@ jobs:
6765
- name: Setup Buildx
6866
uses: docker/setup-buildx-action@v3
6967

68+
- name: Compute lowercase image name
69+
shell: bash
70+
run: |
71+
OWNER="${GITHUB_REPOSITORY_OWNER,,}"
72+
echo "IMAGE=ghcr.io/${OWNER}/diff-risk-dashboard" >> $GITHUB_ENV
73+
7074
- name: Build & Push image
71-
uses: docker/build-push-action@v5
75+
uses: docker/build-push-action@v6
7276
with:
7377
context: .
7478
push: true
75-
tags: ghcr.io/${{ github.repository }}:${{ env.TAG }}
76-
platforms: linux/amd64
79+
tags: ${{ env.IMAGE }}:${{ env.TAG }}

.github/workflows/publish-pypi.yml

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,65 @@ name: publish-pypi
22

33
on:
44
workflow_run:
5-
workflows: ["semantic-release"]
5+
workflows: ["publish-on-semrel"]
66
types: [completed]
77
workflow_dispatch:
88
inputs:
99
tag:
10-
description: "Tag to publish (e.g. v0.4.35)"
10+
description: Tag to publish (e.g. v0.4.36)
1111
required: false
1212
type: string
1313

14+
permissions:
15+
contents: read
16+
id-token: write
17+
packages: write
18+
1419
jobs:
1520
publish:
16-
if: >
17-
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') ||
18-
(github.event_name == 'workflow_dispatch')
19-
runs-on: ubuntu-latest
21+
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success') }}
2022
environment: pypi
21-
permissions:
22-
contents: read
23-
packages: write
24-
id-token: write
23+
runs-on: ubuntu-latest
2524
steps:
2625
- name: Checkout with tags
2726
uses: actions/checkout@v4
2827
with:
2928
fetch-depth: 0
29+
fetch-tags: true
3030

3131
- name: Resolve TAG
3232
id: tag
3333
shell: bash
3434
run: |
35-
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" && -n "${{ github.event.inputs.tag }}" ]]; then
36-
TAG="${{ github.event.inputs.tag }}"
35+
if [[ -n "${{ github.event.inputs.tag }}" ]]; then
36+
echo "TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
3737
else
3838
git fetch --tags --force
39-
TAG="$(git tag -l 'v*' --sort=-v:refname | head -n1)"
39+
TAG=$(git describe --tags --abbrev=0)
40+
echo "TAG=$TAG" >> $GITHUB_ENV
4041
fi
41-
echo "TAG=$TAG" | tee -a "$GITHUB_ENV"
42-
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
42+
echo "Resolved TAG=$TAG"
43+
44+
- name: Sync version from TAG into pyproject.toml
45+
shell: bash
46+
env:
47+
TAG: ${{ env.TAG }}
48+
run: |
49+
VER="${TAG#v}"
50+
python - <<'PY'
51+
import os,re,pathlib
52+
ver=os.environ["VER"]
53+
p=pathlib.Path("pyproject.toml")
54+
t=p.read_text()
55+
t=re.sub(r'(?m)^(\s*version\s*=\s*")\d+\.\d+\.\d+(")', rf'\1{ver}\2', t)
56+
p.write_text(t)
57+
print("synced version:", ver)
58+
PY
4359

4460
- name: Setup Python
4561
uses: actions/setup-python@v5
4662
with:
47-
python-version: '3.12'
63+
python-version: '3.x'
4864

4965
- name: Build sdist & wheel
5066
run: |
@@ -55,30 +71,4 @@ jobs:
5571
uses: pypa/gh-action-pypi-publish@release/v1
5672
with:
5773
packages-dir: dist
58-
skip-existing: true
59-
60-
- name: Login to GHCR
61-
uses: docker/login-action@v3
62-
with:
63-
registry: ghcr.io
64-
username: ${{ github.actor }}
65-
password: ${{ secrets.GITHUB_TOKEN }}
66-
67-
- name: Setup Buildx
68-
uses: docker/setup-buildx-action@v3
69-
70-
- name: Compute lowercase image tag
71-
id: img
72-
shell: bash
73-
run: |
74-
OWNER_LC="${GITHUB_REPOSITORY_OWNER,,}"
75-
REPO_LC="$(basename "$GITHUB_REPOSITORY" | tr '[:upper:]' '[:lower:]')"
76-
echo "IMAGE_TAG=ghcr.io/${OWNER_LC}/${REPO_LC}:${TAG}" | tee -a "$GITHUB_ENV"
77-
78-
- name: Build & Push image
79-
uses: docker/build-push-action@v5
80-
with:
81-
context: .
82-
push: true
83-
tags: ${{ env.IMAGE_TAG }}
84-
platforms: linux/amd64
74+
verbose: true

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "diff-risk-dashboard"
3-
version = "0.4.33"
3+
version = "0.4.35"
44
description = "Visual risk exposure of PRs powered by ai-patch-verifier outputs."
55
authors = ["CoderDeltaLAN <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)