build: failover to github if gitlab is unavailable
This commit is contained in:
parent
dc3048d5fd
commit
53df33a216
31
src/build.js
31
src/build.js
|
@ -11,20 +11,51 @@ const { pipeline } = require('stream/promises')
|
||||||
|
|
||||||
const rootPath = join(__dirname, '..')
|
const rootPath = join(__dirname, '..')
|
||||||
const tmpPath = join(rootPath, 'tmp')
|
const tmpPath = join(rootPath, 'tmp')
|
||||||
|
const publicPath = join(rootPath, 'public')
|
||||||
const zipPath = join(tmpPath, 'artifacts.zip')
|
const zipPath = join(tmpPath, 'artifacts.zip')
|
||||||
const artifactsUrl = 'https://gitlab.com/curben/tracking-filter/-/jobs/artifacts/main/download?job=pages'
|
const artifactsUrl = 'https://gitlab.com/curben/tracking-filter/-/jobs/artifacts/main/download?job=pages'
|
||||||
|
const ghMirror = 'https://nightly.link/curbengh/tracking-filter/workflows/pages/main/public.zip'
|
||||||
|
|
||||||
const f = async () => {
|
const f = async () => {
|
||||||
|
let isMirror = false
|
||||||
|
|
||||||
await mkdir(tmpPath, { recursive: true })
|
await mkdir(tmpPath, { recursive: true })
|
||||||
|
|
||||||
console.log(`Downloading artifacts.zip from "${artifactsUrl}"`)
|
console.log(`Downloading artifacts.zip from "${artifactsUrl}"`)
|
||||||
|
try {
|
||||||
await pipeline(
|
await pipeline(
|
||||||
gotStream(artifactsUrl),
|
gotStream(artifactsUrl),
|
||||||
createWriteStream(zipPath)
|
createWriteStream(zipPath)
|
||||||
)
|
)
|
||||||
|
} catch ({ message }) {
|
||||||
|
console.error(JSON.stringify({
|
||||||
|
error: message,
|
||||||
|
link: artifactsUrl
|
||||||
|
}))
|
||||||
|
|
||||||
|
console.log(`Downloading artifacts.zip from "${ghMirror}"`)
|
||||||
|
isMirror = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
await pipeline(
|
||||||
|
gotStream(ghMirror),
|
||||||
|
createWriteStream(zipPath)
|
||||||
|
)
|
||||||
|
} catch ({ message }) {
|
||||||
|
throw new Error(JSON.stringify({
|
||||||
|
error: message,
|
||||||
|
link: ghMirror
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Extracting artifacts.zip...')
|
console.log('Extracting artifacts.zip...')
|
||||||
|
if (isMirror === false) {
|
||||||
await unzip(zipPath, { dir: rootPath })
|
await unzip(zipPath, { dir: rootPath })
|
||||||
|
} else {
|
||||||
|
await mkdir(publicPath, { recursive: true })
|
||||||
|
await unzip(zipPath, { dir: publicPath })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f()
|
f()
|
||||||
|
|
Loading…
Reference in New Issue