Skip to content
8 changes: 6 additions & 2 deletions .github/workflows/rdme-openapi.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: Publish OpenAPI specs to ReadMe
name: Publish OpenAPI specs to ReadMe Production

on:
push:
branches: [ main ]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll put this back after review

paths:
- 'openapi/**'
- '.github/actions/**'
- '.github/workflows/rdme-openapi.yml'

jobs:
rdme-openapi:
Expand All @@ -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'
17 changes: 9 additions & 8 deletions .github/workflows/rdme-staging.yml
Original file line number Diff line number Diff line change
@@ -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:
# ////////////////////////////////////////////////////////////////////////
Expand Down
20 changes: 10 additions & 10 deletions openapi/openapi.config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 23 additions & 12 deletions openapi/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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}`,
},
}
);
Expand All @@ -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`,
],
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion openapi/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading