diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index b38a464aad0..e6b8b6d83dc 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -9,14 +9,16 @@ jobs: steps: - uses: actions/checkout@v5 - - name: Wait for Netlify Deploy + - name: Get Netlify Deploy URL for branch id: netlify_deploy - uses: pettinarip/wait-for-netlify-action@v1.0.2 - with: - site_id: "e8f2e766-888b-4954-8500-1b647d84db99" - max_timeout: 3600 + if: | + github.ref_name == 'dev' || github.ref_name == 'staging' || github.ref_name == 'master' + run: | + npx ts-node -O '{ "module": "commonjs" }' src/scripts/get-netlify-branch-deploy.ts env: + NETLIFY_SITE_ID: "e8f2e766-888b-4954-8500-1b647d84db99" NETLIFY_TOKEN: ${{ secrets.NETLIFY_TOKEN }} + GITHUB_REF_NAME: ${{ github.ref_name }} - uses: actions/setup-node@v4 with: diff --git a/src/scripts/get-netlify-branch-deploy.ts b/src/scripts/get-netlify-branch-deploy.ts new file mode 100644 index 00000000000..8533e2c4bd6 --- /dev/null +++ b/src/scripts/get-netlify-branch-deploy.ts @@ -0,0 +1,50 @@ +// Fetches the latest published Netlify deploy for the current branch and outputs its URL for GitHub Actions +import fs from "fs" + +const siteId = process.env.NETLIFY_SITE_ID +const branch = process.env.GITHUB_REF_NAME +const token = process.env.NETLIFY_TOKEN + +if (!siteId || !branch || !token) { + console.error("Missing NETLIFY_SITE_ID, GITHUB_REF_NAME, or NETLIFY_TOKEN") + process.exit(1) +} + +type NetlifyDeploy = { + state: string + branch: string + published: boolean + deploy_ssl_url?: string + deploy_url?: string +} +;(async () => { + const url = `https://api.netlify.com/api/v1/sites/${siteId}/deploys?branch=${branch}` + const res = await fetch(url, { + headers: { Authorization: `Bearer ${token}` }, + }) + if (!res.ok) { + console.error( + "Failed to fetch Netlify deploys:", + res.status, + await res.text() + ) + process.exit(1) + } + const deploys: NetlifyDeploy[] = await res.json() + // Find the latest published deploy for this branch + const latest = deploys.find( + (d) => d.state === "ready" && d.branch === branch && d.published + ) + if (!latest) { + console.error("No published deploy found for branch:", branch) + process.exit(1) + } + // Use GitHub Actions recommended output syntax (GITHUB_OUTPUT) + const output = `url=${latest.deploy_ssl_url || latest.deploy_url}` + if (process.env.GITHUB_OUTPUT) { + fs.appendFileSync(process.env.GITHUB_OUTPUT, output + "\n") + } else { + // Fallback for local/dev + console.log(output) + } +})()