Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
chore: upload repo info
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Nov 14, 2023
1 parent 2e8e5d7 commit 441c8b8
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/upload.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Upload file
on:
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"
- name: Generate files
run: node scripts/upload.js ${{ secrets.GITHUB_TOKEN }}
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: "data"
3 changes: 3 additions & 0 deletions packages/babel-loader@9/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
3 changes: 3 additions & 0 deletions packages/copy-webpack-plugin@5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"devDependencies": {
"@rspack/cli": "0.3.11",
"copy-webpack-plugin": "^5.1.2"
},
"rspack": {
"version": ">=0.3.11"
}
}
3 changes: 3 additions & 0 deletions packages/fork-ts-checker-webpack-plugin@8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"devDependencies": {
"@rspack/cli": "0.3.11",
"fork-ts-checker-webpack-plugin": "^8.0.0"
},
"rspack": {
"version": ">=0.3.11"
}
}
3 changes: 3 additions & 0 deletions packages/generate-package-json-webpack-plugin@2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"devDependencies": {
"@rspack/cli": "0.3.11",
"generate-package-json-webpack-plugin": "^2.6.0"
},
"rspack": {
"version": ">=0.3.11"
}
}
3 changes: 3 additions & 0 deletions packages/html-webpack-plugin@5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"devDependencies": {
"@rspack/cli": "0.3.11",
"html-webpack-plugin": "^5.5.3"
},
"rspack": {
"version": ">=0.3.11"
}
}
3 changes: 3 additions & 0 deletions packages/webpack-bundle-analyzer@4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"devDependencies": {
"@rspack/cli": "0.3.11",
"webpack-bundle-analyzer": "^4.9.1"
},
"rspack": {
"version": ">=0.3.11"
}
}
3 changes: 3 additions & 0 deletions packages/webpack-stats-plugin@1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"devDependencies": {
"@rspack/cli": "0.3.11",
"webpack-stats-plugin": "^1.1.3"
},
"rspack": {
"version": ">=0.3.11"
}
}
120 changes: 120 additions & 0 deletions scripts/upload.js
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 441c8b8

Please sign in to comment.