build: determine electron version from tags not files (#36106)

* build: determine electron version from tags not files

* build: make electron_version dependent on packed-refs and git HEAD

* build: do not delete electron/.git

* build: do not revert a commit we didn't make

* build: gen version file instead of just writing it

* build: update cache and ninja targets

* build: copy resource.h to generated electron.rc

* build: electron_win32_resources should be public deps

* build: also copy the icon
This commit is contained in:
Samuel Attard 2022-10-24 23:44:43 -07:00 committed by GitHub
parent ad289d120f
commit 7ca2bb5f9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 145 additions and 260 deletions

20
script/lib/get-version.js Normal file
View file

@ -0,0 +1,20 @@
const { spawnSync } = require('child_process');
const rootPackageJson = require('../../package.json');
module.exports.getElectronVersion = () => {
// Find the nearest tag to the current HEAD
// This is equivilant to our old logic of "use a value in package.json" for the following reasons
//
// 1. Whenever we updated the package.json we ALSO pushed a tag with the same version
// 2. Whenever we _reverted_ a bump all we actually did was push a commit that deleted the tag and changed the version number back
//
// The only difference in the "git describe" technique is that technically a commit can "change" it's version
// number if a tag is created / removed retroactively. i.e. the first time a commit is pushed it will be 1.2.3
// and after the tag is made rebuilding the same commit will result in it being 1.2.4
const output = spawnSync('git', ['describe', '--tags', '--abbrev=0']);
if (output.status !== 0) {
console.error(output.stderr);
throw new Error('Failed to get current electron version');
}
return output.stdout.toString().trim();
};

View file

@ -15,7 +15,9 @@ except ImportError:
from urllib2 import urlopen
import zipfile
from lib.config import is_verbose_mode
# from lib.config import is_verbose_mode
def is_verbose_mode():
return False
ELECTRON_DIR = os.path.abspath(
os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
@ -149,11 +151,17 @@ def get_electron_branding():
with open(branding_file_path) as f:
return json.load(f)
cached_electron_version = None
def get_electron_version():
SOURCE_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', '..'))
version_file = os.path.join(SOURCE_ROOT, 'ELECTRON_VERSION')
with open(version_file) as f:
return 'v' + f.read().strip()
global cached_electron_version
if cached_electron_version is None:
cached_electron_version = str.strip(execute([
'node',
'-p',
'require("./script/lib/get-version").getElectronVersion()'
], cwd=ELECTRON_DIR).decode())
return cached_electron_version
def store_artifact(prefix, key_prefix, files):
# Azure Storage