Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): retry detectChanges on error #9769

Merged
merged 2 commits into from
Dec 28, 2023
Merged
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
47 changes: 35 additions & 12 deletions .github/actions/detect-changes/detectChanges.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,49 @@ const getPrNumber = (githubRef) => {
return prNumber
}

async function getChangedFiles(page = 1) {
async function getChangedFiles(page = 1, retries = 0) {
const prNumber = getPrNumber()

console.log(`Getting changed files for PR ${prNumber} (page ${page})`)
if (retries) {
console.log(
`Retry ${retries}: Getting changed files for PR ${prNumber} (page ${page})`
)
} else {
console.log(`Getting changed files for PR ${prNumber} (page ${page})`)
}

let changedFiles = []

// Query the GitHub API to get the changed files in the PR
const githubToken = process.env.GITHUB_TOKEN
const url = `https://api.github.com/repos/redwoodjs/redwood/pulls/${prNumber}/files?per_page=100&page=${page}`
const resp = await fetch(url, {
headers: {
Authorization: githubToken ? `Bearer ${githubToken}` : undefined,
['X-GitHub-Api-Version']: '2022-11-28',
Accept: 'application/vnd.github+json',
},
})

const json = await resp.json()
const files = json?.map((file) => file.filename) || []
let resp
let files

try {
resp = await fetch(url, {
headers: {
Authorization: githubToken ? `Bearer ${githubToken}` : undefined,
['X-GitHub-Api-Version']: '2022-11-28',
Accept: 'application/vnd.github+json',
},
})

const json = await resp.json()
files = json.map((file) => file.filename) || []
} catch (e) {
if (retries >= 3) {
console.error(e)

console.log()
console.log('Too many retries, giving up.')

return []
} else {
await new Promise((resolve) => setTimeout(resolve, 3000))
getChangedFiles(page, ++retries)
}
}

changedFiles = changedFiles.concat(files)

Expand Down
Loading