Skip to content

Regenerate Python Library #162

Regenerate Python Library

Regenerate Python Library #162

name: Regenerate Python Library
on:
workflow_dispatch:
inputs:
library_version:
description: 'The version of the new library'
required: true
api_version:
description: 'The corresponding version of the API'
required: true
release_stage:
description: 'Release stage'
required: true
type: choice
options:
- ga
- beta
- dev
# Writes (commit, PR, auto-merge) are performed with a GitHub App token, not
# GITHUB_TOKEN, so the default token only needs read access for checkout.
permissions:
contents: read
jobs:
regenerate:
runs-on: ubuntu-latest
steps:
- name: Resolve branches
id: branches
run: |
case "${{ github.event.inputs.release_stage }}" in
dev)
echo "checkout_branch=httpx" >> "$GITHUB_OUTPUT"
echo "release_branch=httpx-release" >> "$GITHUB_OUTPUT"
echo "pr_base=httpx" >> "$GITHUB_OUTPUT"
;;
beta)
echo "checkout_branch=beta" >> "$GITHUB_OUTPUT"
echo "release_branch=beta-release" >> "$GITHUB_OUTPUT"
echo "pr_base=beta" >> "$GITHUB_OUTPUT"
;;
ga)
echo "checkout_branch=main" >> "$GITHUB_OUTPUT"
echo "release_branch=release" >> "$GITHUB_OUTPUT"
echo "pr_base=main" >> "$GITHUB_OUTPUT"
;;
esac
# Generate the App token before checkout so checkout persists *it* (not the
# read-only GITHUB_TOKEN) as the git credential used for the later push.
- name: Generate app token
id: app-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.RELEASE_APP_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
- uses: actions/checkout@v6
with:
ref: ${{ steps.branches.outputs.checkout_branch }}
# Persist the App token (write access) so EndBug/add-and-commit can push.
# add-and-commit does NOT set up push auth from its github_token input —
# it relies on whatever credential checkout wrote to git config.
token: ${{ steps.app-token.outputs.token }}
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Set up Python
run: uv python install 3.13
- name: Install dependencies
run: uv sync --group generator
# Preserve the checked-out non-generated sources, then wipe meraki/ so the
# generator only regenerates the API modules. The generator reads the
# preserved copy from disk (MERAKI_SOURCE_DIR) instead of fetching them
# from raw.githubusercontent, which rate-limits (429s) the shared runner IP.
- name: Stash non-generated sources
run: |
cp -r meraki "$RUNNER_TEMP/meraki-src"
rm -rf meraki
- name: Regenerate Python Library
env:
LIBRARY_VERSION: ${{ github.event.inputs.library_version }}
API_VERSION: ${{ github.event.inputs.api_version }}
MERAKI_SOURCE_DIR: ${{ runner.temp }}/meraki-src
MERAKI_DASHBOARD_API_KEY: ${{ (github.event.inputs.release_stage == 'beta' || github.event.inputs.release_stage == 'dev') && secrets.TEST_ORG_API_KEY || '' }}
BETA_ORG_ID: ${{ (github.event.inputs.release_stage == 'beta' || github.event.inputs.release_stage == 'dev') && secrets.TEST_ORG_BETA_00_ID || '' }}
run: |
ARGS="-g true -l -v $LIBRARY_VERSION -a $API_VERSION"
if [ -n "$BETA_ORG_ID" ]; then
ARGS="$ARGS -o $BETA_ORG_ID"
fi
uv run python generator/generate_library.py $ARGS
- name: Set new version
env:
LIBRARY_VERSION: ${{ github.event.inputs.library_version }}
run: |
sed -i "s/^version = \".*\"/version = \"$LIBRARY_VERSION\"/" pyproject.toml
uv lock
# Render changelog.d/ fragments into CHANGELOG.md here so the update rides
# the regeneration PR (and its required checks) instead of being pushed
# straight to a protected branch later. towncrier is in the dev group, so
# `uv sync --group generator` (default-groups = dev) already installed it.
- name: Build changelog
env:
LIBRARY_VERSION: ${{ github.event.inputs.library_version }}
run: |
if ls changelog.d/*.md >/dev/null 2>&1; then
uv run towncrier build --yes --version "$LIBRARY_VERSION"
else
echo "No changelog fragments; skipping towncrier build."
fi
- name: Commit changes to new branch
uses: EndBug/add-and-commit@v10
with:
author_name: GitHub Action
author_email: support@meraki.com
message: Auto-generated library v${{ github.event.inputs.library_version }} for API v${{ github.event.inputs.api_version }}.
new_branch: ${{ steps.branches.outputs.release_branch }}
- name: Create pull request
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
gh pr create \
--base "${{ steps.branches.outputs.pr_base }}" \
--head "${{ steps.branches.outputs.release_branch }}" \
--title "Release v${{ github.event.inputs.library_version }} (API v${{ github.event.inputs.api_version }})" \
--body "Auto-generated library v${{ github.event.inputs.library_version }} for API v${{ github.event.inputs.api_version }}."
- name: Enable auto-merge
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
gh pr merge "${{ steps.branches.outputs.release_branch }}" \
--auto --squash