This is an automated email from the ASF dual-hosted git repository. maximebeauchemin pushed a commit to branch pyproject.toml in repository https://gitbox.apache.org/repos/asf/superset.git
commit 4938e955ca071aacb9c255691861ccee764545cc Author: Maxime Beauchemin <[email protected]> AuthorDate: Mon Mar 25 16:18:05 2024 -0700 progress --- .github/supersetbot/src/cli.js | 2 +- .github/supersetbot/src/github.js | 33 ++++++++++++-------- .github/supersetbot/src/utils.js | 64 ++++++++++++++++++++++++++------------- 3 files changed, 65 insertions(+), 34 deletions(-) diff --git a/.github/supersetbot/src/cli.js b/.github/supersetbot/src/cli.js index 4cefa3567f..2241d0c232 100755 --- a/.github/supersetbot/src/cli.js +++ b/.github/supersetbot/src/cli.js @@ -156,7 +156,7 @@ export default function getCLI(context) { .action(async function (pythonLib) { const opts = context.processOptions(this, ['repo']); const github = new Github({ context }); - github.createBumpLibPullRequest(pythonLib, opts.verbose, opts.dryRun); + await github.createBumpLibPullRequest(pythonLib, opts.verbose, opts.dryRun); }); diff --git a/.github/supersetbot/src/github.js b/.github/supersetbot/src/github.js index f94b350de5..b2b0ca2849 100644 --- a/.github/supersetbot/src/github.js +++ b/.github/supersetbot/src/github.js @@ -253,33 +253,42 @@ class Github { return PROTECTED_LABEL_PATTERNS.some((pattern) => new RegExp(pattern).test(label)); } - createBumpLibPullRequest(lib, verbose = false, dryRun = false) { + async createBumpLibPullRequest(lib, verbose = false, dryRun = false) { const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'update-')); console.log("CWD:", cwd); // Clone the repo - runShellCommand({ command: `git clone --depth 1 [email protected]:${this.context.repo} .`, cwd, verbose }); + await runShellCommand({ command: `git clone --depth 1 [email protected]:${this.context.repo} .`, cwd, verbose }); // Run pip-compile-multi - runShellCommand({ command: `pip-compile-multi -P ${lib}`, cwd }); + await runShellCommand({ command: `pip-compile-multi -P ${lib}`, cwd }); - // Check for changes - const status = runShellCommand({ command: 'git status --porcelain', cwd, raiseOnError: false, verbose }); - if (!!status) { + // Diffing + const diffResults = await runShellCommand({ command: 'git diff --color=never --unified=0', cwd, raiseOnError: false, verbose, exitOnError: false }); + + const changed = diffResults.stdout.trim() + .split('\n') + .map((line) => line.trim()) + .filter((line) => line.startsWith('+' + lib)) + .map((line) => line.substring(1)); + + if (changed.length === 0) { console.log('No changes detected... skipping.'); } else { + console.log("LIB:", changed[0]); + // Create branch - const branchName = `bump-${lib}-${Date.now()}`; - runShellCommand({ command: `git checkout -b ${branchName}`, cwd, verbose }); + const branchName = `supersetbot-bump-${changed[0]}`; + await runShellCommand({ command: `git checkout -b ${branchName}`, cwd, verbose }); // Commit changes - runShellCommand({ command: `git add .`, cwd }); - const commitMessage = `chore(supersetbot): bump python library "${lib}"`; - runShellCommand({ command: `git commit -m "${commitMessage}"`, cwd, verbose }); + await runShellCommand({ command: `git add .`, cwd }); + const commitMessage = `chore(🤖): bump python "${changed[0]}"`; + await runShellCommand({ command: `git commit -m "${commitMessage}"`, cwd, verbose }); // Push changes - runShellCommand({ command: `git push origin ${branchName}`, cwd, verbose }); + await runShellCommand({ command: `git push origin ${branchName}`, cwd, verbose }); if (!dryRun) { // Create a PR diff --git a/.github/supersetbot/src/utils.js b/.github/supersetbot/src/utils.js index 07777c378e..8bc745a852 100644 --- a/.github/supersetbot/src/utils.js +++ b/.github/supersetbot/src/utils.js @@ -17,7 +17,7 @@ * under the License. */ -import { spawnSync } from 'child_process'; +import { spawn} from 'child_process'; import { readFile } from 'fs/promises'; import { fileURLToPath } from 'url'; @@ -41,29 +41,51 @@ export async function currentPackageVersion() { return data.version; } + export function runShellCommand({ command, raiseOnError = true, exitOnError = true, cwd = null, verbose = false }) { - const args = command.split(/\s+/).filter((s) => !!s && s !== '\\'); - const spawnOptions = { stdio: 'inherit', shell: true }; - if (verbose) { - console.log(`RUN: ${command}`); - } - if (cwd) { - spawnOptions.cwd = cwd; - } + return new Promise((resolve, reject) => { + const args = command.split(/\s+/).filter((s) => !!s && s !== '\\'); + const spawnOptions = { + shell: true, + cwd, + }; - const result = spawnSync(args.shift(), args, spawnOptions); + if (verbose) { + console.log(`RUN: ${command}`); + } - if (result.status !== 0) { - const msg = `Command failed with exit code ${result.status}: ${result.stderr?.toString()}`; - console.error(msg); + const child = spawn(args.shift(), args, spawnOptions); + let stdout = ''; + let stderr = ''; - if (raiseOnError) { - throw new Error(msg); - } - if (exitOnError) { - process.exit(1); - } - } + child.stdout.on('data', (data) => { + console.log(data.toString()); + stdout += data.toString(); + }); + + child.stderr.on('data', (data) => { + console.log(data.toString()); + stderr += data.toString(); + }); + + child.on('close', (code) => { + if (code !== 0) { + const msg = `Command failed with exit code ${code}: ${stderr}`; + console.error(msg); + + if (raiseOnError) { + reject(new Error(msg)); + } + if (exitOnError) { + process.exit(1); + } + } + + resolve({ stdout, stderr }); + }); - return result.stdout?.toString(); + child.on('error', (err) => { + reject(err); + }); + }); }
