From 668dffc2c501ae2af2390faa8c25dab296f2a8d7 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Tue, 22 Mar 2022 16:45:07 +0800 Subject: [PATCH] Simplify final release --- CONTRIBUTING.md | 16 ++++++------ extra/beta/update-version.js | 3 +++ extra/update-version.js | 47 +++--------------------------------- extra/update-wiki-version.js | 43 +++++++++++++++++++++++++++++++++ package.json | 6 ++--- 5 files changed, 61 insertions(+), 54 deletions(-) create mode 100644 extra/update-wiki-version.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c5ae4ff3c..ff47b90b7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -196,14 +196,13 @@ https://github.com/louislam/uptime-kuma/issues?q=sort%3Aupdated-desc ### Release Procedures 1. Draft a release note -1. Make sure the repo is cleared -1. `npm run update-version 1.X.X` -1. `npm run build` -1. `npm run build-docker` -1. `git push` -1. Publish the release note as 1.X.X -1. `npm run upload-artifacts` with env vars VERSION=1.X.X;GITHUB_TOKEN=XXXX -1. SSH to demo site server and update to 1.X.X +2. Make sure the repo is cleared +3. `npm run release-final with env vars: `VERSION` and `GITHUB_TOKEN` +4. Wait until the `Press any key to continue` +5. `git push` +6. Publish the release note as 1.X.X +7. Press any key to continue +8. SSH to demo site server and update to 1.X.X Checking: @@ -216,6 +215,7 @@ Checking: 1. Draft a release note, check "This is a pre-release" 2. Make sure the repo is cleared 3. `npm run release-beta` with env vars: `VERSION` and `GITHUB_TOKEN` +4. Wait until the `Press any key to continue` 5. Publish the release note as 1.X.X-beta.X 6. Press any key to continue diff --git a/extra/beta/update-version.js b/extra/beta/update-version.js index 3023534be..aa75562d1 100644 --- a/extra/beta/update-version.js +++ b/extra/beta/update-version.js @@ -44,6 +44,9 @@ function commit(version) { if (stdout.includes("no changes added to commit")) { throw new Error("commit error"); } + + res = child_process.spawnSync("git", ["push", "origin", "master"]); + console.log(res.stdout.toString().trim()); } function tag(version) { diff --git a/extra/update-version.js b/extra/update-version.js index 0caaa3992..8f3562a5e 100644 --- a/extra/update-version.js +++ b/extra/update-version.js @@ -5,10 +5,8 @@ const util = require("../src/util"); util.polyfill(); -const oldVersion = pkg.version; -const newVersion = process.argv[2]; +const newVersion = process.env.VERSION; -console.log("Old Version: " + oldVersion); console.log("New Version: " + newVersion); if (! newVersion) { @@ -22,17 +20,14 @@ if (! exists) { // Process package.json pkg.version = newVersion; - pkg.scripts.setup = pkg.scripts.setup.replaceAll(oldVersion, newVersion); - pkg.scripts["build-docker"] = pkg.scripts["build-docker"].replaceAll(oldVersion, newVersion); - pkg.scripts["build-docker-alpine"] = pkg.scripts["build-docker-alpine"].replaceAll(oldVersion, newVersion); - pkg.scripts["build-docker-debian"] = pkg.scripts["build-docker-debian"].replaceAll(oldVersion, newVersion); + + // Replace the version: https://regex101.com/r/hmj2Bc/1 + pkg.scripts.setup = pkg.scripts.setup.replace(/(git checkout )([^\s]+)/, `$1${newVersion}`); fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n"); commit(newVersion); tag(newVersion); - updateWiki(oldVersion, newVersion); - } else { console.log("version exists"); } @@ -64,37 +59,3 @@ function tagExists(version) { return res.stdout.toString().trim() === version; } -function updateWiki(oldVersion, newVersion) { - const wikiDir = "./tmp/wiki"; - const howToUpdateFilename = "./tmp/wiki/🆙-How-to-Update.md"; - - safeDelete(wikiDir); - - child_process.spawnSync("git", ["clone", "https://github.com/louislam/uptime-kuma.wiki.git", wikiDir]); - let content = fs.readFileSync(howToUpdateFilename).toString(); - content = content.replaceAll(`git checkout ${oldVersion}`, `git checkout ${newVersion}`); - fs.writeFileSync(howToUpdateFilename, content); - - child_process.spawnSync("git", ["add", "-A"], { - cwd: wikiDir, - }); - - child_process.spawnSync("git", ["commit", "-m", `Update to ${newVersion} from ${oldVersion}`], { - cwd: wikiDir, - }); - - console.log("Pushing to Github"); - child_process.spawnSync("git", ["push"], { - cwd: wikiDir, - }); - - safeDelete(wikiDir); -} - -function safeDelete(dir) { - if (fs.existsSync(dir)) { - fs.rmdirSync(dir, { - recursive: true, - }); - } -} diff --git a/extra/update-wiki-version.js b/extra/update-wiki-version.js new file mode 100644 index 000000000..65b563268 --- /dev/null +++ b/extra/update-wiki-version.js @@ -0,0 +1,43 @@ +import child_process from "child_process"; +import fs from "fs"; + +const newVersion = process.env.VERSION; + +updateWiki(newVersion); + +function updateWiki(newVersion) { + const wikiDir = "./tmp/wiki"; + const howToUpdateFilename = "./tmp/wiki/🆙-How-to-Update.md"; + + safeDelete(wikiDir); + + child_process.spawnSync("git", ["clone", "https://github.com/louislam/uptime-kuma.wiki.git", wikiDir]); + let content = fs.readFileSync(howToUpdateFilename).toString(); + + // Replace the version: https://regex101.com/r/hmj2Bc/1 + content = content.replace(/(git checkout )([^\s]+)/, `$1${newVersion}`); + fs.writeFileSync(howToUpdateFilename, content); + + child_process.spawnSync("git", ["add", "-A"], { + cwd: wikiDir, + }); + + child_process.spawnSync("git", ["commit", "-m", `Update to ${newVersion}`], { + cwd: wikiDir, + }); + + console.log("Pushing to Github"); + child_process.spawnSync("git", ["push"], { + cwd: wikiDir, + }); + + safeDelete(wikiDir); +} + +function safeDelete(dir) { + if (fs.existsSync(dir)) { + fs.rmdirSync(dir, { + recursive: true, + }); + } +} diff --git a/package.json b/package.json index 00928a50a..aac0d58f4 100644 --- a/package.json +++ b/package.json @@ -30,15 +30,14 @@ "build-docker": "npm run build && npm run build-docker-debian && npm run build-docker-alpine", "build-docker-alpine-base": "docker buildx build -f docker/alpine-base.dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:base-alpine . --push", "build-docker-debian-base": "docker buildx build -f docker/debian-base.dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:base-debian . --push", - "build-docker-alpine": "cross-env-shell docker buildx build -f docker/dockerfile-alpine --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:alpine -t louislam/uptime-kuma:1-alpine -t louislam/uptime-kuma:$npm_package_version-alpine --target release . --push", - "build-docker-debian": "cross-env-shell docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma -t louislam/uptime-kuma:1 -t louislam/uptime-kuma:$npm_package_version -t louislam/uptime-kuma:debian -t louislam/uptime-kuma:1-debian -t louislam/uptime-kuma:$npm_package_version-debian --target release . --push", + "build-docker-alpine": "node ./extra/env2arg.js docker buildx build -f docker/dockerfile-alpine --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:alpine -t louislam/uptime-kuma:1-alpine -t louislam/uptime-kuma:$VERSION-alpine --target release . --push", + "build-docker-debian": "node ./extra/env2arg.js docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma -t louislam/uptime-kuma:1 -t louislam/uptime-kuma:$VERSION -t louislam/uptime-kuma:debian -t louislam/uptime-kuma:1-debian -t louislam/uptime-kuma:$VERSION-debian --target release . --push", "build-docker-nightly": "npm run build && docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly --target nightly . --push", "build-docker-nightly-alpine": "docker buildx build -f docker/dockerfile-alpine --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly-alpine --target nightly . --push", "build-docker-nightly-amd64": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push --progress plain", "upload-artifacts": "docker buildx build -f docker/dockerfile --platform linux/amd64 -t louislam/uptime-kuma:upload-artifact --build-arg VERSION --build-arg GITHUB_TOKEN --target upload-artifact . --progress plain", "setup": "git checkout 1.12.1 && npm ci --production && npm run download-dist", "download-dist": "node extra/download-dist.js", - "update-version": "node extra/update-version.js", "mark-as-nightly": "node extra/mark-as-nightly.js", "reset-password": "node extra/reset-password.js", "remove-2fa": "node extra/remove-2fa.js", @@ -52,6 +51,7 @@ "update-language-files-with-base-lang": "cd extra/update-language-files && node index.js %npm_config_base_lang% && eslint ../../src/languages/**.js --fix", "update-language-files": "cd extra/update-language-files && node index.js && eslint ../../src/languages/**.js --fix", "ncu-patch": "npm-check-updates -u -t patch", + "release-final": "node extra/update-version.js && npm run build-docker && node ./extra/press-any-key.js && npm run upload-artifacts && node ./extra/update-wiki-version.js", "release-beta": "node extra/beta/update-version.js && npm run build && node ./extra/env2arg.js docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:$VERSION -t louislam/uptime-kuma:beta . --target release --push && node ./extra/press-any-key.js && npm run upload-artifacts", "git-remove-tag": "git tag -d" },