mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-31 09:52:24 +00:00
[ci] add CAS-based unstable cache-state deploy flow
This commit is contained in:
1 parent
e9d1885a4e
commit
492bc61a6b
2 files changed
+203
-71
No files matched your search
@@ -5,7 +5,10 @@ function parseArgs(argv) {
|
||||
const args = {
|
||||
input: null,
|
||||
uploadUrl: process.env.DIST_HASH_STATE_UPLOAD_URL ?? '',
|
||||
method: process.env.DIST_HASH_STATE_UPLOAD_METHOD ?? 'PUT'
|
||||
method: process.env.DIST_HASH_STATE_UPLOAD_METHOD ?? 'PUT',
|
||||
ifMatch: process.env.DIST_HASH_STATE_IF_MATCH ?? '',
|
||||
ifVersion: process.env.DIST_HASH_STATE_IF_VERSION ?? '',
|
||||
ifUnmodifiedSince: process.env.DIST_HASH_STATE_IF_UNMODIFIED_SINCE ?? ''
|
||||
};
|
||||
|
||||
for (let i = 0; i < argv.length; i += 1) {
|
||||
@@ -25,8 +28,25 @@ function parseArgs(argv) {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg === '--if-match') {
|
||||
args.ifMatch = argv[i + 1] ?? '';
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg === '--if-version') {
|
||||
args.ifVersion = argv[i + 1] ?? '';
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg === '--if-unmodified-since') {
|
||||
args.ifUnmodifiedSince = argv[i + 1] ?? '';
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
if (arg === '--help' || arg === '-h') {
|
||||
console.log('Usage: node scripts/store-dist-hash-state.mjs --input <hash-state.json> [--upload-url <url>] [--method PUT]');
|
||||
console.log(
|
||||
'Usage: node scripts/store-dist-hash-state.mjs --input <hash-state.json> [--upload-url <url>] [--method PUT] [--if-match <etag>] [--if-version <version>] [--if-unmodified-since <http-date>]'
|
||||
);
|
||||
process.exit(0);
|
||||
}
|
||||
throw new Error(`Unknown argument: ${arg}`);
|
||||
@@ -46,15 +66,33 @@ async function main() {
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
const body = fs.readFileSync(args.input);
|
||||
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-store'
|
||||
};
|
||||
|
||||
if (args.ifMatch) {
|
||||
headers['If-Match'] = args.ifMatch;
|
||||
}
|
||||
if (args.ifVersion) {
|
||||
headers['X-If-Version'] = args.ifVersion;
|
||||
}
|
||||
if (args.ifUnmodifiedSince) {
|
||||
headers['If-Unmodified-Since'] = args.ifUnmodifiedSince;
|
||||
}
|
||||
|
||||
const response = await fetch(args.uploadUrl, {
|
||||
method: args.method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-store'
|
||||
},
|
||||
headers,
|
||||
body
|
||||
});
|
||||
|
||||
if (response.status === 409 || response.status === 412) {
|
||||
const errorText = await response.text();
|
||||
console.error(`CAS_CONFLICT ${response.status}: ${errorText}`);
|
||||
process.exit(3);
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(`Failed to upload hash state (${response.status}): ${errorText}`);
|
||||
|
||||
Reference in new issue
Block a user