From 826fa07c2a1ec7817a5ca9aeb86fdf7da3ca0d32 Mon Sep 17 00:00:00 2001
From: Wei Chu <6074946+weiwchu@users.noreply.github.com>
Date: Sat, 21 Nov 2026 15:32:33 -0800
Subject: [PATCH 1/2] ci: publish to PyPI with trusted publishing, on a v* tag
or by hand for an existing tag
---
.github/workflows/publish.yml | 57 +++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 .github/workflows/publish.yml
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
new file mode 100644
index 0000000..22ec8c3
--- /dev/null
+++ b/.github/workflows/publish.yml
@@ -0,0 +1,57 @@
+# Publish fa-bench to PyPI with trusted publishing, so no token is stored anywhere.
+#
+# Runs when a v* tag reaches GitHub, or by hand (Actions > publish > Run workflow) for a
+# tag that already exists, such as v2.1.0, which was tagged before this workflow did.
+# PyPI side: a (pending) publisher for olewave/fa-bench, workflow publish.yml, environment pypi.
+name: publish
+
+on:
+ push:
+ tags: ["v*"]
+ workflow_dispatch:
+ inputs:
+ tag:
+ description: "Tag to publish, for example v2.1.0"
+ required: true
+
+permissions:
+ contents: read
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ env:
+ TAG: ${{ inputs.tag || github.ref_name }}
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ ref: refs/tags/${{ env.TAG }}
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.12"
+ - name: The tag matches the package version
+ run: |
+ v=$(python -c "import re,pathlib; print(re.search(r'__version__ = \"(.+?)\"', pathlib.Path('fabench/__init__.py').read_text())[1])")
+ test "v$v" = "$TAG" || { echo "tag $TAG but fabench.__version__ is $v"; exit 1; }
+ - name: Build
+ run: |
+ python -m pip install --upgrade build twine
+ python -m build
+ python -m twine check --strict dist/*
+ - uses: actions/upload-artifact@v4
+ with:
+ name: dist
+ path: dist/
+
+ pypi:
+ needs: build
+ runs-on: ubuntu-latest
+ environment: pypi
+ permissions:
+ id-token: write
+ steps:
+ - uses: actions/download-artifact@v4
+ with:
+ name: dist
+ path: dist/
+ - uses: pypa/gh-action-pypi-publish@release/v1
From f43f06c69c6489cddc3ea8917248114cc08c91de Mon Sep 17 00:00:00 2001
From: Wei Chu <6074946+weiwchu@users.noreply.github.com>
Date: Sat, 21 Nov 2026 15:35:16 -0800
Subject: [PATCH 2/2] ci: pin the README's relative links to the tag on PyPI
---
.github/workflows/publish.yml | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 22ec8c3..c9d0e64 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -33,6 +33,26 @@ jobs:
run: |
v=$(python -c "import re,pathlib; print(re.search(r'__version__ = \"(.+?)\"', pathlib.Path('fabench/__init__.py').read_text())[1])")
test "v$v" = "$TAG" || { echo "tag $TAG but fabench.__version__ is $v"; exit 1; }
+ # PyPI shows README.md with no repository to resolve relative paths against, and a
+ # release's description can't change after upload: pin every relative link to the tag.
+ - name: Point the README's relative links at GitHub, pinned to the tag
+ run: |
+ python - <<'EOF'
+ import os, re
+ from pathlib import Path
+ tag, repo = os.environ["TAG"], "olewave/fa-bench"
+ def fix(u, image):
+ if re.match(r"[a-z][a-z0-9+.-]*:|#|/", u):
+ return u
+ u = u.removeprefix("./")
+ return f"https://raw.githubusercontent.com/{repo}/{tag}/{u}" if image else f"https://github.com/{repo}/blob/{tag}/{u}"
+ p = Path("README.md")
+ t = p.read_text().replace("tycho.olewave.com", "dashboard.olewave.com")
+ t = re.sub(r'(
]*\bsrc=")([^"]+)"', lambda m: m[1] + fix(m[2], True) + '"', t)
+ t = re.sub(r'(]*\bhref=")([^"]+)"', lambda m: m[1] + fix(m[2], False) + '"', t)
+ t = re.sub(r'(!?)\[([^\]]*)\]\(([^)\s]+)\)', lambda m: f"{m[1]}[{m[2]}]({fix(m[3], m[1] == '!')})", t)
+ p.write_text(t)
+ EOF
- name: Build
run: |
python -m pip install --upgrade build twine