Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
50 changes: 50 additions & 0 deletions src/scripts/get-netlify-branch-deploy.ts
Original file line number Diff line number Diff line change
@@ -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)
}
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback logic may result in an undefined URL. If both deploy_ssl_url and deploy_url are undefined, the output will be url=undefined. Consider adding validation to ensure at least one URL exists before proceeding.

Suggested change
}
}
// Ensure at least one URL exists
if (!latest.deploy_ssl_url && !latest.deploy_url) {
console.error("No deploy URL found for the latest published deploy.")
process.exit(1)
}

Copilot uses AI. Check for mistakes.
// 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")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, interesting

} else {
// Fallback for local/dev
console.log(output)
}
})()