aca01aeb63
Closes the Phase-0 follow-up (#5 merged the code but the release never ran). Version-as-declared: the PR bumps pyproject, a green merge cuts the tag (tag-ref write, no CI pushes to main), the tag triggers the publish with Infisical-sourced publisher creds (/ci/gitea-pypi-publisher, org-level CI machine identity) + idempotent upload + install-from-registry smoke. Bump 0.1.0 -> 0.2.0 so the first merge exercises the whole chain. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
94 lines
3.5 KiB
YAML
94 lines
3.5 KiB
YAML
name: auto-release
|
|
|
|
# Publish-on-merge (the Phase-0 follow-up: #5 merged the code but the release
|
|
# never ran, so pip found zero versions). Mirrors the runtime's tag-only
|
|
# auto-release, with one simplification: this repo uses VERSION-AS-DECLARED —
|
|
# pyproject.toml's [project].version is bumped IN the PR, and a green merge
|
|
# cuts the tag `v<that version>` if it does not exist yet. No commit is ever
|
|
# pushed to main by CI (tag-ref writes bypass branch push protection), and an
|
|
# already-tagged version makes this a loud no-op, so re-runs and non-bump
|
|
# merges are safe by construction.
|
|
#
|
|
# Gitea has no `workflow_run` trigger, so the merge-blocking unit-test gate is
|
|
# re-run inline here and the tag is cut only on green (same rationale as the
|
|
# runtime's auto-release).
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: auto-release
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
gate:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
|
|
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
|
with:
|
|
python-version: "3.11"
|
|
cache: pip
|
|
|
|
- name: Install package + test deps
|
|
env:
|
|
PIP_INDEX_URL: https://git.moleculesai.app/api/packages/molecule-ai/pypi/simple/
|
|
PIP_EXTRA_INDEX_URL: https://pypi.org/simple/
|
|
run: pip install -e ".[qr]" pytest
|
|
|
|
- name: Re-run the merge-blocking gate (unit tests)
|
|
run: pytest -q
|
|
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
needs: gate
|
|
steps:
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
|
|
- name: Cut tag v<pyproject version> if untagged
|
|
env:
|
|
RELEASE_BOT_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }}
|
|
GITEA_URL: https://git.moleculesai.app
|
|
REPO: molecule-ai/lark-channel-molecule
|
|
run: |
|
|
set -eu
|
|
if [ -z "${RELEASE_BOT_TOKEN:-}" ]; then
|
|
echo "::error::RELEASE_BOT_TOKEN org secret is not available -- cannot cut the release tag"
|
|
exit 1
|
|
fi
|
|
VERSION=$(python3 - <<'PY'
|
|
import tomllib
|
|
with open("pyproject.toml", "rb") as f:
|
|
print(tomllib.load(f)["project"]["version"])
|
|
PY
|
|
)
|
|
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+([a-z0-9.+-]+)?$'; then
|
|
echo "::error::pyproject version $VERSION does not look like a PEP 440 release"
|
|
exit 1
|
|
fi
|
|
TAG="v$VERSION"
|
|
STATUS=$(curl -sS -o /dev/null -w "%{http_code}" \
|
|
-H "Authorization: token $RELEASE_BOT_TOKEN" -H "User-Agent: curl/8.4.0" \
|
|
"$GITEA_URL/api/v1/repos/$REPO/tags/$TAG")
|
|
if [ "$STATUS" = "200" ]; then
|
|
echo "::notice::$TAG already exists -- version not bumped in this merge; nothing to release"
|
|
exit 0
|
|
fi
|
|
BODY=$(printf '{"tag_name":"%s","target":"%s","message":"auto-release %s (green merge to main)"}' \
|
|
"$TAG" "$GITHUB_SHA" "$TAG")
|
|
CODE=$(curl -sS -o /tmp/tag-out.json -w "%{http_code}" -X POST \
|
|
-H "Authorization: token $RELEASE_BOT_TOKEN" -H "User-Agent: curl/8.4.0" \
|
|
-H "Content-Type: application/json" \
|
|
"$GITEA_URL/api/v1/repos/$REPO/tags" -d "$BODY")
|
|
if [ "$CODE" != "201" ]; then
|
|
echo "::error::tag creation failed (HTTP $CODE): $(cat /tmp/tag-out.json)"
|
|
exit 1
|
|
fi
|
|
echo "::notice::cut $TAG at $GITHUB_SHA -- publish.yml takes it from here"
|