From e8089e63c1ef98de08c5f086437072de12a02438 Mon Sep 17 00:00:00 2001 From: rayangler <27821750+rayangler@users.noreply.github.com> Date: Fri, 28 Feb 2025 18:43:02 -0500 Subject: [PATCH 1/9] DOP-5448: Create Bump GH action for previews and deploys --- .github/scripts/generateSpecMapping.js | 48 +++++++++++++++ .github/workflows/generate-bump-pages.yml | 72 +++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 .github/scripts/generateSpecMapping.js create mode 100644 .github/workflows/generate-bump-pages.yml diff --git a/.github/scripts/generateSpecMapping.js b/.github/scripts/generateSpecMapping.js new file mode 100644 index 0000000000..5d397bc0c2 --- /dev/null +++ b/.github/scripts/generateSpecMapping.js @@ -0,0 +1,48 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const ATLAS_ADMIN_API_V2_DOC = 'atlas-admin-api-v2'; + +const SPEC_MAPPING = [ + { + doc: 'atlas-admin-api-v1', + file: 'openapi/v1-deprecated/v1.json', + branch: 'main', + }, + // Need to programmatically handle resource versions separately + { + doc: ATLAS_ADMIN_API_V2_DOC, + file: 'openapi/v2.json', + branch: 'latest', + }, +]; + +/** + * Handles the resource versions for Atlas Admin API v2 + */ +function handleResourceVersions() { + const directory = 'openapi/v2'; + const filePath = path.join(__dirname, `../../${directory}/versions.json`); + const versions = JSON.parse(fs.readFileSync(filePath, 'utf8')); + + for (const version of versions) { + const openapiFilename = `openapi-${version}.json`; + const openapiFilePath = path.join(path.dirname(filePath), openapiFilename); + + if (!fs.existsSync(openapiFilePath)) { + continue; + } + + SPEC_MAPPING.push({ + doc: ATLAS_ADMIN_API_V2_DOC, + file: `${directory}/${openapiFilename}`, + branch: version, + }); + } +} + +handleResourceVersions(); +console.log(JSON.stringify(SPEC_MAPPING)); diff --git a/.github/workflows/generate-bump-pages.yml b/.github/workflows/generate-bump-pages.yml new file mode 100644 index 0000000000..1826c96bdb --- /dev/null +++ b/.github/workflows/generate-bump-pages.yml @@ -0,0 +1,72 @@ +name: Check & deploy API documentation + +on: + push: + branches: + - main + paths: + - 'openapi/**.json' + + pull_request: + branches: + - main + paths: + - 'openapi/**.json' + +permissions: + contents: read + +jobs: + create-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup Node + uses: actions/setup-node@v4 + - name: Generate matrix + id: set-matrix + run: | + spec_mapping=$(node .github/scripts/generateSpecMapping.js) + echo "matrix=$spec_mapping" >> "$GITHUB_OUTPUT" + + deploy-doc: + needs: create-matrix + if: ${{ github.event_name == 'push' }} + name: Deploy API documentation on Bump.sh + strategy: + matrix: + spec-mapping: ${{ fromJson(needs.create-matrix.outputs.matrix) }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Deploy API documentation + uses: bump-sh/github-action@v1 + with: + doc: ${{matrix.spec-mapping.doc}} + token: ${{secrets.BUMP_TOKEN}} + file: ${{matrix.spec-mapping.file}} + branch: ${{matrix.spec-mapping.branch}} + + api-preview: + needs: create-matrix + if: ${{ github.event_name == 'pull_request' }} + name: Create API preview on Bump.sh + strategy: + matrix: + spec-mapping: ${{ fromJSON(needs.create-matrix.outputs.matrix) }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Create API preview + uses: bump-sh/github-action@v1 + with: + doc: ${{matrix.spec-mapping.doc}} + token: ${{secrets.BUMP_TOKEN}} + file: ${{matrix.spec-mapping.file}} + branch: ${{matrix.spec-mapping.branch}} + command: preview From 4912fa5225ca079d4fdb440cd282e1325780d89d Mon Sep 17 00:00:00 2001 From: rayangler <27821750+rayangler@users.noreply.github.com> Date: Tue, 11 Mar 2025 15:20:16 -0400 Subject: [PATCH 2/9] Update IDs and ensure v2 latest branch is correct --- .github/scripts/generateSpecMapping.js | 35 ++++++++++++++--------- .github/workflows/generate-bump-pages.yml | 1 + 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/.github/scripts/generateSpecMapping.js b/.github/scripts/generateSpecMapping.js index 5d397bc0c2..9e093af0e4 100644 --- a/.github/scripts/generateSpecMapping.js +++ b/.github/scripts/generateSpecMapping.js @@ -4,31 +4,29 @@ import { fileURLToPath } from 'node:url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -const ATLAS_ADMIN_API_V2_DOC = 'atlas-admin-api-v2'; const SPEC_MAPPING = [ { - doc: 'atlas-admin-api-v1', + doc: 'f929d2d7-27d7-4591-b22f-6c2e543a7874', file: 'openapi/v1-deprecated/v1.json', branch: 'main', }, - // Need to programmatically handle resource versions separately - { - doc: ATLAS_ADMIN_API_V2_DOC, - file: 'openapi/v2.json', - branch: 'latest', - }, ]; /** * Handles the resource versions for Atlas Admin API v2 */ -function handleResourceVersions() { +function handleAdminAPIv2() { + const docId = '2accf4b8-a543-426c-94c3-794ae26b68be'; const directory = 'openapi/v2'; const filePath = path.join(__dirname, `../../${directory}/versions.json`); const versions = JSON.parse(fs.readFileSync(filePath, 'utf8')); - for (const version of versions) { + if (!versions || !Array.isArray(versions)) { + return; + } + + for (const [index, version] of versions.entries()) { const openapiFilename = `openapi-${version}.json`; const openapiFilePath = path.join(path.dirname(filePath), openapiFilename); @@ -36,13 +34,24 @@ function handleResourceVersions() { continue; } + const file = `${directory}/${openapiFilename}`; SPEC_MAPPING.push({ - doc: ATLAS_ADMIN_API_V2_DOC, - file: `${directory}/${openapiFilename}`, + doc: docId, + file, branch: version, }); + + // We want the latest version to have its own version AND be the latest/default branch + if (index === versions.length - 1) { + SPEC_MAPPING.push({ + doc: docId, + file, + branch: 'latest', + }); + } } } -handleResourceVersions(); +handleAdminAPIv2(); +// Output to GH action console.log(JSON.stringify(SPEC_MAPPING)); diff --git a/.github/workflows/generate-bump-pages.yml b/.github/workflows/generate-bump-pages.yml index 1826c96bdb..b652fb9217 100644 --- a/.github/workflows/generate-bump-pages.yml +++ b/.github/workflows/generate-bump-pages.yml @@ -1,6 +1,7 @@ name: Check & deploy API documentation on: + workflow_dispatch: # Allow manual trigger in case of quick fix push: branches: - main From c4492f0f289d57478ecf78837aeb8eef35b5a10a Mon Sep 17 00:00:00 2001 From: rayangler <27821750+rayangler@users.noreply.github.com> Date: Tue, 11 Mar 2025 15:22:04 -0400 Subject: [PATCH 3/9] Fix comments --- .github/scripts/generateSpecMapping.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/scripts/generateSpecMapping.js b/.github/scripts/generateSpecMapping.js index 9e093af0e4..06f3b2d850 100644 --- a/.github/scripts/generateSpecMapping.js +++ b/.github/scripts/generateSpecMapping.js @@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); +// Add new specs to be deployed to Bump here const SPEC_MAPPING = [ { doc: 'f929d2d7-27d7-4591-b22f-6c2e543a7874', @@ -13,9 +14,6 @@ const SPEC_MAPPING = [ }, ]; -/** - * Handles the resource versions for Atlas Admin API v2 - */ function handleAdminAPIv2() { const docId = '2accf4b8-a543-426c-94c3-794ae26b68be'; const directory = 'openapi/v2'; From 25341fa7f932451c79a1a66edb5815605b6b8ee8 Mon Sep 17 00:00:00 2001 From: rayangler <27821750+rayangler@users.noreply.github.com> Date: Tue, 11 Mar 2025 17:39:24 -0400 Subject: [PATCH 4/9] Check for dispatch --- .github/workflows/generate-bump-pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate-bump-pages.yml b/.github/workflows/generate-bump-pages.yml index b652fb9217..c6376894fc 100644 --- a/.github/workflows/generate-bump-pages.yml +++ b/.github/workflows/generate-bump-pages.yml @@ -35,7 +35,7 @@ jobs: deploy-doc: needs: create-matrix - if: ${{ github.event_name == 'push' }} + if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} name: Deploy API documentation on Bump.sh strategy: matrix: From 6e66ccdf00281d5d0b204c58b081c79484e88be4 Mon Sep 17 00:00:00 2001 From: rayangler <27821750+rayangler@users.noreply.github.com> Date: Fri, 14 Mar 2025 17:41:06 -0400 Subject: [PATCH 5/9] Make doc IDs repo variables --- .github/scripts/generateSpecMapping.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/scripts/generateSpecMapping.js b/.github/scripts/generateSpecMapping.js index 06f3b2d850..80823d8405 100644 --- a/.github/scripts/generateSpecMapping.js +++ b/.github/scripts/generateSpecMapping.js @@ -5,17 +5,19 @@ import { fileURLToPath } from 'node:url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -// Add new specs to be deployed to Bump here +// Standalone specs can be added directly to the mapping. Any spec that requires displaying a version dropdown +// will need to map its different versions to a separate Bump "branch". For example, a new resource version +// for Atlas Admin API v2 will lead to a new entry in the array with its own Bump branch. const SPEC_MAPPING = [ { - doc: 'f929d2d7-27d7-4591-b22f-6c2e543a7874', + doc: process.env.ATLAS_ADMIN_V1_DOC_ID, file: 'openapi/v1-deprecated/v1.json', branch: 'main', }, ]; function handleAdminAPIv2() { - const docId = '2accf4b8-a543-426c-94c3-794ae26b68be'; + const docId = process.env.ATLAS_ADMIN_V2_DOC_ID; const directory = 'openapi/v2'; const filePath = path.join(__dirname, `../../${directory}/versions.json`); const versions = JSON.parse(fs.readFileSync(filePath, 'utf8')); From c560d8c989cb2b56784a11267ce63a7d9d9902c8 Mon Sep 17 00:00:00 2001 From: rayangler <27821750+rayangler@users.noreply.github.com> Date: Fri, 14 Mar 2025 17:44:24 -0400 Subject: [PATCH 6/9] Set vars in env --- .github/workflows/generate-bump-pages.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/generate-bump-pages.yml b/.github/workflows/generate-bump-pages.yml index c6376894fc..8430a168bd 100644 --- a/.github/workflows/generate-bump-pages.yml +++ b/.github/workflows/generate-bump-pages.yml @@ -29,6 +29,9 @@ jobs: uses: actions/setup-node@v4 - name: Generate matrix id: set-matrix + env: + ATLAS_ADMIN_V1_DOC_ID: ${{ vars.ATLAS_ADMIN_V1_DOC_ID }} + ATLAS_ADMIN_V2_DOC_ID: ${{ vars.ATLAS_ADMIN_V2_DOC_ID }} run: | spec_mapping=$(node .github/scripts/generateSpecMapping.js) echo "matrix=$spec_mapping" >> "$GITHUB_OUTPUT" From 4ea78589309f7090a708524c9834c17919f38943 Mon Sep 17 00:00:00 2001 From: rayangler <27821750+rayangler@users.noreply.github.com> Date: Mon, 17 Mar 2025 10:03:47 -0400 Subject: [PATCH 7/9] Update GH action SHAs Co-authored-by: Andrea Angiolillo --- .github/workflows/generate-bump-pages.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/generate-bump-pages.yml b/.github/workflows/generate-bump-pages.yml index c6376894fc..4de36947df 100644 --- a/.github/workflows/generate-bump-pages.yml +++ b/.github/workflows/generate-bump-pages.yml @@ -45,7 +45,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Deploy API documentation - uses: bump-sh/github-action@v1 + uses: bump-sh/github-action@690c81156715f37cb72d006e5cbb81fbd9b45365 with: doc: ${{matrix.spec-mapping.doc}} token: ${{secrets.BUMP_TOKEN}} @@ -64,7 +64,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Create API preview - uses: bump-sh/github-action@v1 + uses: bump-sh/github-action@690c81156715f37cb72d006e5cbb81fbd9b45365 with: doc: ${{matrix.spec-mapping.doc}} token: ${{secrets.BUMP_TOKEN}} From 6400e0621cce243e7228be8dcf58bfe15a523746 Mon Sep 17 00:00:00 2001 From: rayangler <27821750+rayangler@users.noreply.github.com> Date: Mon, 17 Mar 2025 16:30:15 -0400 Subject: [PATCH 8/9] Remove automated triggers --- .github/workflows/generate-bump-pages.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/workflows/generate-bump-pages.yml b/.github/workflows/generate-bump-pages.yml index 6fb709c7c7..847363822b 100644 --- a/.github/workflows/generate-bump-pages.yml +++ b/.github/workflows/generate-bump-pages.yml @@ -2,17 +2,6 @@ name: Check & deploy API documentation on: workflow_dispatch: # Allow manual trigger in case of quick fix - push: - branches: - - main - paths: - - 'openapi/**.json' - - pull_request: - branches: - - main - paths: - - 'openapi/**.json' permissions: contents: read From 1b75b08704a5dfaa7c6835ec18baa689b1bc8691 Mon Sep 17 00:00:00 2001 From: rayangler <27821750+rayangler@users.noreply.github.com> Date: Tue, 18 Mar 2025 17:30:25 -0400 Subject: [PATCH 9/9] Add error logs --- .github/scripts/generateSpecMapping.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/scripts/generateSpecMapping.js b/.github/scripts/generateSpecMapping.js index 80823d8405..8c888623a7 100644 --- a/.github/scripts/generateSpecMapping.js +++ b/.github/scripts/generateSpecMapping.js @@ -23,6 +23,7 @@ function handleAdminAPIv2() { const versions = JSON.parse(fs.readFileSync(filePath, 'utf8')); if (!versions || !Array.isArray(versions)) { + console.error(`No versions found for Atlas Admin API v2 at ${filePath}`); return; } @@ -31,6 +32,7 @@ function handleAdminAPIv2() { const openapiFilePath = path.join(path.dirname(filePath), openapiFilename); if (!fs.existsSync(openapiFilePath)) { + console.error(`Could not find resource version "${version}" at ${openapiFilePath}`); continue; }