diff --git a/.github/workflows/links.yml b/.github/workflows/links.yml index c5764e5cd..2300f2b6f 100644 --- a/.github/workflows/links.yml +++ b/.github/workflows/links.yml @@ -14,11 +14,11 @@ jobs: # RUN SCRIPT TO USE VERCEL PREVIEW LINK FROM PR - name: Update preview link run: node scripts/generate-mlc-config.mjs ${{ github.event.deployment_status.state }} ${{ github.event.deployment_status.environment_url }} - # # RUN SCRIPT TO GENERATE NEW CONFIG WITH VERCEL PREVIEW URL - # # RUN LINK CHECK - # - uses: gaurav-nelson/github-action-markdown-link-check - # with: - # config-file: 'mlc-config.json' - # file-extension: 'mdx' - # # use-verbose-mode: 'yes' - # folder-path: docs/guides/docs + # RUN SCRIPT TO GENERATE NEW CONFIG WITH VERCEL PREVIEW URL + # RUN LINK CHECK + - uses: gaurav-nelson/github-action-markdown-link-check + with: + config-file: 'mlc-config.json' + file-extension: 'mdx' + # use-verbose-mode: 'yes' + folder-path: docs/guides/docs diff --git a/mlc-config.json b/mlc-config.json index 79e50f695..28531f157 100644 --- a/mlc-config.json +++ b/mlc-config.json @@ -26,7 +26,7 @@ "replacementPatterns": [ { "pattern": "^(/)(.*)", - "replacement": "{{VERCEL_PREVIEW}}$2" + "replacement": "{{VERCEL_PREVIEW}}/$2" } ] } diff --git a/scripts/generate-mlc-config.mjs b/scripts/generate-mlc-config.mjs index 7429dd5e4..344636c5f 100644 --- a/scripts/generate-mlc-config.mjs +++ b/scripts/generate-mlc-config.mjs @@ -1,14 +1,20 @@ -// import fs from 'fs'; +import fs from 'fs'; main(); +const configPath = './mlc-config-test.json'; + function main() { - console.log('DEPLOYMENT STATE:', process.argv[2]); - console.log('DEPLOYMENT URL:', process.argv[3]); - // const previewURL = process.argv[2]; - // console.log('PREVIEW URL:', previewURL); - // const configPath = './mlc-config-test.json'; - // const configFile = fs.readFileSync(configPath, 'utf-8'); - // const newContent = configFile.replace('{{VERCEL_PREVIEW}}', previewURL); - // fs.writeFileSync(configPath, newContent); + const deploymentState = process.argv[2]; + console.log('DEPLOYMENT STATE:', deploymentState); + const deploymentURL = process.argv[3]; + console.log('DEPLOYMENT URL:', deploymentURL); + + if (deploymentState === 'success' && deploymentURL) { + const configFile = fs.readFileSync(configPath, 'utf-8'); + const newContent = configFile.replace('{{VERCEL_PREVIEW}}', deploymentURL); + fs.writeFileSync(configPath, newContent); + } else { + throw Error('MISSING VERCEL DEPLOYMENT'); + } }