Skip to content
Open
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
3 changes: 0 additions & 3 deletions .eslintrc.json

This file was deleted.

148 changes: 79 additions & 69 deletions .github/workflows/scripts/wait-for-netlify-deploy.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,101 @@


[
"PR_NUMBER",
"BRANCH_NAME",
"NETLIFY_SITE_ID",
"NETLIFY_TOKEN",
"UPDATED_AT",
"COMMIT_SHA"
"PR_NUMBER",
"BRANCH_NAME",
"NETLIFY_SITE_ID",
"NETLIFY_TOKEN",
"UPDATED_AT",
"COMMIT_SHA",
].forEach((v) => {
if (!(process.env[v])) {
throw new Error(`Env var: '${v}' was not provided`)
}
})
if (!process.env[v]) {
throw new Error(`Env var: '${v}' was not provided`);
}
});
const {
PR_NUMBER,
BRANCH_NAME,
NETLIFY_SITE_ID,
NETLIFY_TOKEN,
UPDATED_AT,
COMMIT_SHA
PR_NUMBER,
BRANCH_NAME,
NETLIFY_SITE_ID,
NETLIFY_TOKEN,
UPDATED_AT,
COMMIT_SHA,
} = process.env;

// Six minutes
const MAX_NUM_TRIES = 120;
const DELAY_TIME_MS = 5000;

