Skip to content

Commit

Permalink
chore(ci): retry detectChanges on error, and await result (#9772)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Dec 28, 2023
1 parent 6994bdb commit f454531
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions .github/actions/detect-changes/detectChanges.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { hasCodeChanges } from './cases/code_changes.mjs'
import { rscChanged } from './cases/rsc.mjs'
import { ssrChanged } from './cases/ssr.mjs'

const getPrNumber = (githubRef) => {
const getPrNumber = () => {
// Example GITHUB_REF refs/pull/9544/merge
const result = /refs\/pull\/(\d+)\/merge/g.exec(process.env.GITHUB_REF)

Expand Down Expand Up @@ -48,7 +48,7 @@ async function getChangedFiles(page = 1, retries = 0) {
const githubToken = process.env.GITHUB_TOKEN
const url = `https://api.github.com/repos/redwoodjs/redwood/pulls/${prNumber}/files?per_page=100&page=${page}`
let resp
let files
let files = []

try {
resp = await fetch(url, {
Expand All @@ -59,6 +59,12 @@ async function getChangedFiles(page = 1, retries = 0) {
},
})

if (!resp.ok) {
console.log()
console.error('Response not ok')
console.log('resp', resp)
}

const json = await resp.json()
files = json.map((file) => file.filename) || []
} catch (e) {
Expand All @@ -70,8 +76,8 @@ async function getChangedFiles(page = 1, retries = 0) {

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

Expand Down Expand Up @@ -103,8 +109,8 @@ async function main() {

if (changedFiles.length === 0) {
console.log(
'No changed files found. Something must have gone wrong. Fall back to ' +
'running all tests.'
'No changed files found. Something must have gone wrong. Falling back ' +
'to running all tests.'
)
core.setOutput('onlydocs', false)
core.setOutput('rsc', true)
Expand Down

0 comments on commit f454531

Please sign in to comment.