prepare-python-release.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* -----------------------------------------------------------------------------
  2. | Copyright (c) Jupyter Development Team.
  3. | Distributed under the terms of the Modified BSD License.
  4. |----------------------------------------------------------------------------*/
  5. import commander from 'commander';
  6. import * as crypto from 'crypto';
  7. import * as fs from 'fs-extra';
  8. import * as path from 'path';
  9. import * as utils from './utils';
  10. // Specify the program signature.
  11. commander
  12. .description('Prepare the Python package for release')
  13. .action(async (options: any) => {
  14. utils.exitOnUuncaughtException();
  15. const distDir = './dist';
  16. // Clean the dist directory.
  17. if (fs.existsSync(distDir)) {
  18. fs.removeSync(distDir);
  19. }
  20. // Update core mode. This cannot be done until the JS packages are
  21. // released.
  22. utils.run('node buildutils/lib/update-core-mode.js');
  23. // Make the Python release.
  24. utils.run('python -m pip install -U twine build');
  25. utils.run('python -m build .');
  26. utils.run('twine check dist/*');
  27. const files = fs.readdirSync(distDir);
  28. const hashes = new Map<string, string>();
  29. files.forEach(file => {
  30. const shasum = crypto.createHash('sha256');
  31. const hash = shasum.update(fs.readFileSync(path.join(distDir, file)));
  32. hashes.set(file, hash.digest('hex'));
  33. });
  34. const hashString = Array.from(hashes.entries())
  35. .map(entry => `${entry[0]}: ${entry[1]}`)
  36. .join('" -m "');
  37. // Make the commit and the tag.
  38. const curr = utils.getPythonVersion();
  39. utils.run(
  40. `git commit -am "Publish ${curr}" -m "SHA256 hashes:" -m "${hashString}"`
  41. );
  42. utils.run(`git tag v${curr}`);
  43. // Prompt the user to finalize.
  44. console.debug('*'.repeat(40));
  45. console.debug('*'.repeat(40));
  46. console.debug('Ready to publish!');
  47. console.debug('Run these command when ready:');
  48. console.debug('twine upload dist/*');
  49. console.debug('git push origin <BRANCH> --tags');
  50. // Emit a system beep.
  51. process.stdout.write('\x07');
  52. });
  53. commander.parse(process.argv);