commit-and-open-pr.js 1.4 KB

1234567891011121314151617181920212223242526272829
  1. import { spawnSync } from 'node:child_process'
  2. import { fileURLToPath } from 'node:url'
  3. import prompts from 'prompts'
  4. import { REPO_OWNER, REPO_NAME } from './config.js'
  5. export default async function commit (spawnOptions, ...files) {
  6. console.log(`Now is the time to do manual edits to ${files.join(',')}.`)
  7. await prompts({
  8. type: 'toggle',
  9. name: 'value',
  10. message: 'Ready to commit?',
  11. initial: true,
  12. active: 'yes',
  13. inactive: 'yes',
  14. })
  15. spawnSync('git', ['add', ...files.map(url => fileURLToPath(url))], spawnOptions)
  16. spawnSync('git', ['commit', '-n', '-m', 'Prepare next release'], { ...spawnOptions, stdio: 'inherit' })
  17. const sha = spawnSync('git', ['rev-parse', 'HEAD'], spawnOptions).stdout.toString().trim()
  18. const getRemoteCommamnd = `git remote -v | grep '${REPO_OWNER}/${REPO_NAME}' | awk '($3 == "(push)") { print $1; exit }'`
  19. const remote = spawnSync('/bin/sh', ['-c', getRemoteCommamnd]).stdout.toString().trim()
  20. || `git@github.com:${REPO_OWNER}/${REPO_NAME}.git`
  21. console.log(`Please run \`git push ${remote} ${sha}:refs/heads/release\`.`)
  22. console.log(`An automation will kick off and open a release candidate PR
  23. on the GitHub repository. Do not merge it manually! Review the PR (you may need to close and
  24. re-open so the CI and test will run on it). If everything looks good, approve the PR —
  25. this will publish updated packages to npm, then the PR will be merged.`)
  26. }