-
Notifications
You must be signed in to change notification settings - Fork 670
ci: add spectral lint workflow for openapi.yaml #2547
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
Draft
mandarini
wants to merge
2
commits into
master
Choose a base branch
from
ci/openapi-lint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,31 @@ | ||
| name: OpenAPI Lint | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "openapi.yaml" | ||
| - ".spectral.yaml" | ||
| - ".github/workflows/openapi-lint.yml" | ||
| push: | ||
| branches: | ||
| - master | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: openapi-lint-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| spectral: | ||
| name: Spectral lint | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 5 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: stoplightio/spectral-action@6416fd018ae38e60136775066eb3e98172143141 # v0.8.13 | ||
| with: | ||
| file_glob: openapi.yaml | ||
| spectral_ruleset: .spectral.yaml |
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,132 @@ | ||
| name: Schemathesis | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "openapi.yaml" | ||
| - "internal/api/**" | ||
| - "cmd/**" | ||
| - "hack/test.env" | ||
| - ".github/workflows/schemathesis.yml" | ||
| push: | ||
| branches: | ||
| - master | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: schemathesis-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| contract_test: | ||
| name: Contract test (Schemathesis) | ||
| runs-on: blacksmith-4vcpu-ubuntu-2404 | ||
| timeout-minutes: 20 | ||
|
|
||
| services: | ||
| postgres: | ||
| image: postgres:15 | ||
| env: | ||
| POSTGRES_USER: postgres | ||
| POSTGRES_PASSWORD: root | ||
| POSTGRES_DB: postgres | ||
| ports: | ||
| - 5432:5432 | ||
| options: >- | ||
| --health-cmd pg_isready | ||
| --health-interval 10s | ||
| --health-timeout 5s | ||
| --health-retries 5 | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - name: Install Go | ||
| uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0 | ||
| with: | ||
| go-version-file: go.mod | ||
|
|
||
| - name: Install Python | ||
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Init database | ||
| run: psql -f hack/init_postgres.sql postgresql://postgres:root@localhost:5432/postgres | ||
|
|
||
| - name: Run migrations | ||
| run: make migrate_dev | ||
|
|
||
| - name: Build auth | ||
| run: make auth | ||
|
|
||
| - name: Start auth server | ||
| run: | | ||
| ./auth -c=hack/test.env > auth.log 2>&1 & | ||
| echo $! > auth.pid | ||
| echo "auth started with pid $(cat auth.pid)" | ||
|
|
||
| - name: Wait for auth /health | ||
| run: | | ||
| for i in $(seq 1 30); do | ||
| if curl -fs http://localhost:9999/health > /dev/null; then | ||
| echo "auth is up" | ||
| exit 0 | ||
| fi | ||
| sleep 1 | ||
| done | ||
| echo "auth did not come up in 30s; last log lines:" | ||
| tail -n 100 auth.log || true | ||
| exit 1 | ||
|
|
||
| - name: Install Schemathesis | ||
| run: pip install --upgrade 'schemathesis>=3.36,<4' PyJWT | ||
|
|
||
| - name: Mint test JWT | ||
| id: jwt | ||
| run: | | ||
| TOKEN=$(python3 - <<'PY' | ||
| import jwt | ||
| token = jwt.encode( | ||
| {"role": "anon", "aud": "authenticated", "iss": "supabase"}, | ||
| "testsecret", | ||
| algorithm="HS256", | ||
| ) | ||
| print(token) | ||
| PY | ||
| ) | ||
| echo "::add-mask::$TOKEN" | ||
| echo "token=$TOKEN" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Run Schemathesis | ||
| id: schemathesis | ||
| continue-on-error: true | ||
| run: | | ||
| schemathesis run openapi.yaml \ | ||
| --url=http://localhost:9999 \ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| --header="apikey: ${{ steps.jwt.outputs.token }}" \ | ||
| --exclude-path-regex='^/(recover|resend|magiclink|otp|invite|authorize|callback|saml/acs|admin)($|/)' \ | ||
| --hypothesis-max-examples=50 \ | ||
| --checks=all \ | ||
| --junit-xml=schemathesis-report.xml | ||
|
|
||
| - name: Stop auth server | ||
| if: always() | ||
| run: | | ||
| if [ -f auth.pid ]; then | ||
| kill "$(cat auth.pid)" 2>/dev/null || true | ||
| fi | ||
|
|
||
| - name: Upload artifacts | ||
| if: always() | ||
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | ||
| with: | ||
| name: schemathesis-output | ||
| path: | | ||
| schemathesis-report.xml | ||
| auth.log | ||
| if-no-files-found: warn | ||
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,13 @@ | ||
| extends: | ||
| - "spectral:oas" | ||
|
|
||
| # Soft start: warn rather than error on style nits. | ||
| # Tighten over time once the spec passes the strict ruleset. | ||
| rules: | ||
| operation-tag-defined: warn | ||
| operation-description: warn | ||
| operation-tags: warn | ||
| oas3-unused-component: warn | ||
| info-contact: off | ||
| info-license: off | ||
| oas3-server-not-example.com: off |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mandarini Would you consider install the latest version of Schemathesis? Branch 3.x is unsupported and haven't had any updates for ~1.5 years already (and I don't have any plans for it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep thanks! I'm just testing things out atm in any case, but of course, I'll update!