From 0254e72177382dff5e02b9632abf9ef1aa48ca45 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Tue, 29 Oct 2024 22:10:05 +0800 Subject: [PATCH] Fix: Upload Artifact issue (#5271) --- extra/release/beta.mjs | 2 +- extra/release/final.mjs | 2 +- extra/release/lib.mjs | 37 +++++++++++++++++++++++-- extra/release/upload-artifacts-beta.mjs | 6 ++++ extra/release/upload-artifacts.mjs | 6 ++++ package.json | 3 +- 6 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 extra/release/upload-artifacts-beta.mjs create mode 100644 extra/release/upload-artifacts.mjs diff --git a/extra/release/beta.mjs b/extra/release/beta.mjs index a2c9809f..ec3be7c6 100644 --- a/extra/release/beta.mjs +++ b/extra/release/beta.mjs @@ -62,4 +62,4 @@ buildImage(repoName, [ "beta", version ], "release"); await pressAnyKey(); // npm run upload-artifacts -uploadArtifacts(); +uploadArtifacts(version, githubToken); diff --git a/extra/release/final.mjs b/extra/release/final.mjs index d190ac0b..b4435064 100644 --- a/extra/release/final.mjs +++ b/extra/release/final.mjs @@ -51,7 +51,7 @@ buildImage(repoName, [ "next", "2", version ], "release"); await pressAnyKey(); // npm run upload-artifacts -uploadArtifacts(); +uploadArtifacts(version, githubToken); // node extra/update-wiki-version.js execSync("node extra/update-wiki-version.js"); diff --git a/extra/release/lib.mjs b/extra/release/lib.mjs index d6c294c1..49391900 100644 --- a/extra/release/lib.mjs +++ b/extra/release/lib.mjs @@ -171,10 +171,43 @@ export function ver(version, identifier) { /** * Upload artifacts to GitHub + * 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 + * @param {string} version Version + * @param {string} githubToken GitHub token * @returns {void} */ -export function uploadArtifacts() { - execSync("npm run upload-artifacts"); +export function uploadArtifacts(version, githubToken) { + let args = [ + "buildx", + "build", + "-f", + "docker/dockerfile", + "--platform", + "linux/amd64", + "-t", + "louislam/uptime-kuma:upload-artifact", + "--build-arg", + `VERSION=${version}`, + "--build-arg", + "GITHUB_TOKEN", + "--target", + "upload-artifact", + ".", + "--progress", + "plain", + ]; + + if (!dryRun) { + childProcess.spawnSync("docker", args, { + stdio: "inherit", + env: { + ...process.env, + GITHUB_TOKEN: githubToken, + }, + }); + } else { + console.log(`[DRY RUN] docker ${args.join(" ")}`); + } } /** diff --git a/extra/release/upload-artifacts-beta.mjs b/extra/release/upload-artifacts-beta.mjs new file mode 100644 index 00000000..2897097e --- /dev/null +++ b/extra/release/upload-artifacts-beta.mjs @@ -0,0 +1,6 @@ +import { uploadArtifacts } from "./lib.mjs"; + +const version = process.env.RELEASE_BETA_VERSION; +const githubToken = process.env.RELEASE_GITHUB_TOKEN; + +uploadArtifacts(version, githubToken); diff --git a/extra/release/upload-artifacts.mjs b/extra/release/upload-artifacts.mjs new file mode 100644 index 00000000..cd34bd7d --- /dev/null +++ b/extra/release/upload-artifacts.mjs @@ -0,0 +1,6 @@ +import { uploadArtifacts } from "./lib.mjs"; + +const version = process.env.RELEASE_VERSION; +const githubToken = process.env.RELEASE_GITHUB_TOKEN; + +uploadArtifacts(version, githubToken); diff --git a/package.json b/package.json index 2394b09f..4f8eef13 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "build-docker-builder-go": "docker buildx build -f docker/builder-go.dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:builder-go . --push", "build-docker-nightly-local": "npm run build && docker build -f docker/dockerfile -t louislam/uptime-kuma:nightly2 --target nightly .", "build-docker-pr-test": "docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64 -t louislam/uptime-kuma:pr-test2 --target pr-test2 . --push", - "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", + "upload-artifacts": "node extra/release/upload-artifacts.mjs", + "upload-artifacts-beta": "node extra/release/upload-artifacts-beta.mjs", "setup": "git checkout 1.23.15 && npm ci --production && npm run download-dist", "download-dist": "node extra/download-dist.js", "mark-as-nightly": "node extra/mark-as-nightly.js",