This repository was archived by the owner on Mar 7, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathdocker-version.ts
More file actions
87 lines (74 loc) · 2.29 KB
/
docker-version.ts
File metadata and controls
87 lines (74 loc) · 2.29 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { resolve } from "path";
import * as packageJson from "../package.json";
import { readFileSync, writeFileSync } from "fs";
import * as envfile from 'envfile';
import { exec } from "child_process";
const determineDockerVersion = (packageVersion: string): string | null => {
const useLatest = false;
const version = packageVersion;
if (!version) {
console.error(`Package version not found in package.json.`);
return null;
}
return version;
// if (version.includes(`-dev`) || !useLatest) {
// } else {
// return `latest`;
// }
};
const getBranch = () => new Promise<string>((resolve, reject) => {
return exec(`git rev-parse --abbrev-ref HEAD`, (err, stdout, _) => {
if (err)
reject(`getBranch Error: ${err}`);
else if (typeof stdout === `string`)
resolve(stdout.trim());
});
});
const writeEnvToFile = (
envVariables: { key: string; value: any }[],
): void => {
// get `.env` from path of current directory
const path = resolve(__dirname, `../.env`);
console.log(`Writing .env:`, path);
try {
const data = readFileSync(path, `utf8`);
const parsedFile = envfile.parse(data);
envVariables.forEach((envVar: { key: string; value: any }) => {
if (envVar.key && envVar.value) {
parsedFile[envVar.key] = envVar.value;
}
});
writeFileSync(path, envfile.stringify(parsedFile));
console.log(`Updated .env: `, parsedFile);
} catch (err) {
if (err) {
console.error(err);
return;
}
}
};
(async function main() {
try {
const version = await determineDockerVersion(packageJson.version);
let branch = await getBranch();
if(branch == `main`){
branch = `latest`;
}
if (!version) {
process.exit();
}
writeEnvToFile([
{
key: `RELEASE_DOCKER_VERSION`,
value: version
},
{
key: `GIT_BRANCH`,
value: branch
},
]);
process.exit();
} catch (e) {
process.exit(1);
}
})();