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
3 changes: 2 additions & 1 deletion .github/actions/wait-e2e-web-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ runs:
result-encoding: string
script: |
const waitForBuild = require(`${process.env.E2E_WAIT_ACTION_PATH}/wait.cjs`)
return await waitForBuild({ github, context, core, runAttempt: Number(process.env.GITHUB_RUN_ATTEMPT) })
const artifact = await waitForBuild({ github, context, core, runAttempt: Number(process.env.GITHUB_RUN_ATTEMPT) })
return artifact.id
71 changes: 29 additions & 42 deletions .github/actions/wait-e2e-web-build/download.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,13 @@ async function downloadWebBuild({
timeout,
maxBuffer: 32 * 1024 * 1024,
})
const api = async (endpoint, paginate = false) => {
const { stdout } = await run('gh', [
'api',
endpoint,
...(paginate ? ['--paginate', '--slurp'] : []),
])
const list = async (endpoint) => {
const { stdout } = await run('gh', ['api', endpoint, '--paginate', '--slurp'])
return JSON.parse(stdout)
}
// An artifact can be listed for the run before its own endpoint and download are
// readable (seen as a 404 right after upload), so retry those reads briefly.
const withRetry = async (operation) => {
for (let attempt = 1; ; attempt++) {
try {
return await operation()
} catch (error) {
if (attempt >= 3) throw error
console.log(`Web build artifact not readable yet (attempt ${attempt}): ${error.message}`)
await sleep(attempt * 5_000)
}
}
}
const prefix = `repos/${repository}/actions`
let summary = ''
const artifactId = await waitForBuild({
const artifact = await waitForBuild({
github: {
rest: {
actions: { listJobsForWorkflowRunAttempt: 'jobs', listWorkflowRunArtifacts: 'artifacts' },
Expand All @@ -68,7 +51,7 @@ async function downloadWebBuild({
kind === 'jobs'
? `${prefix}/runs/${runId}/attempts/${runAttempt}/jobs?per_page=100`
: `${prefix}/runs/${runId}/artifacts?per_page=100`
const pages = await api(endpoint, true)
const pages = await list(endpoint)
return pages.flatMap((page) => page[kind])
},
},
Expand All @@ -92,30 +75,34 @@ async function downloadWebBuild({
runAttempt,
})

const artifact = await withRetry(() => api(`${prefix}/artifacts/${artifactId}`))
const directory = await mkdtemp(path.join(os.tmpdir(), 'dify-e2e-web-build-'))
try {
// Artifact names are immutable within a run. Use the name selected by wait.cjs,
// including its matching upload timestamp when only consumer jobs are rerun.
await withRetry(() =>
run(
'gh',
[
'run',
'download',
runId,
'--repo',
repository,
'--name',
artifact.name,
'--dir',
directory,
],
300_000,
),
)
// The run's artifact list already provides the immutable name. The separate
// metadata endpoint can return 404 after the artifact has appeared in that list.
// The archive can also take a moment to become readable after upload.
const downloadArgs = [
'run',
'download',
runId,
'--repo',
repository,
'--name',
artifact.name,
'--dir',
directory,
]
for (let attempt = 1; ; attempt++) {
try {
await run('gh', downloadArgs, 300_000)
break
} catch (error) {
if (attempt >= 3) throw error
console.log(`Web build artifact not readable yet (attempt ${attempt}): ${error.message}`)
await sleep(attempt * 5_000)
}
}
await run('tar', ['-xf', path.join(directory, 'e2e-web-build.tar'), '-C', webDir])
console.log(`Web build artifact ${artifactId} extracted and ready.`)
console.log(`Web build artifact ${artifact.id} extracted and ready.`)
} finally {
await rm(directory, { force: true, recursive: true })
}
Expand Down
36 changes: 20 additions & 16 deletions .github/actions/wait-e2e-web-build/download.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@ const { access } = require('node:fs/promises')
const { test } = require('node:test')
const downloadWebBuild = require('./download.cjs')

function fixture({
downloadFails = false,
producerFails = false,
artifactMissingOnce = false,
} = {}) {
function fixture({ downloadFailures = 0, producerFails = false } = {}) {
const calls = []
const sleeps = []
let artifactLookups = 0
const env = {
GITHUB_REPOSITORY: 'owner/repo',
GITHUB_RUN_ID: '123',
Expand All @@ -21,7 +16,10 @@ function fixture({
calls.push({ command, args })
if (command === 'tar') return { stdout: '' }
if (args[0] === 'run') {
if (downloadFails) throw new Error('artifact download failed')
if (downloadFailures > 0) {
downloadFailures--
throw new Error('artifact download failed')
}
return { stdout: '' }
}
if (args[1].includes('/jobs?')) {
Expand Down Expand Up @@ -64,20 +62,25 @@ function fixture({
]),
}
}
assert.equal(args[1], 'repos/owner/repo/actions/artifacts/42')
artifactLookups++
if (artifactMissingOnce && artifactLookups === 1) throw new Error('gh: Not Found (HTTP 404)')
return { stdout: JSON.stringify({ name: 'core-e2e-web-build-2' }) }
throw new Error(`Unexpected command: ${command} ${args.join(' ')}`)
}
const sleep = async (ms) => {
sleeps.push(ms)
}
return { calls, sleeps, options: { env, execute, webDir: '/test/web', sleep } }
}

test('downloads the producer-selected artifact on consumer-only reruns, including paginated results', async () => {
test('downloads the producer-selected artifact on consumer-only reruns without a second metadata lookup', async () => {
const { calls, options } = fixture()
await downloadWebBuild(options)
await downloadWebBuild({
...options,
async execute(command, args) {
if (args[0] === 'api' && args[1].endsWith('/artifacts/42')) {
throw new Error('gh: Not Found (HTTP 404)')
}
return options.execute(command, args)
},
})
assert.match(calls[0].args[1], /runs\/123\/attempts\/4\/jobs/)
const download = calls.find(({ args }) => args[0] === 'run')
assert.deepEqual(download.args.slice(0, 7), [
Expand All @@ -95,15 +98,16 @@ test('downloads the producer-selected artifact on consumer-only reruns, includin
await assert.rejects(access(download.args.at(-1)), { code: 'ENOENT' })
})

test('retries an artifact that is listed before its endpoint is readable', async () => {
const { calls, sleeps, options } = fixture({ artifactMissingOnce: true })
test('retries a listed artifact whose archive is temporarily unreadable', async () => {
const { calls, sleeps, options } = fixture({ downloadFailures: 1 })
await downloadWebBuild(options)
assert.deepEqual(sleeps, [5_000])
assert.equal(calls.filter(({ args }) => args[0] === 'run').length, 2)
assert.equal(calls.at(-1).command, 'tar')
})

test('does not extract a failed download and removes its temporary directory', async () => {
const { calls, sleeps, options } = fixture({ downloadFails: true })
const { calls, sleeps, options } = fixture({ downloadFailures: 3 })
await assert.rejects(downloadWebBuild(options), /artifact download failed/)
assert.deepEqual(sleeps, [5_000, 10_000])
assert.equal(calls.filter(({ args }) => args[0] === 'run').length, 3)
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/wait-e2e-web-build/wait.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = async function waitForBuild({
.addHeading('E2E Web build wait')
.addRaw(`Artifact wait: ${seconds}s`)
.write()
return String(artifact.id)
return { id: String(artifact.id), name: artifact.name }
}
}

Expand Down
12 changes: 6 additions & 6 deletions .github/actions/wait-e2e-web-build/wait.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const successfulProducer = {

test('starts consuming the current artifact without waiting for producer cache saves', async () => {
const { options, calls } = fixture({ artifacts: (elapsed) => (elapsed ? [artifact] : []) })
assert.equal(await waitForBuild(options), '42')
assert.deepEqual(await waitForBuild(options), { id: '42', name: 'core-e2e-web-build-2' })
assert.equal(options.now(), 10000)
assert.deepEqual(
calls.map((call) => call.endpoint),
Expand All @@ -91,7 +91,7 @@ test('full reruns ignore the old artifact until the rebuilding producer publishe
const { options } = fixture({
artifacts: (elapsed) => (elapsed ? [oldArtifact, artifact] : [oldArtifact]),
})
assert.equal(await waitForBuild(options), '42')
assert.equal((await waitForBuild(options)).id, '42')
assert.equal(options.now(), 10000)
})

Expand All @@ -109,7 +109,7 @@ test('consumer-only reruns reuse the actual successful upload despite a relabele
artifacts: [oldArtifact, artifact],
jobs: [{ ...successfulProducer, run_attempt: 4 }],
})
assert.equal(await waitForBuild(options), '42')
assert.deepEqual(await waitForBuild(options), { id: '42', name: 'core-e2e-web-build-2' })
assert.equal(options.now(), 0)
})

Expand Down Expand Up @@ -137,15 +137,15 @@ test('ignores unrelated and expired artifacts and stops at the deadline', async

test('completed rebuilt producers select their upload instead of the old artifact', async () => {
const { options } = fixture({ artifacts: [oldArtifact, artifact], jobs: [successfulProducer] })
assert.equal(await waitForBuild(options), '42')
assert.equal((await waitForBuild(options)).id, '42')
})

test('allows artifact visibility to catch up after a successful producer finishes', async () => {
const { options } = fixture({
artifacts: (elapsed) => (elapsed ? [oldArtifact, artifact] : [oldArtifact]),
jobs: [successfulProducer],
})
assert.equal(await waitForBuild(options), '42')
assert.equal((await waitForBuild(options)).id, '42')
assert.equal(options.now(), 10000)
})

Expand Down Expand Up @@ -185,5 +185,5 @@ test('finds the upload when GitHub skews the upload step timestamps off the arti
},
],
})
assert.equal(await waitForBuild(options), '42')
assert.equal((await waitForBuild(options)).id, '42')
})
6 changes: 2 additions & 4 deletions .github/workflows/web-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,10 @@ jobs:
if: ${{ !cancelled() }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: e2e-logs-chromium-${{ matrix.shard }}
name: e2e-logs-chromium-${{ matrix.shard }}-attempt-${{ github.run_attempt }}
path: e2e/.logs/*.log
if-no-files-found: ignore
include-hidden-files: true
overwrite: true
retention-days: 7

webkit-smoke:
Expand Down Expand Up @@ -244,11 +243,10 @@ jobs:
if: ${{ !cancelled() }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: e2e-logs-webkit
name: e2e-logs-webkit-attempt-${{ github.run_attempt }}
path: e2e/.logs/*.log
if-no-files-found: ignore
include-hidden-files: true
overwrite: true
retention-days: 7

external-runtime:
Expand Down