Skip to content

Commit e8089e6

Browse files
committed
DOP-5448: Create Bump GH action for previews and deploys
1 parent 246df4d commit e8089e6

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
const ATLAS_ADMIN_API_V2_DOC = 'atlas-admin-api-v2';
8+
9+
const SPEC_MAPPING = [
10+
{
11+
doc: 'atlas-admin-api-v1',
12+
file: 'openapi/v1-deprecated/v1.json',
13+
branch: 'main',
14+
},
15+
// Need to programmatically handle resource versions separately
16+
{
17+
doc: ATLAS_ADMIN_API_V2_DOC,
18+
file: 'openapi/v2.json',
19+
branch: 'latest',
20+
},
21+
];
22+
23+
/**
24+
* Handles the resource versions for Atlas Admin API v2
25+
*/
26+
function handleResourceVersions() {
27+
const directory = 'openapi/v2';
28+
const filePath = path.join(__dirname, `../../${directory}/versions.json`);
29+
const versions = JSON.parse(fs.readFileSync(filePath, 'utf8'));
30+
31+
for (const version of versions) {
32+
const openapiFilename = `openapi-${version}.json`;
33+
const openapiFilePath = path.join(path.dirname(filePath), openapiFilename);
34+
35+
if (!fs.existsSync(openapiFilePath)) {
36+
continue;
37+
}
38+
39+
SPEC_MAPPING.push({
40+
doc: ATLAS_ADMIN_API_V2_DOC,
41+
file: `${directory}/${openapiFilename}`,
42+
branch: version,
43+
});
44+
}
45+
}
46+
47+
handleResourceVersions();
48+
console.log(JSON.stringify(SPEC_MAPPING));
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Check & deploy API documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'openapi/**.json'
9+
10+
pull_request:
11+
branches:
12+
- main
13+
paths:
14+
- 'openapi/**.json'
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
create-matrix:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
matrix: ${{ steps.set-matrix.outputs.matrix }}
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
- name: Setup Node
28+
uses: actions/setup-node@v4
29+
- name: Generate matrix
30+
id: set-matrix
31+
run: |
32+
spec_mapping=$(node .github/scripts/generateSpecMapping.js)
33+
echo "matrix=$spec_mapping" >> "$GITHUB_OUTPUT"
34+
35+
deploy-doc:
36+
needs: create-matrix
37+
if: ${{ github.event_name == 'push' }}
38+
name: Deploy API documentation on Bump.sh
39+
strategy:
40+
matrix:
41+
spec-mapping: ${{ fromJson(needs.create-matrix.outputs.matrix) }}
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v4
46+
- name: Deploy API documentation
47+
uses: bump-sh/github-action@v1
48+
with:
49+
doc: ${{matrix.spec-mapping.doc}}
50+
token: ${{secrets.BUMP_TOKEN}}
51+
file: ${{matrix.spec-mapping.file}}
52+
branch: ${{matrix.spec-mapping.branch}}
53+
54+
api-preview:
55+
needs: create-matrix
56+
if: ${{ github.event_name == 'pull_request' }}
57+
name: Create API preview on Bump.sh
58+
strategy:
59+
matrix:
60+
spec-mapping: ${{ fromJSON(needs.create-matrix.outputs.matrix) }}
61+
runs-on: ubuntu-latest
62+
steps:
63+
- name: Checkout
64+
uses: actions/checkout@v4
65+
- name: Create API preview
66+
uses: bump-sh/github-action@v1
67+
with:
68+
doc: ${{matrix.spec-mapping.doc}}
69+
token: ${{secrets.BUMP_TOKEN}}
70+
file: ${{matrix.spec-mapping.file}}
71+
branch: ${{matrix.spec-mapping.branch}}
72+
command: preview

0 commit comments

Comments
 (0)