mirror of
https://github.com/actions/checkout.git
synced 2026-07-19 04:30:04 +08:00
move to using sha uploads
This commit is contained in:
parent
8879f31369
commit
7484b46911
5 changed files with 460 additions and 520 deletions
|
|
@ -1,29 +1,20 @@
|
|||
/* eslint-disable i18n-text/no-en -- log/error strings are English by upstream convention */
|
||||
/* eslint-disable i18n-text/no-en -- upstream convention */
|
||||
import * as core from '@actions/core'
|
||||
|
||||
// Thin client for backend-core's /api/v1/git-mirrors endpoints.
|
||||
//
|
||||
// Auth is the runner verification token every WarpBuild job carries in its env
|
||||
// (WARPBUILD_RUNNER_VERIFICATION_TOKEN); the backend resolves instance → org from the
|
||||
// token alone.
|
||||
//
|
||||
// HTTP contract (mirrors internal/runners/internal/git_mirror_service.go):
|
||||
// 200 -> use the presigned URL
|
||||
// 404 -> cache miss: create the mirror (download from GitHub + tar + upload)
|
||||
// 403 -> feature disabled for this org (backend-driven kill switch): skip mirror
|
||||
// creation and upload entirely, behave exactly like stock actions/checkout
|
||||
// else -> transient trouble: fall back WITHOUT the mirror download
|
||||
// Client for backend-core's /api/v1/git-mirrors endpoints, authed by the runner
|
||||
// verification token. Contract: 200 = presigned URL; 404 = miss (upload after the
|
||||
// stock fetch); 403 = unservable org (skip cache + upload); else = fall back.
|
||||
|
||||
const API_TIMEOUT_MS = 10_000
|
||||
|
||||
export interface MirrorDownloadInfo {
|
||||
export interface SnapshotDownloadInfo {
|
||||
url: string
|
||||
size_bytes: number
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export type MirrorLookup =
|
||||
| {kind: 'hit'; info: MirrorDownloadInfo}
|
||||
export type SnapshotLookup =
|
||||
| {kind: 'hit'; info: SnapshotDownloadInfo}
|
||||
| {kind: 'miss'}
|
||||
| {kind: 'disabled'}
|
||||
| {kind: 'error'}
|
||||
|
|
@ -41,35 +32,41 @@ function authHeader(): string {
|
|||
return `Bearer ${process.env['WARPBUILD_RUNNER_VERIFICATION_TOKEN'] || ''}`
|
||||
}
|
||||
|
||||
export async function lookupMirror(repoKey: string): Promise<MirrorLookup> {
|
||||
export async function lookupSnapshot(
|
||||
repoKey: string,
|
||||
sha: string
|
||||
): Promise<SnapshotLookup> {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${baseUrl()}/api/v1/git-mirrors/download-url?repo_key=${encodeURIComponent(repoKey)}`,
|
||||
`${baseUrl()}/api/v1/git-mirrors/download-url?repo_key=${encodeURIComponent(
|
||||
repoKey
|
||||
)}&sha=${encodeURIComponent(sha)}`,
|
||||
{
|
||||
headers: {authorization: authHeader()},
|
||||
signal: AbortSignal.timeout(API_TIMEOUT_MS)
|
||||
}
|
||||
)
|
||||
if (res.status === 200) {
|
||||
return {kind: 'hit', info: (await res.json()) as MirrorDownloadInfo}
|
||||
return {kind: 'hit', info: (await res.json()) as SnapshotDownloadInfo}
|
||||
}
|
||||
if (res.status === 404) {
|
||||
return {kind: 'miss'}
|
||||
}
|
||||
if (res.status === 403) {
|
||||
core.debug(`[wb-mirror] download-url answered 403 (disabled)`)
|
||||
core.debug(`[wb-cache] download-url answered 403 (disabled)`)
|
||||
return {kind: 'disabled'}
|
||||
}
|
||||
core.debug(`[wb-mirror] download-url answered ${res.status}`)
|
||||
core.debug(`[wb-cache] download-url answered ${res.status}`)
|
||||
return {kind: 'error'}
|
||||
} catch (error) {
|
||||
core.debug(`[wb-mirror] download-url failed: ${error}`)
|
||||
core.debug(`[wb-cache] download-url failed: ${error}`)
|
||||
return {kind: 'error'}
|
||||
}
|
||||
}
|
||||
|
||||
export async function requestUploadURL(
|
||||
repoKey: string
|
||||
repoKey: string,
|
||||
sha: string
|
||||
): Promise<UploadURLResult> {
|
||||
try {
|
||||
const res = await fetch(`${baseUrl()}/api/v1/git-mirrors/upload-url`, {
|
||||
|
|
@ -78,7 +75,7 @@ export async function requestUploadURL(
|
|||
authorization: authHeader(),
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({repo_key: repoKey}),
|
||||
body: JSON.stringify({repo_key: repoKey, sha}),
|
||||
signal: AbortSignal.timeout(API_TIMEOUT_MS)
|
||||
})
|
||||
if (res.status === 200) {
|
||||
|
|
@ -89,13 +86,13 @@ export async function requestUploadURL(
|
|||
return {kind: 'error'}
|
||||
}
|
||||
if (res.status === 403) {
|
||||
core.debug(`[wb-mirror] upload-url answered 403 (disabled)`)
|
||||
core.debug(`[wb-cache] upload-url answered 403 (disabled)`)
|
||||
return {kind: 'disabled'}
|
||||
}
|
||||
core.debug(`[wb-mirror] upload-url answered ${res.status}`)
|
||||
core.debug(`[wb-cache] upload-url answered ${res.status}`)
|
||||
return {kind: 'error'}
|
||||
} catch (error) {
|
||||
core.debug(`[wb-mirror] upload-url failed: ${error}`)
|
||||
core.debug(`[wb-cache] upload-url failed: ${error}`)
|
||||
return {kind: 'error'}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue