-
Notifications
You must be signed in to change notification settings - Fork 12
HYPERFLEET-1024 - feat: CI for schema checks, version bump, externalize as Go module #42
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
Changes from all commits
f3a980a
4bab831
79da4d2
e286c57
e9a3736
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,68 @@ | ||||||||||||||||||||||||||||||||||||||
| name: CI | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||||||
| pull_request: | ||||||||||||||||||||||||||||||||||||||
| push: | ||||||||||||||||||||||||||||||||||||||
| branches: | ||||||||||||||||||||||||||||||||||||||
| - main | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||
| validate: | ||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||
| - name: Checkout code | ||||||||||||||||||||||||||||||||||||||
| uses: actions/checkout@v6 | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: Setup Node.js | ||||||||||||||||||||||||||||||||||||||
| uses: actions/setup-node@v6 | ||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||
| node-version: '20' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: Install dependencies | ||||||||||||||||||||||||||||||||||||||
| run: npm ci | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: Build all schemas | ||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||
| ./build-schema.sh core | ||||||||||||||||||||||||||||||||||||||
| ./build-schema.sh core --swagger | ||||||||||||||||||||||||||||||||||||||
| ./build-schema.sh gcp | ||||||||||||||||||||||||||||||||||||||
| ./build-schema.sh gcp --swagger | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: Check schema consistency | ||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||
| if ! git diff --exit-code schemas/; then | ||||||||||||||||||||||||||||||||||||||
| echo "Committed schemas are out of sync with TypeSpec sources." | ||||||||||||||||||||||||||||||||||||||
| echo "Run './build-schema.sh core --swagger && ./build-schema.sh gcp --swagger' and commit the results." | ||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: Lint OpenAPI schemas | ||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||
| npx spectral lint schemas/core/openapi.yaml schemas/gcp/openapi.yaml --format github-actions --fail-severity warn | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: Check version bump | ||||||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||||||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||
| CURRENT=$(grep -oP '(?<=version: ")[^"]+' main.tsp) | ||||||||||||||||||||||||||||||||||||||
| if [ -z "$CURRENT" ]; then | ||||||||||||||||||||||||||||||||||||||
| echo "::error::Failed to extract version from main.tsp — check the @info decorator format" >&2 | ||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
| LATEST=$(gh release list --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null | sed 's/^v//' || echo "") | ||||||||||||||||||||||||||||||||||||||
| if [ -z "$LATEST" ]; then | ||||||||||||||||||||||||||||||||||||||
| echo "No previous releases found — version check skipped" | ||||||||||||||||||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+55
to
+58
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. Don’t treat GitHub API failures as “no previous releases.”
Suggested fix- LATEST=$(gh release list --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null | sed 's/^v//' || echo "")
- if [ -z "$LATEST" ]; then
+ if ! RAW_LATEST=$(gh release list --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null); then
+ echo "::error::Failed to query latest GitHub release tag via gh."
+ exit 1
+ fi
+ LATEST=$(printf '%s' "$RAW_LATEST" | sed 's/^v//')
+ if [ -z "$RAW_LATEST" ]; then
echo "No previous releases found — version check skipped"
exit 0
fiAs per coding guidelines, "CI requirements for PRs: Enforce a strict version bump ... and fail unless main.tsp’s version is strictly greater than the latest release (or skip if no prior releases)." 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
| HIGHEST=$(printf '%s\n%s\n' "$CURRENT" "$LATEST" | sort -V | tail -1) | ||||||||||||||||||||||||||||||||||||||
| if [ "$CURRENT" = "$LATEST" ]; then | ||||||||||||||||||||||||||||||||||||||
| echo "::error::Version '$CURRENT' matches latest release tag 'v$LATEST' — bump the version in main.tsp before merging." | ||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||
| elif [ "$HIGHEST" != "$CURRENT" ]; then | ||||||||||||||||||||||||||||||||||||||
| echo "::error::Version '$CURRENT' is lower than latest release 'v$LATEST' — version in main.tsp must be strictly greater." | ||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
| echo "Version bump OK: $LATEST → $CURRENT" | ||||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| extends: ["spectral:oas"] | ||
| overrides: | ||
| - files: | ||
| - "schemas/core/openapi.yaml#/components/schemas/BearerAuth" | ||
| - "schemas/gcp/openapi.yaml#/components/schemas/BearerAuth" | ||
| rules: | ||
| oas3-unused-component: off |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,19 +20,13 @@ Thank you for your interest in contributing to the HyperFleet API specification! | |
| cd hyperfleet-api-spec | ||
| ``` | ||
|
|
||
| 2. Install TypeSpec compiler globally: | ||
|
|
||
| ```bash | ||
| npm install -g @typespec/compiler | ||
| ``` | ||
|
|
||
| 3. Install project dependencies: | ||
| 2. Install project dependencies (includes the TypeSpec compiler locally): | ||
|
|
||
| ```bash | ||
| npm install | ||
| ``` | ||
|
|
||
| 4. Verify your setup by building the schemas: | ||
| 3. Verify your setup by building the schemas: | ||
|
|
||
| ```bash | ||
| npm run build:core | ||
|
|
@@ -85,6 +79,22 @@ npm run build:gcp:swagger | |
| npm run build:all | ||
| ``` | ||
|
|
||
| ### Linting Schemas | ||
|
|
||
| CI automatically lints OpenAPI schemas using a pinned version of [Spectral](https://github.com/stoplightio/spectral) installed locally in the workflow. For local linting during development, install Spectral globally: | ||
|
|
||
| ```bash | ||
| npm install -g @stoplight/spectral-cli | ||
| ``` | ||
|
|
||
| Then lint the generated schemas: | ||
|
|
||
| ```bash | ||
| spectral lint schemas/core/openapi.yaml schemas/gcp/openapi.yaml | ||
| ``` | ||
|
Comment on lines
+84
to
+94
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. Use local/pinned Spectral in contributor instructions, not a global install Line 84 correctly calls out pinned CI behavior, but Lines 85-94 switch to a global install and unpinned binary invocation. That can produce lint results different from CI and hurts reproducibility for contributors. Suggested doc fix-CI automatically lints OpenAPI schemas using a pinned version of [Spectral](https://github.com/stoplightio/spectral) installed locally in the workflow. For local linting during development, install Spectral globally:
+CI automatically lints OpenAPI schemas using a pinned version of [Spectral](https://github.com/stoplightio/spectral) installed locally in the workflow. For local linting during development, use the project-local dependency:
```bash
-npm install -g `@stoplight/spectral-cli`
+npm ciThen lint the generated schemas: -spectral lint schemas/core/openapi.yaml schemas/gcp/openapi.yaml
+node_modules/.bin/spectral lint schemas/core/openapi.yaml schemas/gcp/openapi.yamlVerify each finding against current code. Fix only still-valid issues, skip the In |
||
|
|
||
| The `.spectral.yaml` config at the repo root applies the `spectral:oas` ruleset. | ||
|
|
||
| ### Validating Output | ||
|
|
||
| After building, verify the generated schemas: | ||
|
|
@@ -212,15 +222,15 @@ refactor: consolidate common status fields | |
|
|
||
| ## Release Process | ||
|
|
||
| See [RELEASING.md](RELEASING.md) for detailed release instructions. | ||
| Releases are **fully automated**. See [RELEASING.md](RELEASING.md) for details. | ||
|
|
||
| When a PR is merged to `main`, the release workflow automatically: | ||
|
|
||
| **Quick summary:** | ||
| 1. Extracts the version from `main.tsp` | ||
| 2. Creates an annotated Git tag | ||
| 3. Publishes a GitHub Release with all four schema artifacts attached | ||
|
|
||
| 1. Build schemas: `npm run build:all` | ||
| 2. Commit changes | ||
| 3. Create tag: `git tag -a vX.Y.Z -m "Release vX.Y.Z"` | ||
| 4. Push tag: `git push upstream vX.Y.Z` | ||
| 5. Create GitHub Release with `core-openapi.yaml` and `gcp-openapi.yaml` assets | ||
| The CI workflow enforces that the version in `main.tsp` is bumped from the latest release tag before a PR can be merged. | ||
|
|
||
| ## Pull Request Process | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.