-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add OpenAPI-generated API client #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| name: Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout Code | ||
| uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 | ||
|
|
||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2 | ||
| with: | ||
| php-version: "8.3" | ||
|
|
||
| - name: Install dependencies | ||
| run: composer install --prefer-dist --no-progress | ||
|
|
||
| - name: Run tests | ||
| run: composer test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| name: SDK Generation | ||
|
|
||
| # Generator: OpenAPI Generator (php) via scripts/generate.sh. | ||
| # | ||
| # Keeps the same workflow filename and dispatch inputs as the other SDK repos | ||
| # (convoy.js, convoy-python, convoy-java, convoy-go, convoy.rb) so the | ||
| # frain-dev/convoy dispatcher (speakeasy-sdk.yml) works unchanged. | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| force: | ||
| # Accepted for dispatcher compatibility. Generation is deterministic | ||
| # from the spec, so there is nothing to force: no diff means no PR. | ||
| description: Accepted for compatibility; regeneration is always run | ||
| required: false | ||
| default: "false" | ||
| type: string | ||
| feature_branch: | ||
| description: Branch for SDK changes | ||
| required: false | ||
| type: string | ||
| schedule: | ||
| - cron: "0 6 * * 1" | ||
|
|
||
| # Serialize generations: overlapping cron/dispatch runs race on the same | ||
| # branch/PR. Queue instead of cancel so a triggered regen is never dropped. | ||
| concurrency: | ||
| group: sdk-generation | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| generate: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout Code | ||
| uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 | ||
| with: | ||
| # Regen branches are always derived from main: the spec is pulled | ||
| # from convoy main, so a dispatch from another ref must not silently | ||
| # commit generated output onto that ref's base. | ||
| ref: main | ||
| # Prefer a PAT: PRs opened with GITHUB_TOKEN do not trigger | ||
| # pull_request workflows, so verify CI would never run on them. | ||
| token: ${{ secrets.SDK_BOT_PAT || secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Setup Java | ||
| uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4.8.0 | ||
| with: | ||
| distribution: temurin | ||
| java-version: "17" | ||
|
|
||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2 | ||
| with: | ||
| php-version: "8.3" | ||
|
|
||
| - name: Regenerate client | ||
| run: ./scripts/generate.sh | ||
|
|
||
| - name: Test regenerated client | ||
| # Never open a PR for a client that breaks the tests (verify + | ||
| # contract). PR CI (ci.yml) re-proves this on the PR itself. | ||
| run: | | ||
| composer install --prefer-dist --no-progress | ||
| composer test | ||
|
|
||
| - name: Detect changes | ||
| id: diff | ||
| run: | | ||
| if git diff --quiet && [ -z "$(git status --porcelain)" ]; then | ||
| echo "changed=false" >> "$GITHUB_OUTPUT" | ||
| echo "No client changes; skipping PR." >> "$GITHUB_STEP_SUMMARY" | ||
| else | ||
| echo "changed=true" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Prepare feature branch | ||
| if: steps.diff.outputs.changed == 'true' | ||
| id: branch | ||
| env: | ||
| # Never interpolate free-form dispatch inputs into run: directly. | ||
| FEATURE_BRANCH_INPUT: ${{ inputs.feature_branch }} | ||
| run: | | ||
| if [ -n "$FEATURE_BRANCH_INPUT" ]; then | ||
| # SDK PRs must come from a reviewable feature branch, never a | ||
| # protected ref or an option-looking / metacharacter name. | ||
| # refs/* is blocked too: "refs/heads/main" would bypass the | ||
| # literal main check and force-push the default branch. | ||
| case "$FEATURE_BRANCH_INPUT" in | ||
| main|master|release/*|refs/*|-*|*[!a-zA-Z0-9._/-]*) | ||
| echo "::error::Invalid feature_branch '$FEATURE_BRANCH_INPUT'" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| echo "name=$FEATURE_BRANCH_INPUT" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "name=sdk-regen-$(date -u +%Y%m%d)" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Push branch and open PR | ||
| if: steps.diff.outputs.changed == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.SDK_BOT_PAT || secrets.GITHUB_TOKEN }} | ||
| BRANCH: ${{ steps.branch.outputs.name }} | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| git checkout -B "$BRANCH" | ||
| git add -A | ||
| git commit -m "feat: regenerate API client from OpenAPI spec" | ||
| # Force push is safe: the regen branch is fully derived from main | ||
| # plus this deterministic generation; any previous content is stale. | ||
| git push --force origin "$BRANCH" | ||
|
|
||
| existing=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number // empty') | ||
| if [ -z "$existing" ]; then | ||
| gh pr create \ | ||
| --head "$BRANCH" \ | ||
| --title "feat: regenerate API client from OpenAPI spec" \ | ||
| --body "Automated regeneration via OpenAPI Generator (php) from \`docs/v3/openapi3.yaml\` on frain-dev/convoy main. Hand-written SDK code (\`src/\` outside \`src/Client/\`, incl. webhook verify) is untouched by the sync script." | ||
| echo "Opened PR for $BRANCH" >> "$GITHUB_STEP_SUMMARY" | ||
| else | ||
| echo "Updated existing PR #$existing" >> "$GITHUB_STEP_SUMMARY" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,6 @@ psalm.xml | |
| vendor | ||
| .php-cs-fixer.cache | ||
|
|
||
|
|
||
| # OpenAPI Generator cache (scripts/generate.sh) | ||
| .cache/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # OpenAPI Generator (php) config for the generated API client. | ||
| # The generated code lives under src/Client/ (namespace Convoy\Client, mapped | ||
| # by the existing PSR-4 rule "Convoy\" => src); the hand-written SDK code in | ||
| # the rest of src/ is not generated and never touched by scripts/generate.sh. | ||
| invokerPackage: "Convoy\\Client" | ||
| hideGenerationTimestamp: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # Regenerate the API client from Convoy's OpenAPI spec with OpenAPI Generator | ||
| # (php), then sync it into src/Client/ without touching the hand-written SDK | ||
| # code (the rest of src/, incl. webhook verify). | ||
| # | ||
| # Requires: java 17+, rsync, curl. Run from the repo root. | ||
|
|
||
| SPEC_URL="${SPEC_URL:-https://raw.githubusercontent.com/frain-dev/convoy/main/docs/v3/openapi3.yaml}" | ||
| # Pin so regeneration output is reproducible; bump deliberately. | ||
| GENERATOR_VERSION="7.23.0" | ||
| GENERATOR_JAR="${GENERATOR_JAR:-.cache/openapi-generator-cli-${GENERATOR_VERSION}.jar}" | ||
| # Official artifact checksum; the download is verified before execution so a | ||
| # compromised mirror/CDN cannot run arbitrary code in CI. Update alongside | ||
| # GENERATOR_VERSION (sha256 of the Maven Central JAR). | ||
| GENERATOR_SHA256="cb087e40001e31eb08ef6140dd5de10938dbeb89016a1fe0481eaa25cd569026" | ||
|
|
||
| tmp="$(mktemp -d)" | ||
| trap 'rm -rf "$tmp"' EXIT | ||
|
|
||
| if [ ! -f "$GENERATOR_JAR" ]; then | ||
| mkdir -p "$(dirname "$GENERATOR_JAR")" | ||
| curl -fsSL -o "$GENERATOR_JAR" \ | ||
| "https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${GENERATOR_VERSION}/openapi-generator-cli-${GENERATOR_VERSION}.jar" | ||
| fi | ||
|
|
||
| # Fail closed on checksum mismatch (covers cached files too). | ||
| echo "${GENERATOR_SHA256} ${GENERATOR_JAR}" | shasum -a 256 -c - >/dev/null || { | ||
| echo "ERROR: ${GENERATOR_JAR} failed sha256 verification" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| curl -fsSL "$SPEC_URL" -o "$tmp/openapi3.yaml" | ||
|
|
||
| java -jar "$GENERATOR_JAR" generate \ | ||
| -i "$tmp/openapi3.yaml" \ | ||
| -g php \ | ||
| -c .openapi-generator-config.yaml \ | ||
| -o "$tmp/gen" | ||
|
|
||
| # Mirror only the generated namespace. --delete keeps src/Client an exact | ||
| # mirror of generator output; the hand-written src/ code is never touched. | ||
| rsync -a --delete "$tmp/gen/lib/" src/Client/ | ||
|
|
||
| echo "Generated client synced into src/Client/" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.