From d97a68e28ec6553c3545fdf7e5322e871559cfdb Mon Sep 17 00:00:00 2001 From: zacchua-stripe Date: Thu, 5 Nov 2026 14:50:49 -0800 Subject: [PATCH] Add Canary CI workflow sharing CI steps through local actions (#1967) Move the static checks, build, and test steps into composite actions used by both CI and a new Canary CI workflow. Canary CI runs on pushes to the canary-ga, canary-beta, and canary-private-preview branches, points stripe-mock at the matching canary specs and fixtures, and has no publish job. CI job names are unchanged, so required status checks still match. Committed-By-Agent: claude Co-authored-by: Claude Opus 5.5 --- .github/actions/build-package/action.yml | 15 ++++ .github/actions/static-checks/action.yml | 29 +++++++ .github/actions/test/action.yml | 100 +++++++++++++++++++++++ .github/workflows/canary.yml | 89 ++++++++++++++++++++ .github/workflows/ci.yml | 49 +---------- 5 files changed, 237 insertions(+), 45 deletions(-) create mode 100644 .github/actions/build-package/action.yml create mode 100644 .github/actions/static-checks/action.yml create mode 100644 .github/actions/test/action.yml create mode 100644 .github/workflows/canary.yml diff --git a/.github/actions/build-package/action.yml b/.github/actions/build-package/action.yml new file mode 100644 index 000000000..24c38c132 --- /dev/null +++ b/.github/actions/build-package/action.yml @@ -0,0 +1,15 @@ +name: Build +description: Build and check the package into dist/. Shared by CI and Canary CI; expects the repository to be checked out. + +runs: + using: composite + steps: + - uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4.0.0 + - name: Set up Python 3 + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: "3.10" + - name: Build and check package + shell: bash + run: | + just build diff --git a/.github/actions/static-checks/action.yml b/.github/actions/static-checks/action.yml new file mode 100644 index 000000000..485e7f0c7 --- /dev/null +++ b/.github/actions/static-checks/action.yml @@ -0,0 +1,29 @@ +name: Static Checks +description: Typecheck examples, lint, check formatting, and typecheck. Shared by CI and Canary CI; expects the repository to be checked out. + +runs: + using: composite + steps: + - uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4.0.0 + - name: Set up Python 3 + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: "3.13" + - name: check examples w/ mypy (against python@3.13) + shell: bash + run: just typecheck-examples + # skip deps on all these since mypy installed everything + - name: check linting + shell: bash + run: just --no-deps lint + - name: check formatting + shell: bash + run: just --no-deps format-check + # pyright depends on node, which it handles and installs for itself as needed + # we _could_ run setup-node to make it available for it if we're having reliability problems + - name: check types + # only check against a modern version- unit tests will catch syntax errors on older versions + # this isn't user facing, this is just checking that our code is internally consistent + # e.g. a bug here wouldn't cause user CI to fail since the issue is internal to our codebase + shell: bash + run: just --no-deps typecheck diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml new file mode 100644 index 000000000..b9e711811 --- /dev/null +++ b/.github/actions/test/action.yml @@ -0,0 +1,100 @@ +name: Test +description: Start stripe-mock, then run the tests. Shared by CI and Canary CI; expects the repository to be checked out. + +inputs: + python-version: + description: Python version to test against. + required: true + canary_channel: + description: >- + Canary channel (ga, beta, or private-preview) whose specs and fixtures + stripe-mock should serve. Empty uses the OPENAPI_VERSION release. + required: false + default: '' + +runs: + using: composite + steps: + - uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4.0.0 + - name: Resolve stripe-mock OpenAPI inputs + id: openapi + shell: bash + env: + CANARY_CHANNEL: ${{ inputs.canary_channel }} + run: | + set -euo pipefail + + if [[ -z "$CANARY_CHANNEL" ]]; then + echo "version=$(< OPENAPI_VERSION)" >> "$GITHUB_OUTPUT" + exit 0 + fi + + case "$CANARY_CHANNEL" in + ga) + spec_name=spec3.sdk.json + fixtures_name=fixtures3.json + beta=false + ;; + beta) + spec_name=spec3.beta.sdk.json + fixtures_name=fixtures3.beta.json + beta=true + ;; + private-preview) + spec_name=spec3.private_preview.sdk.json + fixtures_name=fixtures3.private_preview.json + beta=true + ;; + *) + echo "::error::Unsupported canary channel: $CANARY_CHANNEL" + exit 1 + ;; + esac + + canary_dir="$GITHUB_WORKSPACE/.stripe-mock-canary" + mkdir -p "$canary_dir" + + spec_path="$canary_dir/$spec_name" + fixtures_path="$canary_dir/$fixtures_name" + canary_base="https://raw.githubusercontent.com/stripe/openapi/master/openapi/canary/$CANARY_CHANNEL" + curl_options=( + --retry 3 + --retry-all-errors + --fail + --silent + --show-error + ) + + curl "${curl_options[@]}" "$canary_base/$spec_name" -o "$spec_path" + curl "${curl_options[@]}" "$canary_base/$fixtures_name" -o "$fixtures_path" + + { + echo "spec_path=$spec_path" + echo "fixtures_path=$fixtures_path" + echo "beta=$beta" + } >> "$GITHUB_OUTPUT" + - name: Set up Python ${{ inputs.python-version }} + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: ${{ inputs.python-version }} + - uses: stripe/openapi/actions/stripe-mock@master + with: + openapi_version: ${{ steps.openapi.outputs.version }} + spec_path: ${{ steps.openapi.outputs.spec_path }} + fixtures: ${{ steps.openapi.outputs.fixtures_path }} + beta: ${{ steps.openapi.outputs.beta }} + + # Composite steps must name a shell; keep each OS on the shell CI used before. + - name: "run tests" + if: runner.os != 'Windows' + shell: bash + run: just test + env: + STRIPE_MOCK_HOST: localhost + - name: "run tests" + if: runner.os == 'Windows' + shell: pwsh + run: just test + env: + # Use IP instead of 'localhost' to avoid slow DNS resolution on Windows + STRIPE_MOCK_HOST: 127.0.0.1 diff --git a/.github/workflows/canary.yml b/.github/workflows/canary.yml new file mode 100644 index 000000000..de4d00abb --- /dev/null +++ b/.github/workflows/canary.yml @@ -0,0 +1,89 @@ +name: Canary CI + +# Runs the same checks as CI against code generated from the canary specs. +# sdk-codegen force-pushes these branches; they are never released, so there is +# no publish job. +on: + workflow_dispatch: {} + push: + branches: + - canary-ga + - canary-beta + - canary-private-preview + +permissions: {} + +concurrency: + # Each push replaces the branch, so an older run's result is stale. + group: canary-ci-${{ github.ref_name }} + cancel-in-progress: true + +env: + # Map each canary branch to the channel stripe-mock serves. + CANARY_CHANNEL: >- + ${{ + github.ref_name == 'canary-ga' && 'ga' || + github.ref_name == 'canary-beta' && 'beta' || + github.ref_name == 'canary-private-preview' && 'private-preview' || + 'unsupported' + }} + +jobs: + lint: + name: Static Checks + runs-on: "ubuntu-24.04" + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: ./.github/actions/static-checks + + build: + name: Build + runs-on: "ubuntu-24.04" + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: ./.github/actions/build-package + + test: + name: Test (${{ matrix.python_version }}, ${{ matrix.os }}) + runs-on: ${{ matrix.os }} + permissions: + contents: read + strategy: + fail-fast: false + matrix: + # Keep in sync with the test matrix in ci.yml. + os: + - "ubuntu-24.04" + python_version: + # The last ~5 versions, once we're on schedule + # https://docs.stripe.com/sdks/versioning?lang=python#stripe-sdk-language-version-support-policy + # https://endoflife.date/python + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + - "3.14" + - "pypy-3.9" + - "pypy-3.10" + - "pypy-3.11" + include: + - os: windows-latest + # use any modern-ish version + python_version: "3.14" + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: ./.github/actions/test + with: + python-version: ${{ matrix.python_version }} + canary_channel: ${{ env.CANARY_CHANNEL }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f8a8332dc..ccc0711b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,28 +28,10 @@ jobs: permissions: contents: read steps: - - uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4.0.0 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - name: Set up Python 3 - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 - with: - python-version: "3.13" - - name: check examples w/ mypy (against python@3.13) - run: just typecheck-examples - # skip deps on all these since mypy installed everything - - name: check linting - run: just --no-deps lint - - name: check formatting - run: just --no-deps format-check - # pyright depends on node, which it handles and installs for itself as needed - # we _could_ run setup-node to make it available for it if we're having reliability problems - - name: check types - # only check against a modern version- unit tests will catch syntax errors on older versions - # this isn't user facing, this is just checking that our code is internally consistent - # e.g. a bug here wouldn't cause user CI to fail since the issue is internal to our codebase - run: just --no-deps typecheck + - uses: ./.github/actions/static-checks build: name: Build @@ -57,19 +39,10 @@ jobs: permissions: contents: read steps: - - uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4.0.0 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - - name: Set up Python 3 - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 - with: - python-version: "3.10" - - - name: Build and check package - run: | - just build + - uses: ./.github/actions/build-package - name: "Upload Artifact" uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 @@ -85,6 +58,7 @@ jobs: strategy: fail-fast: false matrix: + # Keep in sync with the test matrix in canary.yml. os: - "ubuntu-24.04" python_version: @@ -105,27 +79,12 @@ jobs: # use any modern-ish version python_version: "3.14" steps: - - uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4.0.0 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - name: Read OpenAPI version - id: openapi - shell: bash - run: echo "version=$(< OPENAPI_VERSION)" >> "$GITHUB_OUTPUT" - - name: Set up Python ${{ matrix.python_version }} - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + - uses: ./.github/actions/test with: python-version: ${{ matrix.python_version }} - - uses: stripe/openapi/actions/stripe-mock@master - with: - openapi_version: ${{ steps.openapi.outputs.version }} - - - name: "run tests" - run: just test - env: - # Use IP instead of 'localhost' to avoid slow DNS resolution on Windows - STRIPE_MOCK_HOST: ${{ runner.os == 'Windows' && '127.0.0.1' || 'localhost' }} publish: name: Publish