Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 38 additions & 28 deletions .github/workflows/regen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,48 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Discover latest archive version
id: latest
- uses: bufbuild/buf-action@v1
with:
setup_only: true

- name: Resolve schema commit
id: schema
run: |
current=$(grep -E 'readonly BUF_PY_VERSION="' scripts/regen.sh \
| sed -E 's/.*="([^"]+)".*/\1/')
echo "current=$current" >> "$GITHUB_OUTPUT"
# Buf does not expose a public version-list endpoint; we resolve
# `main` to a pinned ref by introspecting the redirect target.
latest=$(curl -sI \
"https://buf.build/gen/archive/openstatus/api/protocolbuffers/python/main.zip" \
| grep -i '^location:' | sed -E 's/.*\/([^/]+)\.zip.*/\1/' | tr -d '\r')
echo "latest=$latest" >> "$GITHUB_OUTPUT"

- name: No-op when already up to date
if: steps.latest.outputs.latest == steps.latest.outputs.current
run: echo "Already on ${{ steps.latest.outputs.current }}; nothing to do."

- name: Bump pin and regenerate
if: steps.latest.outputs.latest != steps.latest.outputs.current
json=$(buf registry module commit resolve \
buf.build/openstatus/api:main --format json)
commit=$(jq -r '.commit' <<< "$json")
source_url=$(jq -r '.source_control_url' <<< "$json")
if [[ -z "$commit" || "$commit" == "null" ]]; then
echo "::error::schema commit resolution returned empty"
exit 1
fi
echo "commit=$commit" >> "$GITHUB_OUTPUT"
echo "source_url=$source_url" >> "$GITHUB_OUTPUT"

- name: Regenerate
run: bash scripts/regen.sh "${{ steps.schema.outputs.commit }}"

- name: Bump patch version
run: |
sed -i -E "s/(readonly BUF_PY_VERSION=)\"[^\"]+\"/\1\"${{ steps.latest.outputs.latest }}\"/" \
scripts/regen.sh
bash scripts/regen.sh
if git diff --quiet -- src/openstatus/_gen; then
echo "no schema change; skipping version bump"
exit 0
fi
cur=$(grep -oP '^version = "\K[^"]+' pyproject.toml)
IFS=. read -r maj min pat <<< "$cur"
next="$maj.$min.$((pat + 1))"
sed -i -E "0,/^version = \"[^\"]+\"/s//version = \"$next\"/" pyproject.toml
echo "bumped $cur -> $next"

- name: Open PR
if: steps.latest.outputs.latest != steps.latest.outputs.current
uses: peter-evans/create-pull-request@v6
with:
branch: regen/${{ steps.latest.outputs.latest }}
commit-message: "chore: bump buf schema to ${{ steps.latest.outputs.latest }}"
title: "chore: bump buf schema to ${{ steps.latest.outputs.latest }}"
token: ${{ secrets.SDK_BOT_TOKEN || github.token }}
branch: regen/${{ steps.schema.outputs.commit }}
commit-message: "chore: bump buf schema to ${{ steps.schema.outputs.commit }}"
title: "chore: bump buf schema to ${{ steps.schema.outputs.commit }}"
body: |
Automated bump of the pinned `protocolbuffers/python` archive
version from `${{ steps.latest.outputs.current }}` to
`${{ steps.latest.outputs.latest }}`.
Automated regeneration from `buf.build/openstatus/api` schema
commit `${{ steps.schema.outputs.commit }}`.

Source: ${{ steps.schema.outputs.source_url }}
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ permissions:

jobs:
publish:
if: github.repository == 'openstatusHQ/sdk-python'
name: build and publish to PyPI
runs-on: ubuntu-latest
environment:
Expand Down
25 changes: 13 additions & 12 deletions scripts/regen.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

# Pinned Buf-generated archives for buf.build/openstatus/api.
# To upgrade: change this line, run `bash scripts/regen.sh`, commit the result.
readonly BUF_PY_VERSION="v35.0-7d7b7047611f.1"
# Recorded in $DEST/VERSION only — the archive itself is fetched by the `main`
# label, since the archive URL uses a plugin-version coordinate that cannot be
# reconstructed from the commit alone.
SCHEMA_COMMIT="${1:?usage: regen.sh <schema-commit>}"

# Transitive deps. Buf does not expose pinned versions for these from the
# openstatus/api module, so we track main. The PHP plan ships empty initOnce()
Expand Down Expand Up @@ -31,12 +32,12 @@ fetch() {
unzip -q "${TMP}/${name}-${plugin}.zip" -d "${TMP}/${name}-${plugin}"
}

fetch "openstatus/api" python "${BUF_PY_VERSION}" openstatus
fetch "openstatus/api" pyi "${BUF_PY_VERSION}" openstatus
fetch "${BUF_VALIDATE_REF}" python main bufvalidate
fetch "${BUF_VALIDATE_REF}" pyi main bufvalidate
fetch "${GNOSTIC_REF}" python main gnostic
fetch "${GNOSTIC_REF}" pyi main gnostic
fetch "openstatus/api" python main openstatus
fetch "openstatus/api" pyi main openstatus
fetch "${BUF_VALIDATE_REF}" python main bufvalidate
fetch "${BUF_VALIDATE_REF}" pyi main bufvalidate
fetch "${GNOSTIC_REF}" python main gnostic
fetch "${GNOSTIC_REF}" pyi main gnostic

# Merge a top-level package from a buf archive into $DEST.
# - archive layout: <archive>/<plugin-prefix>_<lang>/<pkg-root>/...
Expand Down Expand Up @@ -67,7 +68,7 @@ merge gnostic-pyi gnostic
# `openstatus` package is not polluted and so the buf/gnostic vendored copies
# do not collide with any user-installed packages of the same name.
find "$DEST" -type f \( -name '*.py' -o -name '*.pyi' \) -print0 \
| xargs -0 sed -i '' \
| xargs -0 sed -i \
-e 's|^from openstatus\.|from openstatus._gen.openstatus.|g' \
-e 's|^from buf\.|from openstatus._gen.buf.|g' \
-e 's|^from gnostic\.|from openstatus._gen.gnostic.|g' \
Expand All @@ -78,8 +79,8 @@ find "$DEST" -type f \( -name '*.py' -o -name '*.pyi' \) -print0 \
# Generated trees ship no __init__.py — create empty shims so packages import.
find "$DEST" -type d -exec sh -c 'touch "$0/__init__.py"' {} \;

echo "${BUF_PY_VERSION}" > "$DEST/VERSION"
echo "${SCHEMA_COMMIT}" > "$DEST/VERSION"

echo
echo "Done. Generated tree at $DEST"
echo "Pinned openstatus version recorded at $DEST/VERSION"
echo "Schema commit recorded at $DEST/VERSION"
Loading