From c3016f9889153ba8941e643e66d5f9490480a206 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Fri, 2 Jun 2023 01:49:43 +0100 Subject: [PATCH] Fix detecting branch in CI and don't include remote-config.json in app bundle --- package.json | 3 ++- resources/build/ci-main-version.js | 4 ++-- resources/build/ci-package-json.js | 4 ++-- rollup.config.js | 10 +++++++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 9c8f828..6527b04 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,8 @@ "!dist/app/package", "!**/node_modules/**/*", "resources/app", - "resources/common" + "resources/common", + "!resources/common/remote-config.json" ], "asar": false, "extraMetadata": { diff --git a/resources/build/ci-main-version.js b/resources/build/ci-main-version.js index 3306987..8e36ca5 100644 --- a/resources/build/ci-main-version.js +++ b/resources/build/ci-main-version.js @@ -11,8 +11,8 @@ const git = (...args) => execFile('git', args, options).then(({stdout}) => stdou const pkg = JSON.parse(await fs.readFile(new URL('../../package.json', import.meta.url), 'utf-8')); const [revision, branch_str, changed_files_str, tags_str, commit_count_str] = await Promise.all([ - git('rev-parse', 'HEAD'), - git('rev-parse', '--abbrev-ref', 'HEAD'), + process.env.CI_COMMIT_SHA || git('rev-parse', 'HEAD'), + process.env.CI_COMMIT_BRANCH || git('rev-parse', '--abbrev-ref', 'HEAD'), git('diff', '--name-only', 'HEAD'), git('log', '--tags', '--no-walk', '--pretty=%D'), git('rev-list', '--count', 'HEAD'), diff --git a/resources/build/ci-package-json.js b/resources/build/ci-package-json.js index 8cc04c2..8c0211b 100644 --- a/resources/build/ci-package-json.js +++ b/resources/build/ci-package-json.js @@ -10,8 +10,8 @@ const git = (...args) => execFile('git', args, options).then(({stdout}) => stdou const pkg = JSON.parse(await fs.readFile(new URL('../../package.json', import.meta.url), 'utf-8')); const [revision, branch, changed_files] = await Promise.all([ - git('rev-parse', 'HEAD'), - git('rev-parse', '--abbrev-ref', 'HEAD'), + process.env.CI_COMMIT_SHA || git('rev-parse', 'HEAD'), + process.env.CI_COMMIT_BRANCH || git('rev-parse', '--abbrev-ref', 'HEAD'), git('diff', '--name-only', 'HEAD'), ]); diff --git a/rollup.config.js b/rollup.config.js index 0bb6d3d..c80becf 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -18,6 +18,14 @@ const default_remote_config = JSON.parse(fs.readFileSync(path.join(dir, 'resources', 'common', 'remote-config.json'), 'utf-8')); const git = (() => { + if (process.env.GITLAB_CI && process.env.CI_COMMIT_SHA) { + return { + revision: process.env.CI_COMMIT_SHA, + branch: process.env.CI_COMMIT_BRANCH || null, + changed_files: [], + }; + } + try { fs.statSync(path.join(dir, '.git')); } catch (err) { @@ -34,7 +42,7 @@ const git = (() => { branch: branch && branch !== 'HEAD' ? branch : null, changed_files: changed_files.length ? changed_files.split('\n') : [], }; -})();; +})(); // If CI_COMMIT_TAG is set this is a tagged version for release const release = process.env.NODE_ENV === 'production' ? process.env.CI_COMMIT_TAG || null : null;