Commit a730c443 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'prefer-to-use-foss-only' into 'master'

Change `IS_GITLAB_EE` to `FOSS_ONLY`

Closes #33875

See merge request gitlab-org/gitlab!18517
parents 2ac03aa4 c2508bda
...@@ -153,4 +153,4 @@ ...@@ -153,4 +153,4 @@
.only-ee-as-if-foss: .only-ee-as-if-foss:
extends: .only-ee extends: .only-ee
variables: variables:
IS_GITLAB_EE: '0' FOSS_ONLY: '1'
...@@ -3,12 +3,12 @@ const path = require('path'); ...@@ -3,12 +3,12 @@ const path = require('path');
const ROOT_PATH = path.resolve(__dirname, '../..'); const ROOT_PATH = path.resolve(__dirname, '../..');
// The `IS_GITLAB_EE` is always `string` or `nil` // The `FOSS_ONLY` is always `string` or `nil`
// Thus the nil or empty string will result // Thus the nil or empty string will result
// in using default value: true // in using default value: false
// //
// The behavior needs to be synchronised with // The behavior needs to be synchronised with
// lib/gitlab.rb: Gitlab.ee? // lib/gitlab.rb: Gitlab.ee?
const isFossOnly = JSON.parse(process.env.FOSS_ONLY || 'false');
module.exports = module.exports =
fs.existsSync(path.join(ROOT_PATH, 'ee', 'app', 'models', 'license.rb')) && fs.existsSync(path.join(ROOT_PATH, 'ee', 'app', 'models', 'license.rb')) && !isFossOnly;
(!process.env.IS_GITLAB_EE || JSON.parse(process.env.IS_GITLAB_EE));
...@@ -380,7 +380,7 @@ module.exports = { ...@@ -380,7 +380,7 @@ module.exports = {
new webpack.DefinePlugin({ new webpack.DefinePlugin({
// This one is used to define window.gon.ee and other things properly in tests: // This one is used to define window.gon.ee and other things properly in tests:
'process.env.IS_GITLAB_EE': JSON.stringify(IS_EE), 'process.env.IS_EE': JSON.stringify(IS_EE),
// This one is used to check against "EE" properly in application code // This one is used to check against "EE" properly in application code
IS_EE: IS_EE ? 'window.gon && window.gon.ee' : JSON.stringify(false), IS_EE: IS_EE ? 'window.gon && window.gon.ee' : JSON.stringify(false),
}), }),
......
...@@ -20,9 +20,9 @@ should be added for EE. Licensed features can be stubbed using the ...@@ -20,9 +20,9 @@ should be added for EE. Licensed features can be stubbed using the
spec helper `stub_licensed_features` in `EE::LicenseHelpers`. spec helper `stub_licensed_features` in `EE::LicenseHelpers`.
You can force GitLab to act as CE by either deleting the `ee/` directory or by You can force GitLab to act as CE by either deleting the `ee/` directory or by
setting the [`IS_GITLAB_EE` environment variable](https://gitlab.com/gitlab-org/gitlab/blob/master/config/helpers/is_ee_env.js) setting the [`FOSS_ONLY` environment variable](https://gitlab.com/gitlab-org/gitlab/blob/master/config/helpers/is_ee_env.js)
to something that evaluates as `false`. The same works for running tests to something that evaluates as `true`. The same works for running tests
(for example `IS_GITLAB_EE=0 yarn jest`). (for example `FOSS_ONLY=1 yarn jest`).
[ee-as-ce]: https://gitlab.com/gitlab-org/gitlab/issues/2500 [ee-as-ce]: https://gitlab.com/gitlab-org/gitlab/issues/2500
......
...@@ -102,7 +102,7 @@ These common definitions are: ...@@ -102,7 +102,7 @@ These common definitions are:
`docker.elastic.co/elasticsearch/elasticsearch:5.6.12` services. `docker.elastic.co/elasticsearch/elasticsearch:5.6.12` services.
- `.only-ee`: Only creates a job for the `gitlab` project. - `.only-ee`: Only creates a job for the `gitlab` project.
- `.only-ee-as-if-foss`: Same as `.only-ee` but simulate the FOSS project by - `.only-ee-as-if-foss`: Same as `.only-ee` but simulate the FOSS project by
setting the `IS_GITLAB_EE='0'` environment variable. setting the `FOSS_ONLY='1'` environment variable.
## Changes detection ## Changes detection
......
...@@ -69,14 +69,14 @@ module Gitlab ...@@ -69,14 +69,14 @@ module Gitlab
# means that checking the presence of the License class could result in # means that checking the presence of the License class could result in
# this method returning `false`, even for an EE installation. # this method returning `false`, even for an EE installation.
# #
# The `IS_GITLAB_EE` is always `string` or `nil` # The `FOSS_ONLY` is always `string` or `nil`
# Thus the nil or empty string will result # Thus the nil or empty string will result
# in using default value: true # in using default value: false
# #
# The behavior needs to be synchronised with # The behavior needs to be synchronised with
# config/helpers/is_ee_env.js # config/helpers/is_ee_env.js
root.join('ee/app/models/license.rb').exist? && root.join('ee/app/models/license.rb').exist? &&
(ENV['IS_GITLAB_EE'].to_s.empty? || Gitlab::Utils.to_boolean(ENV['IS_GITLAB_EE'])) !%w[true 1].include?(ENV['FOSS_ONLY'].to_s)
end end
def self.ee def self.ee
......
...@@ -70,7 +70,7 @@ window.gl = window.gl || {}; ...@@ -70,7 +70,7 @@ window.gl = window.gl || {};
window.gl.TEST_HOST = TEST_HOST; window.gl.TEST_HOST = TEST_HOST;
window.gon = window.gon || {}; window.gon = window.gon || {};
window.gon.test_env = true; window.gon.test_env = true;
window.gon.ee = process.env.IS_GITLAB_EE; window.gon.ee = process.env.IS_EE;
gon.relative_url_root = ''; gon.relative_url_root = '';
let hasUnhandledPromiseRejections = false; let hasUnhandledPromiseRejections = false;
...@@ -118,7 +118,7 @@ const axiosDefaultAdapter = getDefaultAdapter(); ...@@ -118,7 +118,7 @@ const axiosDefaultAdapter = getDefaultAdapter();
// render all of our tests // render all of our tests
const testContexts = [require.context('spec', true, /_spec$/)]; const testContexts = [require.context('spec', true, /_spec$/)];
if (process.env.IS_GITLAB_EE) { if (process.env.IS_EE) {
testContexts.push(require.context('ee_spec', true, /_spec$/)); testContexts.push(require.context('ee_spec', true, /_spec$/));
} }
...@@ -207,7 +207,7 @@ if (process.env.BABEL_ENV === 'coverage') { ...@@ -207,7 +207,7 @@ if (process.env.BABEL_ENV === 'coverage') {
describe('Uncovered files', function() { describe('Uncovered files', function() {
const sourceFilesContexts = [require.context('~', true, /\.(js|vue)$/)]; const sourceFilesContexts = [require.context('~', true, /\.(js|vue)$/)];
if (process.env.IS_GITLAB_EE) { if (process.env.IS_EE) {
sourceFilesContexts.push(require.context('ee', true, /\.(js|vue)$/)); sourceFilesContexts.push(require.context('ee', true, /\.(js|vue)$/));
} }
......
...@@ -146,7 +146,7 @@ describe Gitlab do ...@@ -146,7 +146,7 @@ describe Gitlab do
describe '.ee?' do describe '.ee?' do
before do before do
stub_env('IS_GITLAB_EE', nil) # Make sure the ENV is clean stub_env('FOSS_ONLY', nil) # Make sure the ENV is clean
described_class.instance_variable_set(:@is_ee, nil) described_class.instance_variable_set(:@is_ee, nil)
end end
...@@ -154,42 +154,66 @@ describe Gitlab do ...@@ -154,42 +154,66 @@ describe Gitlab do
described_class.instance_variable_set(:@is_ee, nil) described_class.instance_variable_set(:@is_ee, nil)
end end
it 'returns true when using Enterprise Edition' do context 'for EE' do
root = Pathname.new('dummy') before do
license_path = double(:path, exist?: true) root = Pathname.new('dummy')
license_path = double(:path, exist?: true)
allow(described_class) allow(described_class)
.to receive(:root) .to receive(:root)
.and_return(root) .and_return(root)
allow(root) allow(root)
.to receive(:join) .to receive(:join)
.with('ee/app/models/license.rb') .with('ee/app/models/license.rb')
.and_return(license_path) .and_return(license_path)
end
expect(described_class.ee?).to eq(true) context 'when using FOSS_ONLY=1' do
end before do
stub_env('FOSS_ONLY', '1')
end
it 'returns false when using Community Edition' do it 'returns not to be EE' do
root = double(:path) expect(described_class).not_to be_ee
license_path = double(:path, exists?: false) end
end
allow(described_class) context 'when using FOSS_ONLY=0' do
.to receive(:root) before do
.and_return(Pathname.new('dummy')) stub_env('FOSS_ONLY', '0')
end
allow(root) it 'returns to be EE' do
.to receive(:join) expect(described_class).to be_ee
.with('ee/app/models/license.rb') end
.and_return(license_path) end
expect(described_class.ee?).to eq(false) context 'when using default FOSS_ONLY' do
it 'returns to be EE' do
expect(described_class).to be_ee
end
end
end end
it 'returns true when the IS_GITLAB_EE variable is not empty' do context 'for CE' do
stub_env('IS_GITLAB_EE', '1') before do
root = double(:path)
license_path = double(:path, exists?: false)
expect(described_class.ee?).to eq(true) allow(described_class)
.to receive(:root)
.and_return(Pathname.new('dummy'))
allow(root)
.to receive(:join)
.with('ee/app/models/license.rb')
.and_return(license_path)
end
it 'returns not to be EE' do
expect(described_class).not_to be_ee
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment