From 25144511adc9a81d770d3c2b74797cd9a03bc6f4 Mon Sep 17 00:00:00 2001 From: Ondrej Ezr Date: Tue, 23 Jan 2024 10:07:27 +0100 Subject: [PATCH] api: split pulling API changes and regenerating new API For checking wether the api was tempered with, we need separate action, that just checks the code against the currently pulled spec. This introduces two subactions for `npx api`. These are `npx api:generate` and `npx api:pull`. --- .github/workflows/dev-checks.yml | 2 +- api/README.md | 19 +++++++++++++++++++ api.sh => api/codegen.sh | 3 --- api/pull.sh | 4 ++++ package.json | 4 +++- 5 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 api/README.md rename api.sh => api/codegen.sh (66%) create mode 100644 api/pull.sh diff --git a/.github/workflows/dev-checks.yml b/.github/workflows/dev-checks.yml index d3a0075a..52296695 100644 --- a/.github/workflows/dev-checks.yml +++ b/.github/workflows/dev-checks.yml @@ -22,7 +22,7 @@ jobs: - name: Install dependencies run: npm ci - name: Check for manual changes to API - run: npm run api && [ -z "$(git status --porcelain=v1 2>/dev/null)" ] && echo "✓ No manual API changes." || echo "✗ API manually changed, please refer to the README for the procedure to follow for programmatically generated API endpoints." && [ -z "$(git status --porcelain=v1 2>/dev/null)" ] + run: npm run api:generate && [ -z "$(git status --porcelain=v1 2>/dev/null)" ] && echo "✓ No manual API changes." || echo "✗ API manually changed, please refer to the README for the procedure to follow for programmatically generated API endpoints." && [ -z "$(git status --porcelain=v1 2>/dev/null)" ] - name: Run build run: npm run build - name: Run lint check diff --git a/api/README.md b/api/README.md new file mode 100644 index 00000000..f85ad6d8 --- /dev/null +++ b/api/README.md @@ -0,0 +1,19 @@ +# API + +This folder contains generated code for API endpoints needed by this repo. + +## Updating API changes + +To pull new API changes and regenerating the code run + +```shell +npm run api +``` + +## Regenerating the code only + +To regenerate the code only, run + +```shell +npm run api:generate +``` \ No newline at end of file diff --git a/api.sh b/api/codegen.sh similarity index 66% rename from api.sh rename to api/codegen.sh index 6afac99a..0a7df723 100644 --- a/api.sh +++ b/api/codegen.sh @@ -1,8 +1,5 @@ #!/bin/bash -# Download the most up-to-date imageBuilder.yaml file and overwrite the existing one -curl https://raw.githubusercontent.com/osbuild/image-builder/main/internal/v1/api.yaml -o ./api/schema/imageBuilder.yaml - # Run commands in the background using & operator npx @rtk-query/codegen-openapi ./api/config/imageBuilder.ts & npx @rtk-query/codegen-openapi ./api/config/rhsm.ts & diff --git a/api/pull.sh b/api/pull.sh new file mode 100644 index 00000000..0c4d0b96 --- /dev/null +++ b/api/pull.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Download the most up-to-date imageBuilder.yaml file and overwrite the existing one +curl https://raw.githubusercontent.com/osbuild/image-builder/main/internal/v1/api.yaml -o ./api/schema/imageBuilder.yaml diff --git a/package.json b/package.json index 5d10e9ac..2334a1cf 100644 --- a/package.json +++ b/package.json @@ -129,7 +129,9 @@ "test": "TZ=UTC jest --verbose --no-cache", "test:single": "jest --verbose -w 1", "build": "webpack --config config/prod.webpack.config.js", - "api": "bash api.sh", + "api": "npm-run-all api:*", + "api:generate": "bash api/codegen.sh", + "api:pull": "bash api/pull.sh", "verify": "npm-run-all build lint test" }, "insights": {