From 4ce696181bcfe6f6ce8e71c571b2bcf37bcc84f1 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 12 Nov 2023 16:27:02 +0800 Subject: [PATCH 1/5] Add release process --- extra/env2arg.js | 20 ++++++++++++ extra/test-docker.ts | 9 ++++++ extra/update-version.ts | 68 +++++++++++++++++++++++++++++++++++++++++ package.json | 3 +- 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 extra/env2arg.js create mode 100644 extra/test-docker.ts create mode 100644 extra/update-version.ts diff --git a/extra/env2arg.js b/extra/env2arg.js new file mode 100644 index 0000000..244fe58 --- /dev/null +++ b/extra/env2arg.js @@ -0,0 +1,20 @@ +#!/usr/bin/env node + +import childProcess from "child_process"; + +let env = process.env; + +let cmd = process.argv[2]; +let args = process.argv.slice(3); +let replacedArgs = []; + +for (let arg of args) { + for (let key in env) { + arg = arg.replaceAll(`$${key}`, env[key]); + } + replacedArgs.push(arg); +} + +let child = childProcess.spawn(cmd, replacedArgs); +child.stdout.pipe(process.stdout); +child.stderr.pipe(process.stderr); diff --git a/extra/test-docker.ts b/extra/test-docker.ts new file mode 100644 index 0000000..b9844fa --- /dev/null +++ b/extra/test-docker.ts @@ -0,0 +1,9 @@ +// Check if docker is running +import { exec } from "child_process"; + +exec("docker ps", (err, stdout, stderr) => { + if (err) { + console.error("Docker is not running. Please start docker and try again."); + process.exit(1); + } +}); diff --git a/extra/update-version.ts b/extra/update-version.ts new file mode 100644 index 0000000..97adfce --- /dev/null +++ b/extra/update-version.ts @@ -0,0 +1,68 @@ +import pkg from "../package.json"; +import childProcess from "child_process"; + +const newVersion = process.env.VERSION; + +console.log("New Version: " + newVersion); + +if (! newVersion) { + console.error("invalid version"); + process.exit(1); +} + +const exists = tagExists(newVersion); + +if (! exists) { + // Process package.json + pkg.version = newVersion; + + // Also update pnpm-lock.yaml + const npm = /^win/.test(process.platform) ? "pnpm.cmd" : "pnpm"; + childProcess.spawnSync(npm, [ "install" ]); + + commit(newVersion); + tag(newVersion); + +} else { + console.log("version exists"); +} + +/** + * Commit updated files + * @param {string} version Version to update to + */ +function commit(version) { + let msg = "Update to " + version; + + let res = childProcess.spawnSync("git", [ "commit", "-m", msg, "-a" ]); + let stdout = res.stdout.toString().trim(); + console.log(stdout); + + if (stdout.includes("no changes added to commit")) { + throw new Error("commit error"); + } +} + +/** + * Create a tag with the specified version + * @param {string} version Tag to create + */ +function tag(version) { + let res = childProcess.spawnSync("git", [ "tag", version ]); + console.log(res.stdout.toString().trim()); +} + +/** + * Check if a tag exists for the specified version + * @param {string} version Version to check + * @returns {boolean} Does the tag already exist + */ +function tagExists(version) { + if (! version) { + throw new Error("invalid version"); + } + + let res = childProcess.spawnSync("git", [ "tag", "-l", version ]); + + return res.stdout.toString().trim() === version; +} diff --git a/package.json b/package.json index 4dce7ca..b0f3139 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,10 @@ "start": "tsx ./backend/index.ts", "dev:backend": "cross-env NODE_ENV=development tsx watch ./backend/index.ts", "dev:frontend": "cross-env NODE_ENV=development vite --host --config ./frontend/vite.config.ts", + "release-final": "tsx ./extra/test-docker.ts && tsx extra/update-version.ts && npm run build:docker", "build:frontend": "vite build --config ./frontend/vite.config.ts", "build:docker-base": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:base -f ./docker/Base.Dockerfile . --push", - "build:docker": "pnpm run build:frontend && docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:latest -t louislam/dockge:1 -t louislam/dockge:1.0.0 --target release -f ./docker/Dockerfile . --push", + "build:docker": "pnpm run build:frontend && node ./extra/env2arg.js docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:latest -t louislam/dockge:1 -t louislam/dockge:$VERSION --target release -f ./docker/Dockerfile . --push", "build:docker-nightly": "pnpm run build:frontend && docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:nightly --target nightly -f ./docker/Dockerfile . --push", "start-docker": "docker run --rm -p 5001:5001 --name dockge louislam/dockge:latest", "mark-as-nightly": "tsx ./extra/mark-as-nightly.ts" From 7f41cc099ce1acbf8d784fd2c69e7c6372eb9607 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 12 Nov 2023 16:29:17 +0800 Subject: [PATCH 2/5] Update --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b0f3139..206d863 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,10 @@ "start": "tsx ./backend/index.ts", "dev:backend": "cross-env NODE_ENV=development tsx watch ./backend/index.ts", "dev:frontend": "cross-env NODE_ENV=development vite --host --config ./frontend/vite.config.ts", - "release-final": "tsx ./extra/test-docker.ts && tsx extra/update-version.ts && npm run build:docker", + "release-final": "tsx ./extra/test-docker.ts && pnpm run build:frontend && tsx extra/update-version.ts && npm run build:docker", "build:frontend": "vite build --config ./frontend/vite.config.ts", "build:docker-base": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:base -f ./docker/Base.Dockerfile . --push", - "build:docker": "pnpm run build:frontend && node ./extra/env2arg.js docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:latest -t louislam/dockge:1 -t louislam/dockge:$VERSION --target release -f ./docker/Dockerfile . --push", + "build:docker": "node ./extra/env2arg.js docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:latest -t louislam/dockge:1 -t louislam/dockge:$VERSION --target release -f ./docker/Dockerfile . --push", "build:docker-nightly": "pnpm run build:frontend && docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:nightly --target nightly -f ./docker/Dockerfile . --push", "start-docker": "docker run --rm -p 5001:5001 --name dockge louislam/dockge:latest", "mark-as-nightly": "tsx ./extra/mark-as-nightly.ts" From dd58a9cbc484229f1fe2945b50f344c27c50e967 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 12 Nov 2023 16:31:38 +0800 Subject: [PATCH 3/5] Update --- extra/update-version.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extra/update-version.ts b/extra/update-version.ts index 97adfce..e62139b 100644 --- a/extra/update-version.ts +++ b/extra/update-version.ts @@ -1,5 +1,6 @@ import pkg from "../package.json"; import childProcess from "child_process"; +import fs from "fs"; const newVersion = process.env.VERSION; @@ -15,6 +16,7 @@ const exists = tagExists(newVersion); if (! exists) { // Process package.json pkg.version = newVersion; + fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n"); // Also update pnpm-lock.yaml const npm = /^win/.test(process.platform) ? "pnpm.cmd" : "pnpm"; From 200ba0ca075b91a223664386b64e13d78a7921cd Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 12 Nov 2023 16:39:21 +0800 Subject: [PATCH 4/5] Update --- extra/update-version.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/extra/update-version.ts b/extra/update-version.ts index e62139b..c3812c7 100644 --- a/extra/update-version.ts +++ b/extra/update-version.ts @@ -17,14 +17,8 @@ if (! exists) { // Process package.json pkg.version = newVersion; fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n"); - - // Also update pnpm-lock.yaml - const npm = /^win/.test(process.platform) ? "pnpm.cmd" : "pnpm"; - childProcess.spawnSync(npm, [ "install" ]); - commit(newVersion); tag(newVersion); - } else { console.log("version exists"); } From 3dca9e735a0d491474c9c58d46cd5b10581434dc Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 12 Nov 2023 16:39:48 +0800 Subject: [PATCH 5/5] Update to 1.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 206d863..4bf7aa2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dockge", - "version": "1.0.0", + "version": "1.0.1", "type": "module", "scripts": { "fmt": "eslint \"**/*.{ts,vue}\" --fix",