async function main() {
let numTries = 0;
while (numTries <= MAX_NUM_TRIES) {
numTries++;
await new Promise((res) => setTimeout(res, DELAY_TIME_MS));
console.info(`Attempt #${numTries}`);

const pageNum = 1;
const result = await fetch(
`https://api.netlify.com/api/v1/sites/${NETLIFY_SITE_ID}/deploys?branch=${BRANCH_NAME}&page=${pageNum}`,
{
headers: {
Authorization: `Bearer ${NETLIFY_TOKEN}`,
},
}
);

if (!result.ok) {
throw new Error(`Result was not ok: ${result.statusText}`);
}

let numTries = 0;
while (numTries <= MAX_NUM_TRIES) {
numTries++;
await new Promise((res) => setTimeout(res, DELAY_TIME_MS))
console.info(`Attempt #${numTries}`);

let pageNum = 1;
const result = await fetch(`https://api.netlify.com/api/v1/sites/${NETLIFY_SITE_ID}/deploys?branch=${BRANCH_NAME}&page=${pageNum}`, {
headers: {
"Authorization": `Bearer ${NETLIFY_TOKEN}`
}
});

if (!result.ok) {
throw new Error(`Result was not ok: ${result.statusText}`)
}

const json = await result.json();

if (json.length === 100) {
throw new Error("Result length was 100, you have there is probably another page of results")
}

const filteredResults = json.filter((v) => v.review_id === parseInt(PR_NUMBER) && v.commit_ref === COMMIT_SHA);
console.info(`Found ${filteredResults.length} results with matching review_id and commit_ref`);


const filteredResults2 = filteredResults.filter((v) => {
return new Date(v.created_at) > new Date(UPDATED_AT);
})

console.info(`Found ${filteredResults2.length} results with matching created_at greater than UPDATED_AT (${UPDATED_AT})`);
const json = await result.json();

if (filteredResults2.length > 1) {
throw new Error(`Expect only one deploy to exist, got ${filteredResults2.length}`)
}
if (json.length === 100) {
throw new Error(
"Result length was 100, you have there is probably another page of results"
);
}

const filteredResults = json.filter(
(v) =>
v.review_id === Number.parseInt(PR_NUMBER) &&
v.commit_ref === COMMIT_SHA
);
console.info(
`Found ${filteredResults.length} results with matching review_id and commit_ref`
);

const filteredResults2 = filteredResults.filter((v) => {
return new Date(v.created_at) > new Date(UPDATED_AT);
});

console.info(
`Found ${filteredResults2.length} results with matching created_at greater than UPDATED_AT (${UPDATED_AT})`
);

if (filteredResults2.length > 1) {
throw new Error(
`Expect only one deploy to exist, got ${filteredResults2.length}`
);
}

if (filteredResults2.length === 0) {
console.info("No matching results, deploy isn't created yet.");
continue;
}
if (filteredResults2.length === 0) {
console.info("No matching results, deploy isn't created yet.");
continue;
}

const singleResult = filteredResults2[0];
const resultStatus = singleResult.state;
const singleResult = filteredResults2[0];
const resultStatus = singleResult.state;

console.info(`Result state is '${resultStatus}'`)
console.info(`Result state is '${resultStatus}'`);

if (resultStatus === "ready") {
console.info(`Deploy URL: ${singleResult.deploy_ssl_url}`)
process.exit(0);
}
if (resultStatus === "ready") {
console.info(`Deploy URL: ${singleResult.deploy_ssl_url}`);
process.exit(0);
}

if (result.status === "error") {
throw new Error("Deploy had an error status")
}
if (result.status === "error") {
throw new Error("Deploy had an error status");
}
}

throw new Error("Maximum retries exceeded.")
throw new Error("Maximum retries exceeded.");
}

main();
main();
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules

/.cache
Expand Down
115 changes: 57 additions & 58 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
{
"cSpell.words": [
"Barfloo",
"blackbox",
"Bloggs",
"brianlow",
"CDKTF",
"codemirror",
"datetimes",
"Deduped",
"devs",
"divs",
"dockerise",
"dockerised",
"Dockerising",
"easymde",
"Foobar",
"Fooby",
"FOUCs",
"frontmatter",
"harfiles",
"importmap",
"interactable",
"jsonplaceholder",
"logmetadata",
"MDE's",
"MITM",
"Mockbin",
"nextjs",
"Oldweb",
"openapi",
"petstore",
"Rehype",
"relitigate",
"Sendgrid",
"statefulness",
"supervisord",
"tanstack",
"testid",
"testids",
"textareas",
"texteditor",
"thunks",
"timezones",
"Todos",
"toolings",
"tsconfigs",
"webp"
],
"cSpell.words": [
"Barfloo",
"blackbox",
"Bloggs",
"brianlow",
"CDKTF",
"codemirror",
"datetimes",
"Deduped",
"devs",
"divs",
"dockerise",
"dockerised",
"Dockerising",
"easymde",
"Foobar",
"Fooby",
"FOUCs",
"frontmatter",
"harfiles",
"importmap",
"interactable",
"jsonplaceholder",
"logmetadata",
"MDE's",
"MITM",
"Mockbin",
"nextjs",
"Oldweb",
"openapi",
"petstore",
"Rehype",
"relitigate",
"Sendgrid",
"statefulness",
"supervisord",
"tanstack",
"testid",
"testids",
"textareas",
"texteditor",
"thunks",
"timezones",
"Todos",
"toolings",
"tsconfigs",
"webp"
],

"[mdx]": {
"editor.defaultFormatter": "unifiedjs.vscode-mdx",
"editor.inlineSuggest.enabled": false,
"editor.quickSuggestions": {
"other": "off",
"comments": "off",
"strings": "off"
}
"[mdx]": {
"editor.defaultFormatter": "unifiedjs.vscode-mdx",
"editor.inlineSuggest.enabled": false,
"editor.quickSuggestions": {
"other": "off",
"comments": "off",
"strings": "off"
}

}
}
}
41 changes: 41 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"a11y": {
"recommended": true
}
}
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2
},
"javascript": {
"formatter": {
"quoteStyle": "double",
"trailingCommas": "es5"
}
},
"files": {
"ignore": [
"node_modules",
".next",
"src/generated",
"public",
"next-env.d.ts",
"tsconfig.tsbuildinfo"
]
}
}
Loading
Loading