From 50970f462a7643e522fd4fed7d96bd72de096b74 Mon Sep 17 00:00:00 2001 From: bohan Date: Mon, 13 Nov 2023 21:58:48 +0800 Subject: [PATCH] chore: upload repo info --- .github/workflows/upload.yaml | 32 +++++ packages/babel-loader@9/package.json | 3 + packages/copy-webpack-plugin@5/package.json | 3 + .../package.json | 3 + .../package.json | 3 + packages/html-webpack-plugin@5/package.json | 3 + .../webpack-bundle-analyzer@4/package.json | 3 + packages/webpack-stats-plugin@1/package.json | 3 + scripts/upload.js | 120 ++++++++++++++++++ 9 files changed, 173 insertions(+) create mode 100644 .github/workflows/upload.yaml create mode 100644 scripts/upload.js diff --git a/.github/workflows/upload.yaml b/.github/workflows/upload.yaml new file mode 100644 index 0000000..cac9a66 --- /dev/null +++ b/.github/workflows/upload.yaml @@ -0,0 +1,32 @@ +name: Upload file +on: + pull_request: + branches: [main] + # push: + # branches: + # - main + +jobs: + upload: + name: Build And Upload + runs-on: "ubuntu-latest" + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup git user + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git checkout data + - name: Generate files + run: node scripts/upload.js ${{ secrets.GITHUB_TOKEN }} + - name: ls + run: ls -alh + - name: store + run: | + git add . + git commit -m 'upload files' + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/packages/babel-loader@9/package.json b/packages/babel-loader@9/package.json index bc287ab..ada105a 100644 --- a/packages/babel-loader@9/package.json +++ b/packages/babel-loader@9/package.json @@ -7,5 +7,8 @@ "@rspack/cli": "0.3.11", "babel-loader": "^9.1.3", "@babel/preset-typescript": "^7.23.2" + }, + "rspack": { + "version": ">=0.3.11" } } \ No newline at end of file diff --git a/packages/copy-webpack-plugin@5/package.json b/packages/copy-webpack-plugin@5/package.json index 308c23e..d8b7730 100644 --- a/packages/copy-webpack-plugin@5/package.json +++ b/packages/copy-webpack-plugin@5/package.json @@ -6,5 +6,8 @@ "devDependencies": { "@rspack/cli": "0.3.11", "copy-webpack-plugin": "^5.1.2" + }, + "rspack": { + "version": ">=0.3.11" } } \ No newline at end of file diff --git a/packages/fork-ts-checker-webpack-plugin@8/package.json b/packages/fork-ts-checker-webpack-plugin@8/package.json index c87bf84..ca84924 100644 --- a/packages/fork-ts-checker-webpack-plugin@8/package.json +++ b/packages/fork-ts-checker-webpack-plugin@8/package.json @@ -6,5 +6,8 @@ "devDependencies": { "@rspack/cli": "0.3.11", "fork-ts-checker-webpack-plugin": "^8.0.0" + }, + "rspack": { + "version": ">=0.3.11" } } \ No newline at end of file diff --git a/packages/generate-package-json-webpack-plugin@2/package.json b/packages/generate-package-json-webpack-plugin@2/package.json index 6e38416..5d009a1 100644 --- a/packages/generate-package-json-webpack-plugin@2/package.json +++ b/packages/generate-package-json-webpack-plugin@2/package.json @@ -6,5 +6,8 @@ "devDependencies": { "@rspack/cli": "0.3.11", "generate-package-json-webpack-plugin": "^2.6.0" + }, + "rspack": { + "version": ">=0.3.11" } } \ No newline at end of file diff --git a/packages/html-webpack-plugin@5/package.json b/packages/html-webpack-plugin@5/package.json index 2c49300..5ab74f3 100644 --- a/packages/html-webpack-plugin@5/package.json +++ b/packages/html-webpack-plugin@5/package.json @@ -6,5 +6,8 @@ "devDependencies": { "@rspack/cli": "0.3.11", "html-webpack-plugin": "^5.5.3" + }, + "rspack": { + "version": ">=0.3.11" } } \ No newline at end of file diff --git a/packages/webpack-bundle-analyzer@4/package.json b/packages/webpack-bundle-analyzer@4/package.json index bd7e901..d3bdc72 100644 --- a/packages/webpack-bundle-analyzer@4/package.json +++ b/packages/webpack-bundle-analyzer@4/package.json @@ -6,5 +6,8 @@ "devDependencies": { "@rspack/cli": "0.3.11", "webpack-bundle-analyzer": "^4.9.1" + }, + "rspack": { + "version": ">=0.3.11" } } \ No newline at end of file diff --git a/packages/webpack-stats-plugin@1/package.json b/packages/webpack-stats-plugin@1/package.json index 0a107b9..9424451 100644 --- a/packages/webpack-stats-plugin@1/package.json +++ b/packages/webpack-stats-plugin@1/package.json @@ -6,5 +6,8 @@ "devDependencies": { "@rspack/cli": "0.3.11", "webpack-stats-plugin": "^1.1.3" + }, + "rspack": { + "version": ">=0.3.11" } } \ No newline at end of file diff --git a/scripts/upload.js b/scripts/upload.js new file mode 100644 index 0000000..5a26afa --- /dev/null +++ b/scripts/upload.js @@ -0,0 +1,120 @@ +const path = require('path'); +const fs = require('fs/promises'); +const fsSync = require('fs'); +const assert = require('assert'); +const { spawn } = require('child_process') + +async function runCommand( + command, + args, + { verbose = true, env, onData } = {} +) { + const hasOnData = typeof onData === "function"; + const stdio = verbose ? "inherit" : "ignore"; + const p = spawn(command, args, { + shell: true, + stdio: [stdio, hasOnData ? "pipe" : stdio, "inherit"], + env: env + ? { + ...process.env, + ...env + } + : undefined + }); + if (hasOnData) { + p.stdout.on("data", onData); + } + + const exitCode = await new Promise(resolve => p.once("exit", resolve)); + if (exitCode !== 0) + throw new Error(`${command} ${args.join(" ")} failed with ${exitCode}`); +} + +function ok(value) { + assert(value) +} + + +const root = path.resolve(__dirname, '..'); +const dataDir = path.resolve(root, '.data'); + +/** + * @param {string} name + * @returns {[string, string]} + */ +function splitPackageName(name) { + return name.split('@') +} + +/** + * @param {string} dir + */ +async function readCompat(dir) { + const list = await fs.readdir(dir); + return list.map(item => { + const [name, version] = splitPackageName(item); + const abs = path.resolve(dir, item, 'package.json'); + const info = require(abs).rspack; + ok(typeof info.version === 'string') + ok(typeof name === 'string') + ok(typeof version === 'string') + return { + name, + version, + rspackVersion: info.version, + path: path.relative(root, path.resolve(dir, item)) + } + }) +} + +/** + * @param {string[]} args + */ +async function run(args) { + const dir = path.resolve(root, 'packages'); + const jsonStr = await readCompat(dir).then((list) => JSON.stringify(list, undefined, 2)); + const name = 'rspack-compat.json' + const abs = path.resolve(root, name) + // write file to root + await fs.writeFile(abs, jsonStr) + + // const token = args[0]; + // ok(typeof token === 'string'); + // const GITHUB_ACTOR = process.env.GITHUB_ACTOR; + // ok(typeof GITHUB_ACTOR === 'string'); + // const repoUrl = `https://${GITHUB_ACTOR}:${token}@github.com/web-infra-dev/rspack-compat.git`; + + // if (!fsSync.existsSync(dataDir)) { + // await runCommand("git", [ + // "clone", + // "--branch", + // "data", + // "--single-branch", + // "--depth", + // "1", + // repoUrl, + // ".data" + // ]) + // } + // process.chdir(dataDir); + // await runCommand("git", ["remote", "set-url", "origin", repoUrl]); + // await runCommand("git", ["reset", "--hard", "origin/data"]); + // await runCommand("git", ["pull", "--rebase"]); + + // await fs.copyFile(abs, path.resolve(dataDir, name)); + // // await fs.unlink(abs); + + // await runCommand("ls", ["-alh"]); + // await runCommand("git", ["rev-parse", "--abbrev-ref", "HEAD"]); + + // try { + // await runCommand("git", ["add", "."]); + // // git commit may run failed due there has no file changed + // await runCommand("git", ["commit", "-m", `"update compat info"`]); + // await runCommand("git", ["push", "origin", "data", "-f"]); + // } catch (error) { + // console.log(error) + // } +} + +run(process.argv.slice(2))