-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
executable file
·63 lines (51 loc) · 1.83 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env -S deno run -A
import { readFile } from "node:fs/promises";
import process from "node:process";
import { $ } from "npm:zx";
import * as core from "npm:@actions/core";
import { temporaryFile, temporaryWrite } from "npm:tempy";
import { glob } from "npm:glob";
const path = core.getInput("path");
const source = core.getInput("source");
const latest = core.getBooleanInput("latest");
process.chdir(path);
$.cwd = process.cwd();
const fileList = await glob([".devcontainer/**", "devcontainer-template.json"], { ignore: [".git/**"], dot: true });
const archivePath = temporaryFile();
await $`tar -cvf ${archivePath} ${fileList}`;
const devcontainerTemplate = JSON.parse(
await readFile("devcontainer-template.json", "utf8")
);
const image = core.getInput("image").replace("*", devcontainerTemplate.id);
const annotations = {
$manifest: {
"com.github.package.type": "devcontainer_template",
// "dev.containers.metadata": JSON.stringify(devcontainerTemplate),
"org.opencontainers.image.source": source,
},
[archivePath]: {
"org.opencontainers.image.title": `devcontainer-template-${devcontainerTemplate.id}.tgz`,
},
};
const annotationsPath = await temporaryWrite(JSON.stringify(annotations), {
extension: "json",
});
await $`oras push \
--config /dev/null:application/vnd.devcontainers \
--annotation-file ${annotationsPath} \
${image}:${devcontainerTemplate.version} \
${archivePath}:application/vnd.devcontainers.layer.v1+tar`;
const [major, minor, patch] = devcontainerTemplate.version
.split(".")
.map((x) => parseInt(x));
await $`oras tag \
${image}:${devcontainerTemplate.version} \
${image}:${major}.${minor}`;
await $`oras tag \
${image}:${devcontainerTemplate.version} \
${image}:${major}`;
if (latest) {
await $`oras tag \
${image}:${devcontainerTemplate.version} \
${image}:latest`;
}