diff --git a/.github/actions/build-cached-packs/action.yaml b/.github/actions/build-cached-packs/action.yaml index 5ceba44907f..a6a96dc6d30 100644 --- a/.github/actions/build-cached-packs/action.yaml +++ b/.github/actions/build-cached-packs/action.yaml @@ -28,10 +28,8 @@ runs: run: | # Ensure the correct folders exist. mkdir -p .docusaurus/packs-integrations - mkdir -p .docusaurus/plugin-packs-integrations # Move the files to their correct places in the checked out repository mv downloaded_artifacts/.docusaurus/packs-integrations/* .docusaurus/packs-integrations - mv downloaded_artifacts/.docusaurus/plugin-packs-integrations/* .docusaurus/plugin-packs-integrations mkdir -p static/img/packs mv downloaded_artifacts/build/packs/* static/img/packs # Clean up. diff --git a/.github/workflows/post_release.yaml b/.github/workflows/post_release.yaml index cca12dc76c2..d391afde304 100644 --- a/.github/workflows/post_release.yaml +++ b/.github/workflows/post_release.yaml @@ -50,6 +50,5 @@ jobs: path: | build/packs .docusaurus/packs-integrations - .docusaurus/plugin-packs-integrations if-no-files-found: error retention-days: 7 diff --git a/plugins/packs-integrations.js b/plugins/packs-integrations.js index aa263fc1a98..b0f33994e27 100644 --- a/plugins/packs-integrations.js +++ b/plugins/packs-integrations.js @@ -341,23 +341,7 @@ async function mapRepositories(repositories) { return acc; }, []); - open(`${dirname}${repos_filename}`, "w+", (err, fd) => { - if (err) { - logger.error("An error occurred while opening the JSON file:", err); - return; - } - try { - writeFile(`${dirname}${repos_filename}`, JSON.stringify(repoMap), (err1) => { - if (err1) { - logger.error("An error occurred while writing the JSON file:", err1); - } - }); - } finally { - close(fd, (err2) => { - if (err2) logger.error("An error occurred while closing the file:", err2); - }); - } - }); + await writeResponseFile(`${dirname}${repos_filename}`, repoMap); return repoMap; } @@ -420,6 +404,27 @@ async function getLogoUrl(packsAllData, logoUrlMap) { } } +async function writeResponseFile(path, apiResponse) { + open(path, "w+", (err, fd) => { + if (err) { + logger.error("An error occurred while opening the JSON file:", err); + return; + } + try { + writeFile(path, JSON.stringify(apiResponse), (err1) => { + if (err1) { + logger.error("An error occurred while writing the JSON file:", err1); + } + logger.info(`API Response saved to ${path}`); + }); + } finally { + close(fd, (err2) => { + if (err2) logger.error("An error occurred while closing the file:", err2); + }); + } + }); +} + // If the plugin is disabled, then the packs and integrations data will not be fetched. // However, the PDE service packs still need to be loaded. // Otherwise, errors will be thrown when the PDE service packs are accessed. @@ -532,23 +537,7 @@ async function pluginPacksAndIntegrationsData(context, options) { apiPackResponse.apiPacksData = apiPacksData; apiPackResponse.packMDMap = packMDMap; apiPackResponse.logoUrlMap = logoUrlMap; - open(`${dirname}${packs_filename}`, "w+", (err, fd) => { - if (err) { - logger.error("An error occurred while opening the JSON file:", err); - return; - } - try { - writeFile(`${dirname}${packs_filename}`, JSON.stringify(apiPackResponse), (err1) => { - if (err1) { - logger.error("An error occurred while writing the JSON file:", err1); - } - }); - } finally { - close(fd, (err2) => { - if (err2) logger.error("An error occurred while closing the file:", err2); - }); - } - }); + await writeResponseFile(`${dirname}${packs_filename}`, apiPackResponse); } else { try { const data = await promises.readFile(`${dirname}${packs_filename}`); diff --git a/scripts/get-cached-packs.sh b/scripts/get-cached-packs.sh index 6cd4311495b..43cfa9e33cc 100755 --- a/scripts/get-cached-packs.sh +++ b/scripts/get-cached-packs.sh @@ -36,11 +36,9 @@ echo "✅ Cached packs artifact downloaded." # Ensure the correct folders exist. mkdir -p .docusaurus/packs-integrations -mkdir -p .docusaurus/plugin-packs-integrations # Move the files to their correct places in the checked out repository mv downloaded_artifacts/.docusaurus/packs-integrations/* .docusaurus/packs-integrations -mv downloaded_artifacts/.docusaurus/plugin-packs-integrations/* .docusaurus/plugin-packs-integrations mkdir -p static/img/packs mv downloaded_artifacts/build/packs/* static/img/packs