Skip to content

Commit f8e6530

Browse files
CLOUDP-308422: addressing follow up comments
2 parents 54c68b7 + c657a6a commit f8e6530

File tree

98 files changed

+4096
-970
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+4096
-970
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = path.dirname(__filename);
7+
8+
// Standalone specs can be added directly to the mapping. Any spec that requires displaying a version dropdown
9+
// will need to map its different versions to a separate Bump "branch". For example, a new resource version
10+
// for Atlas Admin API v2 will lead to a new entry in the array with its own Bump branch.
11+
const SPEC_MAPPING = [
12+
{
13+
doc: process.env.ATLAS_ADMIN_V1_DOC_ID,
14+
file: 'openapi/v1-deprecated/v1.json',
15+
branch: 'main',
16+
},
17+
];
18+
19+
function handleAdminAPIv2() {
20+
const docId = process.env.ATLAS_ADMIN_V2_DOC_ID;
21+
const directory = 'openapi/v2';
22+
const filePath = path.join(__dirname, `../../${directory}/versions.json`);
23+
const versions = JSON.parse(fs.readFileSync(filePath, 'utf8'));
24+
25+
if (!versions || !Array.isArray(versions)) {
26+
console.error(`No versions found for Atlas Admin API v2 at ${filePath}`);
27+
return;
28+
}
29+
30+
for (const [index, version] of versions.entries()) {
31+
const openapiFilename = `openapi-${version}.json`;
32+
const openapiFilePath = path.join(path.dirname(filePath), openapiFilename);
33+
34+
if (!fs.existsSync(openapiFilePath)) {
35+
console.error(`Could not find resource version "${version}" at ${openapiFilePath}`);
36+
continue;
37+
}
38+
39+
const file = `${directory}/${openapiFilename}`;
40+
SPEC_MAPPING.push({
41+
doc: docId,
42+
file,
43+
branch: version,
44+
});
45+
46+
// We want the latest version to have its own version AND be the latest/default branch
47+
if (index === versions.length - 1) {
48+
SPEC_MAPPING.push({
49+
doc: docId,
50+
file,
51+
branch: 'latest',
52+
});
53+
}
54+
}
55+
}
56+
57+
handleAdminAPIv2();
58+
// Output to GH action
59+
console.log(JSON.stringify(SPEC_MAPPING));
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Check & deploy API documentation
2+
3+
on:
4+
# For deployments
5+
workflow_dispatch: # Allow manual trigger in case of quick fix
6+
push:
7+
branches:
8+
- main
9+
paths:
10+
- 'openapi/**.json'
11+
12+
# For previews
13+
pull_request:
14+
branches:
15+
- main
16+
paths:
17+
- 'openapi/**.json'
18+
19+
permissions:
20+
contents: read
21+
22+
jobs:
23+
create-matrix:
24+
runs-on: ubuntu-latest
25+
outputs:
26+
matrix: ${{ steps.set-matrix.outputs.matrix }}
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
- name: Setup Node
31+
uses: actions/setup-node@v4
32+
- name: Generate matrix
33+
id: set-matrix
34+
env:
35+
ATLAS_ADMIN_V1_DOC_ID: ${{ vars.ATLAS_ADMIN_V1_DOC_ID }}
36+
ATLAS_ADMIN_V2_DOC_ID: ${{ vars.ATLAS_ADMIN_V2_DOC_ID }}
37+
run: |
38+
spec_mapping=$(node .github/scripts/generateSpecMapping.js)
39+
echo "matrix=$spec_mapping" >> "$GITHUB_OUTPUT"
40+
41+
deploy-doc:
42+
needs: create-matrix
43+
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
44+
name: Deploy API documentation on Bump.sh
45+
strategy:
46+
matrix:
47+
spec-mapping: ${{ fromJson(needs.create-matrix.outputs.matrix) }}
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v4
52+
- name: Deploy API documentation
53+
uses: bump-sh/github-action@690c81156715f37cb72d006e5cbb81fbd9b45365
54+
with:
55+
doc: ${{matrix.spec-mapping.doc}}
56+
token: ${{secrets.BUMP_TOKEN}}
57+
file: ${{matrix.spec-mapping.file}}
58+
branch: ${{matrix.spec-mapping.branch}}
59+
60+
api-preview:
61+
needs: create-matrix
62+
if: ${{ github.event_name == 'pull_request' }}
63+
name: Create API preview on Bump.sh
64+
strategy:
65+
matrix:
66+
spec-mapping: ${{ fromJSON(needs.create-matrix.outputs.matrix) }}
67+
runs-on: ubuntu-latest
68+
steps:
69+
- name: Checkout
70+
uses: actions/checkout@v4
71+
- name: Create API preview
72+
uses: bump-sh/github-action@690c81156715f37cb72d006e5cbb81fbd9b45365
73+
with:
74+
doc: ${{matrix.spec-mapping.doc}}
75+
token: ${{secrets.BUMP_TOKEN}}
76+
file: ${{matrix.spec-mapping.file}}
77+
branch: ${{matrix.spec-mapping.branch}}
78+
command: preview

.github/workflows/optional-spec-validations.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
run-id: ${{ github.run_id }}
4242
- name: Run IPA validation
4343
id: ipa-spectral-validation
44+
if: ${{ inputs.env == 'dev'}}
4445
run: |
4546
npx spectral lint openapi-foas.json --ruleset=./tools/spectral/ipa/ipa-spectral.yaml
4647
- name: Validate the FOAS can be used to generate Postman collection

.github/workflows/spectral-lint.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ name: Spectral Lint Commited OpenAPI Spec
33
# Trigger the workflow on pull requests and pushes to the main branch
44
on:
55
pull_request:
6-
paths:
6+
paths:
77
- 'tools/spectral/**'
88
- 'openapi/**.yaml'
99
- 'package.json'
1010
push:
1111
branches:
1212
- main
13-
paths:
13+
paths:
1414
- 'tools/spectral/**'
1515
- 'openapi/**.yaml'
1616
- 'package.json'
1717

1818
jobs:
1919
spectral-lint:
2020
runs-on: ubuntu-latest
21-
21+
2222
steps:
2323
# Checkout the code
2424
- name: Checkout repository
@@ -34,6 +34,9 @@ jobs:
3434
cache: 'npm'
3535
- name: Install npm dependencies
3636
run: npm install
37+
- name: Fetch OAS file from Dev Branch
38+
run: curl -O "https://raw.githubusercontent.com/mongodb/openapi/refs/heads/dev/openapi/.raw/v2.yaml"
39+
working-directory: ${{ github.workspace }}
3740
- name: Spectral action
3841
uses: stoplightio/spectral-action@2ad0b9302e32a77c1caccf474a9b2191a8060d83
3942
with:
@@ -43,5 +46,6 @@ jobs:
4346
- name: IPA validation action
4447
uses: stoplightio/spectral-action@2ad0b9302e32a77c1caccf474a9b2191a8060d83
4548
with:
46-
file_glob: openapi/.raw/v2.yaml
49+
file_glob: v2.yaml
4750
spectral_ruleset: tools/spectral/ipa/ipa-spectral.yaml
51+

0 commit comments

Comments
 (0)