diff --git a/.github/workflows/rdme-openapi.yml b/.github/workflows/rdme-openapi.yml index 8c5a22d404..56058926b1 100644 --- a/.github/workflows/rdme-openapi.yml +++ b/.github/workflows/rdme-openapi.yml @@ -1,8 +1,12 @@ -name: Publish OpenAPI specs to ReadMe +name: Publish OpenAPI specs to ReadMe Production on: push: branches: [ main ] + paths: + - 'openapi/**' + - '.github/actions/**' + - '.github/workflows/rdme-openapi.yml' jobs: rdme-openapi: @@ -17,4 +21,4 @@ jobs: - run: npm run api:publish env: README_API_KEY: ${{ secrets.README_API_KEY }} - README_VERSION: '3.26' + README_VERSION: '3.27' diff --git a/.github/workflows/rdme-staging.yml b/.github/workflows/rdme-staging.yml index de8c8a51f8..4326af65ed 100644 --- a/.github/workflows/rdme-staging.yml +++ b/.github/workflows/rdme-staging.yml @@ -1,13 +1,14 @@ name: Generate ReadMe Staging 🦉 -on: - # run this workflow on all PRs that have reference dirs changed - pull_request: - paths: - - 'openapi/**' - - 'reference/**' - - '.github/actions/**' - - '.github/workflows/rdme-staging.yml' +# This is currently broken, fix this in a future PR +# on: +# # run this workflow on all PRs that have reference dirs changed +# pull_request: +# paths: +# - 'openapi/**' +# - 'reference/**' +# - '.github/actions/**' +# - '.github/workflows/rdme-staging.yml' jobs: # //////////////////////////////////////////////////////////////////////// diff --git a/openapi/openapi.config.yaml b/openapi/openapi.config.yaml index a2e3d7d45a..d81f1ef923 100644 --- a/openapi/openapi.config.yaml +++ b/openapi/openapi.config.yaml @@ -1,34 +1,34 @@ apis: annotations: root: ./src/annotations.openapi.yaml - output: ./out/annotations.openapi.yaml + output: ./out/annotations-api.json data-pipelines: root: ./src/data-pipelines.openapi.yaml - output: ./out/data-pipelines.openapi.yaml + output: ./out/data-pipelines-api.json export: root: ./src/export.openapi.yaml - output: ./out/export.openapi.yaml + output: ./out/event-export-api.json gdpr: root: ./src/gdpr.openapi.yaml - output: ./out/gdpr.openapi.yaml + output: ./out/gdpr-api-2.json identity: root: ./src/identity.openapi.yaml - output: ./out/identity.openapi.yaml + output: ./out/identity-api.json ingestion: root: ./src/ingestion.openapi.yaml - output: ./out/ingestion.openapi.yaml + output: ./out/ingestion-api.json lexicon-schemas: root: ./src/lexicon-schemas.openapi.yaml - output: ./out/lexicon-schemas.openapi.yaml + output: ./out/lexicon-schemas-api.json query: root: ./src/query.openapi.yaml - output: ./out/query.openapi.yaml + output: ./out/query-api.json service-accounts: root: ./src/service-accounts.openapi.yaml - output: ./out/service-accounts.openapi.yaml + output: ./out/service-accounts-api.json warehouse-connectors: root: ./src/warehouse-connectors.openapi.yaml - output: ./out/warehouse-connectors.openapi.yaml + output: ./out/warehouse-connectors-api.json extends: - recommended diff --git a/openapi/publish.js b/openapi/publish.js index 675d09c7cc..8f6773eda5 100644 --- a/openapi/publish.js +++ b/openapi/publish.js @@ -7,11 +7,11 @@ const YAML = require("yaml"); const execFile = util.promisify(require("node:child_process").execFile); const README_API_KEY = process.env.README_API_KEY; +const README_VERSION = process.env.README_VERSION; if (!README_API_KEY) { console.error(`README_API_KEY not set`); process.exit(1); } -const README_VERSION = process.env.README_VERSION; if (!README_VERSION) { console.error(`README_VERSION not set`); process.exit(1); @@ -31,13 +31,10 @@ async function execAndLog(cmd, args) { async function updateSpecs() { // fetch IDs of openapi specs via readme API const res = await fetch( - `https://dash.readme.com/api/v1/api-specification?perPage=10&page=1`, + `https://api.readme.com/v2/branches/${README_VERSION}/apis`, { headers: { - Authorization: `Basic ${Buffer.from(README_API_KEY).toString( - "base64" - )}`, - "x-readme-version": README_VERSION, + Authorization: `Bearer ${README_API_KEY}`, }, } ); @@ -47,25 +44,39 @@ async function updateSpecs() { const outBase = path.resolve(__dirname, `out`); const filenames = fs .readdirSync(outBase) - .filter((fn) => fn.endsWith(`.openapi.yaml`)); + .filter((fn) => fn.endsWith(`.json`)); + + if (!remoteSpecMetas) { + console.error(`!!! No remote specs found, please double check the API`); + process.exit(1); + } for (specFile of filenames) { // get ID of each spec by matching title between filename and metadata const fullPath = path.join(outBase, specFile); const yamlStr = fs.readFileSync(fullPath, "utf8"); const spec = YAML.parse(yamlStr); - const specMeta = remoteSpecMetas.find((m) => m.title === spec.info.title); + const specMeta = remoteSpecMetas.data.find((m) => m.filename === specFile); if (!specMeta) { console.log(`!!! No spec found for "${spec.info.title}". Please upload it as found in the developer.mixpanel.com runbook.`); continue; } - const specId = specMeta.id; // validate and publish spec - console.log(`Updating ${spec.info.title} (${specFile}, ID ${specId})`); - await execAndLog('npx', ['rdme', 'openapi:validate', fullPath]); + console.log(`Updating ${spec.info.title} (${specFile})`); + await execAndLog('npx', ['rdme@10.5.1', 'openapi:validate', fullPath]); + // publish the json version await execAndLog( - 'npx', ['rdme', 'openapi', fullPath, `--id=${specId}`, `--key=${README_API_KEY}`] + 'npx', [ + 'rdme@10.5.1', + 'openapi', + 'upload', + `${fullPath}`, + `--key=${README_API_KEY}`, + `--slug=${specFile}`, + `--branch=${README_VERSION}`, + `--confirm-overwrite`, + ], ); } } diff --git a/openapi/test.sh b/openapi/test.sh index 913e715776..d3762e99df 100755 --- a/openapi/test.sh +++ b/openapi/test.sh @@ -4,7 +4,7 @@ set -e npm run api:lint npm run api:build -for file in openapi/out/*.yaml; do +for file in openapi/out/*.json; do echo "✔ Validating $file" npx rdme openapi:validate $file done