diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e379616..c38a996 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,3 @@ -# @format - name: "update" on: push: @@ -17,7 +15,9 @@ jobs: uses: actions/checkout@v4 - name: "npm" - run: npm i -g typescript @types/node ts-node + working-directory: ./script + run: yarn install - name: "update" + working-directory: ./script run: npx ts-node ./src/index.ts diff --git a/.gitignore b/.gitignore index 55371e5..20335c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -.vscode \ No newline at end of file +.vscode +.idea \ No newline at end of file diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..69d248e --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,5 @@ +{ + "printWidth": 100, + "trailingComma": "none", + "tabWidth": 4 +} diff --git a/bucket/hello.json b/bucket/hello.json index 83626f7..0caf7da 100644 --- a/bucket/hello.json +++ b/bucket/hello.json @@ -1 +1 @@ -{"name":"hello","repo":"https://github.com/WhirlScript/hello","versions":[{"version":"1.0.0","dependencies":{},"sha1":"0e4e47152263a098a022c466d1a37c23bc5bd331"},{"version":"1.0.1","dependencies":{},"sha1":"ecb96fc983dd6ae016388ce4737ee9bd56dc74f6"},{"version":"1.0.2","dependencies":{},"sha1":"d238d177e9d212eac3a09a03c9c123e5f7ef12d7"}]} \ No newline at end of file +{"name":"hello","repo":"https://github.com/WhirlScript/hello","versions":[{"version":"1.0.0","dependencies":{},"sha1":"0e4e47152263a098a022c466d1a37c23bc5bd331"},{"version":"1.0.1","dependencies":{},"sha1":"ecb96fc983dd6ae016388ce4737ee9bd56dc74f6"}]} \ No newline at end of file diff --git a/script/package.json b/script/package.json new file mode 100644 index 0000000..fbfa848 --- /dev/null +++ b/script/package.json @@ -0,0 +1,11 @@ +{ + "private": true, + "scripts": { + "run": "ts-node ./src/index.ts" + }, + "dependencies": { + "@types/node": "^20.11.19", + "ts-node": "^10.9.2", + "typescript": "^5.3.3" + } +} diff --git a/script/src/githubApi.d.ts b/script/src/githubApi.d.ts new file mode 100644 index 0000000..0a02f36 --- /dev/null +++ b/script/src/githubApi.d.ts @@ -0,0 +1,10 @@ +export declare type GitHubRepoTags = { + "ref": string, + "node_id": string, + "url": string, + "object": { + "sha": string, + "type": string, + "url": string + } +}[]; \ No newline at end of file diff --git a/script/src/index.ts b/script/src/index.ts new file mode 100644 index 0000000..ca13700 --- /dev/null +++ b/script/src/index.ts @@ -0,0 +1,166 @@ +import * as fs from "node:fs"; +import * as path from "node:path"; +import * as cp from "child_process"; +import { GitHubRepoTags } from "./githubApi"; +import { WhirlBucket, WhirlPkgJson } from "./whirlPackage"; + +// check ./bucket dir +const githubUrl = "https://github.com/"; +const githubApiUrl = "https://api.github.com/repos/"; + +if (!fs.existsSync(path.resolve("../bucket/"))) + fs.mkdirSync(path.resolve("../bucket/")); + +const whirlPackageList: any = require(path.resolve("../packages.json")); + +const fetchOption: RequestInit = { + method: "GET", + headers: { + "Accept": "application/vnd.github+json", + "X-GitHub-Api-Version": "2022-11-28", + "User-Agent": "Whirlpkg-Index" + } +}; + +let commitDetails = ""; + +(async () => { + for (let file in whirlPackageList) { + let isNew = true; + let packageInf: WhirlBucket = { + name: file, + repo: whirlPackageList[file], + versions: [] + }; + const currentVersions: { [key: string]: boolean } = {}; + if (fs.existsSync(`../bucket/${file}.json`)) { + isNew = false; + packageInf = JSON.parse(fs.readFileSync(`../bucket/${file}.json`, { encoding: "utf-8" })); + for (const version of packageInf.versions) { + currentVersions[version.version] = version.status == "deprecated"; + } + } + const whirlPackName: string = file; + const whirlPackageRepoURL: string = whirlPackageList[file]; + const whirlPackageGithubPath: string = whirlPackageRepoURL.split(githubUrl)[1]; + + const oldVersionList = packageInf.versions; + packageInf.versions = []; + + const messageHead = `${whirlPackName}${isNew ? " (new!)" : ""}:`; + try { + const tagsReq = await (await fetch(`${githubApiUrl}${whirlPackageGithubPath}/git/refs/tags/`, fetchOption)).json() as GitHubRepoTags; + + const tags: { version: string, sha: string }[] = []; + for (const tagsReqElement of tagsReq) { + tags.push({ version: tagsReqElement.ref.split("refs/tags/")[1], sha: tagsReqElement.object.sha }); + } + + const tasks: { + newVersion: { version: string, sha: string }[], + deprecateVersion: string[] + } = { + newVersion: [], + deprecateVersion: [] + }; + + for (const tag of tags) { + if (currentVersions[tag.version] != undefined) { + currentVersions[tag.version] = true; + continue; + } + + tasks.newVersion.push(tag); + } + + for (const version in currentVersions) { + if (currentVersions[version]) { + continue; + } + tasks.deprecateVersion.push(version); + } + + if (tasks.newVersion.length == 0 && tasks.deprecateVersion.length == 0) { + continue; + } + + for (const tag of tasks.newVersion) { + let whirlpkg: WhirlPkgJson; + const req = await fetch(`${githubUrl}${whirlPackageGithubPath}/raw/${tag.version}/whirlpkg.json`, fetchOption); + try { + whirlpkg = await req.json() as WhirlPkgJson; + } catch { + console.warn(`${messageHead} invalid whirlpkg.json at version ${tag.version}`); + commitDetails += `:rotating_light: ${messageHead} invalid whirlpkg.json at version ${tag.version}\n`; + continue; + } + + if (!whirlpkg.name || !whirlpkg.version || !whirlpkg.author || !whirlpkg.index) { + console.warn(`${messageHead} invalid whirlpkg.json at version ${tag.version}`); + commitDetails += `:rotating_light: ${messageHead} invalid whirlpkg.json at version ${tag.version}\n`; + continue; + } + + packageInf.versions.push({ + dependencies: whirlpkg.dependencies ?? {}, + sha: tag.sha, + version: tag.version + }); + + console.log(`${messageHead} add ${tag.version}`); + commitDetails += `:sparkles: ${messageHead} add ${tag.version}`; + } + + for (const oldVersionListElement of oldVersionList) { + if (tasks.deprecateVersion.indexOf(oldVersionListElement.version)) { + oldVersionListElement.status = "deprecated"; + console.log(`${messageHead} deprecated ${oldVersionListElement.version}`); + commitDetails += `:wastebasket: ${messageHead} deprecated ${oldVersionListElement.version}\n`; + } + packageInf.versions.push(oldVersionListElement); + } + + fs.writeFileSync( + `../bucket/${whirlPackName}.json`, + JSON.stringify(packageInf) + ); + } catch (e) { + console.error(e); + console.warn(`${messageHead} cannot fetch tags.`); + } + } + + if (commitDetails == "") { + console.log("Nothing changed."); + return; + } + + // commit + const commitInf = "Update packages.\n\n" + commitDetails; + cp.execSync("git config user.name \"github-actions[bot]\"", { + cwd: path.resolve("../") + }); + cp.execSync( + "git config user.email \"41898282+github-actions[bot]@users.noreply.github.com\"", { + cwd: path.resolve("../") + } + ); + cp.execSync(`git remote set-url origin git@github.com:WhirlScript/WhirlPKG-index.git"`, { + cwd: path.resolve("../") + }); + cp.execSync("git add .", { + cwd: path.resolve("../") + }); + cp.execSync(`git commit -m "${commitInf}"`, { + cwd: path.resolve("../") + }); + + cp.execSync(`mkdir -p ~/.ssh/`); + cp.execSync(`touch ~/.ssh/id_rsa.pub`); + console.log("Gen ssh pub key"); + cp.execSync(`echo '${process.env["ssh_key"]}' > ~/.ssh/id_rsa`); + console.log("Pushing to repo..."); + cp.execSync(`git push`, { + cwd: path.resolve("../") + }); +})(); \ No newline at end of file diff --git a/script/src/whirlPackage.d.ts b/script/src/whirlPackage.d.ts new file mode 100644 index 0000000..1158695 --- /dev/null +++ b/script/src/whirlPackage.d.ts @@ -0,0 +1,21 @@ +export declare type WhirlPkgJson = { + name: string, + version: string, + author: string, + repo?: string, + license?: string, + index: string, + export?: { [key: string]: string }, + dependencies?: { [key: string]: string }, +} + +export declare type WhirlBucket = { + name: string, + repo: string, + versions: { + version: string, + dependencies: { [key: string]: string }, + sha: string, + status?: "deprecated" + }[], +} \ No newline at end of file diff --git a/script/yarn.lock b/script/yarn.lock new file mode 100644 index 0000000..3144a75 --- /dev/null +++ b/script/yarn.lock @@ -0,0 +1,124 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@cspotcode/source-map-support@^0.8.0": + version "0.8.1" + resolved "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1" + integrity sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw== + dependencies: + "@jridgewell/trace-mapping" "0.3.9" + +"@jridgewell/resolve-uri@^3.0.3": + version "3.1.2" + resolved "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz#7a0ee601f60f99a20c7c7c5ff0c80388c1189bd6" + integrity sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw== + +"@jridgewell/sourcemap-codec@^1.4.10": + version "1.4.15" + resolved "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32" + integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg== + +"@jridgewell/trace-mapping@0.3.9": + version "0.3.9" + resolved "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz#6534fd5933a53ba7cbf3a17615e273a0d1273ff9" + integrity sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ== + dependencies: + "@jridgewell/resolve-uri" "^3.0.3" + "@jridgewell/sourcemap-codec" "^1.4.10" + +"@tsconfig/node10@^1.0.7": + version "1.0.9" + resolved "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz#df4907fc07a886922637b15e02d4cebc4c0021b2" + integrity sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA== + +"@tsconfig/node12@^1.0.7": + version "1.0.11" + resolved "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz#ee3def1f27d9ed66dac6e46a295cffb0152e058d" + integrity sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag== + +"@tsconfig/node14@^1.0.0": + version "1.0.3" + resolved "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz#e4386316284f00b98435bf40f72f75a09dabf6c1" + integrity sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow== + +"@tsconfig/node16@^1.0.2": + version "1.0.4" + resolved "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz#0b92dcc0cc1c81f6f306a381f28e31b1a56536e9" + integrity sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA== + +"@types/node@^20.11.19": + version "20.11.19" + resolved "https://registry.npmjs.org/@types/node/-/node-20.11.19.tgz#b466de054e9cb5b3831bee38938de64ac7f81195" + integrity sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ== + dependencies: + undici-types "~5.26.4" + +acorn-walk@^8.1.1: + version "8.3.2" + resolved "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.2.tgz#7703af9415f1b6db9315d6895503862e231d34aa" + integrity sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A== + +acorn@^8.4.1: + version "8.11.3" + resolved "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz#71e0b14e13a4ec160724b38fb7b0f233b1b81d7a" + integrity sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg== + +arg@^4.1.0: + version "4.1.3" + resolved "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" + integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA== + +create-require@^1.1.0: + version "1.1.1" + resolved "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" + integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== + +diff@^4.0.1: + version "4.0.2" + resolved "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" + integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== + +make-error@^1.1.1: + version "1.3.6" + resolved "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" + integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== + +ts-node@^10.9.2: + version "10.9.2" + resolved "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz#70f021c9e185bccdca820e26dc413805c101c71f" + integrity sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ== + dependencies: + "@cspotcode/source-map-support" "^0.8.0" + "@tsconfig/node10" "^1.0.7" + "@tsconfig/node12" "^1.0.7" + "@tsconfig/node14" "^1.0.0" + "@tsconfig/node16" "^1.0.2" + acorn "^8.4.1" + acorn-walk "^8.1.1" + arg "^4.1.0" + create-require "^1.1.0" + diff "^4.0.1" + make-error "^1.1.1" + v8-compile-cache-lib "^3.0.1" + yn "3.1.1" + +typescript@^5.3.3: + version "5.3.3" + resolved "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37" + integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw== + +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== + +v8-compile-cache-lib@^3.0.1: + version "3.0.1" + resolved "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf" + integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg== + +yn@3.1.1: + version "3.1.1" + resolved "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" + integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index ee5d9ba..0000000 --- a/src/index.ts +++ /dev/null @@ -1,237 +0,0 @@ -/** @format */ - -import fs, { StatsFs } from "node:fs"; -import path from "node:path"; -import cp from "child_process"; - -// check ./bucket dir -const githubURL = "https://github.com/"; -const githubAPIURL = "https://api.github.com/repos/"; - -if (!fs.existsSync(path.resolve("./bucket/"))) - fs.mkdirSync(path.resolve("./bucket/")); -console.log(path.resolve("./bucket/")); - -const wrsPackageList: any = require(path.resolve("./packages.json")); -const wrpBucketFileList: string[] = fs.readdirSync("./bucket/"); - -const fetchOption: RequestInit = { - method: "GET", - headers: { - Accept: "application/vnd.github+json", - "X-GitHub-Api-Version": "2022-11-28", - "User-Agent": "Whirlpkg-Index", - }, -}; - -console.log(wrsPackageList); - -let status: any = { - newPac: { - todo: 0, - finished: 0, - }, - updatePac: { - todo: 0, - finished: 0, - }, -}; - -let noticeList: any = { - update: [], - new: [], - deprecate: [], - failed: [], -}; - -// check whether there is a new package or not -for (let file in wrsPackageList) { - if (fs.existsSync(`./bucket/${file}.json`)) continue; - status.newPac.todo += 1; -} - -for (let file in wrsPackageList) { - if (fs.existsSync(`./bucket/${file}.json`)) continue; - console.log(`New package: ${file}`); - const wrsPackName: string = file; - const wrsPackageRepoURL: string = wrsPackageList[file]; - const wrsPackageGithubPath: string = wrsPackageRepoURL.split(githubURL)[1]; - let packageInf = { - name: wrsPackName, - repo: wrsPackageRepoURL, - versions: [] as any[], - }; - - // request github api - fetch(`${githubAPIURL}${wrsPackageGithubPath}/git/refs/tags/`, fetchOption) - .then(res => res.json()) - .then(data => { - const reqData: any = data; - const latestVersionSha: string = - reqData[reqData.length - 1].object.sha; - - fetch( - `${githubURL}${wrsPackageGithubPath}/raw/${latestVersionSha}/whirlpkg.json` - ) - .then(res => res.json()) - .then(data => { - const reqData: any = data; - - packageInf.versions.push({ - version: reqData.version, - dependencies: reqData.dependencies - ? reqData.dependencies - : {}, - sha1: latestVersionSha, - }); - // write - fs.writeFileSync( - `./bucket/${wrsPackName}.json`, - JSON.stringify(packageInf) - ); - noticeList.new.push( - `${wrsPackName}(new!) ${reqData.version}` - ); - status.newPac.finished += 1; - }); - }); -} - -// check for update -for (let fileName of wrpBucketFileList) { - const filePath = path.join("./bucket", fileName); // bucket/.json - - // read wrs package inf - const wrsPackageInfo: any = require(path.resolve(filePath)); - - const wrsPackageNameInFileName: string = fileName.split(".json")[0]; - const wrsPackageNameInJson: string = wrsPackageInfo.name; - - // package name check: - if (wrsPackageNameInFileName !== wrsPackageNameInJson) continue; - status.updatePac.todo += 1; -} - -for (let fileName of wrpBucketFileList) { - const filePath = path.join("./bucket", fileName); // bucket/.json - - // read wrs package inf - const wrsPackageInfo: any = require(path.resolve(filePath)); - - const wrsPackageNameInFileName: string = fileName.split(".json")[0]; - const wrsPackageNameInJson: string = wrsPackageInfo.name; - - // package name check: - if (wrsPackageNameInFileName !== wrsPackageNameInJson) { - console.warn( - `Package name (${wrsPackageNameInFileName}) != package name defined in ${fileName}(${wrsPackageNameInJson})!` - ); - noticeList.failed.push( - `Package name (${wrsPackageNameInFileName}) != package name defined in ${fileName}(${wrsPackageNameInJson})!` - ); - continue; - } - - const wrsPackageRepoURL: string = wrsPackageInfo.repo; - const wrsPackageGithubPath: string = wrsPackageRepoURL.split(githubURL)[1]; - const wrsPackageVersion: string = - wrsPackageInfo.versions[wrsPackageInfo.versions.length - 1].version; - console.log( - `Checking update for wrs package ${wrsPackageNameInJson}(${wrsPackageVersion})...` - ); - - // fetch github api to check update。 - fetch(`${githubAPIURL}${wrsPackageGithubPath}/git/refs/tags/`, fetchOption) - .then(res => res.json()) - .then(data => { - const reqData: any = data; - const latestVersionSha: string = - reqData[reqData.length - 1].object.sha; - const latestVersion = - reqData[reqData.length - 1].ref.split("refs/tags/")[1]; - - // if localVer == remoreVer,return. - if (wrsPackageVersion === latestVersion) { - console.log("Update skip。"); - status.updatePac.finished += 1; - return; - } - console.log(`Updating ${wrsPackageNameInJson}...`); - // get whirlpkg.json's raw in target repo: - fetch( - `${githubURL}${wrsPackageGithubPath}/raw/${latestVersionSha}/whirlpkg.json` - ) - .then(res => res.json()) - .then(data => { - const reqData: any = data; - - // change bucket/hello.json,then push - let writeData: any = require(path.resolve(filePath)); - writeData.versions.push({ - version: reqData.version, - dependencies: reqData.dependencies - ? reqData.dependencies - : {}, - sha1: latestVersionSha, - }); - - fs.writeFileSync(filePath, JSON.stringify(writeData)); - console.log( - `Updated wrs package${fileName}(${wrsPackageVersion}) to version ${reqData.version}` - ); - noticeList.update.push( - `${fileName}(${wrsPackageVersion}) ${reqData.version}` - ); - status.updatePac.finished += 1; - }); - }); -} - -// commit -function push2repo() { - cp.execSync('git config user.name "github-actions[bot]"'); - cp.execSync( - 'git config user.email "41898282+github-actions[bot]@users.noreply.github.com"' - ); - cp.execSync("git add ."); - let commitInf = "Update packages.\n"; - for (let newPackageNotice of noticeList.new) { - commitInf += newPackageNotice + "\n"; - } - for (let updatePackageNotice of noticeList.update) { - commitInf += updatePackageNotice + "\n"; - } - for (let deprecatePackageNotice of noticeList.deprecate) { - commitInf += deprecatePackageNotice + "\n"; - } - commitInf += noticeList.failed.length === 0 ? "" : "WARNING!"; - for (let failedPackageNotice of noticeList.failed) { - commitInf += failedPackageNotice + "\n"; - } - if (commitInf === "Update packages.\n") return; - try { - cp.execSync(`git commit -m "${commitInf}"`); - } catch (e) { - console.error(e); - return; - } - - cp.execSync(`mkdir -p ~/.ssh/`); - cp.execSync(`touch ~/.ssh/id_rsa.pub`); - cp.execSync(`echo ${process.env["ssh_key"]} > ~/.ssh/id_rsa.pub`); - console.log("Gen ssh pub key"); - console.log("Pushing to repo...");; - cp.execSync(`git push`); -} - -const runTask = setInterval(() => { - if ( - status.newPac.todo <= status.newPac.finished && - status.updatePac.todo <= status.updatePac.finished - ) { - push2repo(); - console.log("Task finished!"); - clearInterval(runTask); - } - console.log(status); -}, 1000);