get-version.js 1.1 KB

12345678910111213141516171819202122
  1. const { spawnSync } = require('node:child_process');
  2. const path = require('node:path');
  3. module.exports.getElectronVersion = () => {
  4. // Find the nearest tag to the current HEAD
  5. // This is equivilant to our old logic of "use a value in package.json" for the following reasons
  6. //
  7. // 1. Whenever we updated the package.json we ALSO pushed a tag with the same version
  8. // 2. Whenever we _reverted_ a bump all we actually did was push a commit that deleted the tag and changed the version number back
  9. //
  10. // The only difference in the "git describe" technique is that technically a commit can "change" it's version
  11. // number if a tag is created / removed retroactively. i.e. the first time a commit is pushed it will be 1.2.3
  12. // and after the tag is made rebuilding the same commit will result in it being 1.2.4
  13. const output = spawnSync('git', ['describe', '--tags', '--abbrev=0'], {
  14. cwd: path.resolve(__dirname, '..', '..')
  15. });
  16. if (output.status !== 0) {
  17. console.error(output.stderr);
  18. throw new Error('Failed to get current electron version');
  19. }
  20. return output.stdout.toString().trim().replace(/^v/g, '');
  21. };