Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup env variables #24739

Merged
merged 19 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/screener-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ jobs:
# BROWSERSLIST_IGNORE_OLD_DATA = Prevents failures on CI when "caniuse-lite" becomes outdated
# DEPLOYHOST = address of host for screener tests deployment
# BUILD_BUILDID = unique ID of the workflow run within the repo
# BUILD_SOURCEBRANCH = branch that triggered the workflow -> refs/pull/<pr_number>/merge
###########################################
- name: Set base env variables
run: |
cat <<EOT >> artifacts/environment
BROWSERSLIST_IGNORE_OLD_DATA=true
DEPLOYHOST='fluentuipr.z22.web.core.windows.net'
BUILD_BUILDID=${{ github.run_id }}
BUILD_SOURCEBRANCH=${{ github.ref }}
SCREENER_BUILD=1
EOT

Expand Down Expand Up @@ -77,12 +74,11 @@ jobs:
run: |
cat <<EOT >> artifacts/environment
SYSTEM_PULLREQUEST_TARGETBRANCH=${{ github.event.pull_request.base.ref }}
SYSTEM_PULLREQUEST_SOURCEBRANCH=${{ github.event.pull_request.head.ref }}
SYSTEM_PULLREQUEST_PULLREQUESTID=${{ github.event.pull_request.id }}
SYSTEM_PULLREQUEST_SOURCECOMMITID=${{ github.event.pull_request.head.sha }}
DEPLOYBASEPATH=pull/${{github.event.pull_request.number}}
DEPLOYURL=https://${{env.DEPLOYHOST}}/pull/${{github.event.pull_request.number}}
BUILD_SOURCEBRANCHNAME='merge'
BUILD_SOURCEBRANCHNAME=${{ github.event.pull_request.head.ref }}
EOT
if: ${{ github.event_name == 'pull_request' && env.SKIP_SCREENER == ''}}

Expand Down
50 changes: 28 additions & 22 deletions apps/vr-tests-react-components/screener.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,32 @@ function getCurrentHash() {

return '';
}
/**
*
* @param {Object} options
* @param {string} options.screenerApiKey
* @param {string} options.sourceBranchName
* @param {string} options.deployUrl
* @param {string} options.targetBranch
* @returns
*/
function getConfig({ screenerApiKey, sourceBranchName, deployUrl, targetBranch }) {
const baseBranch = targetBranch ? targetBranch.replace(/^refs\/heads\//, '') : 'master';
// https://github.com/screener-io/screener-storybook#additional-configuration-options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be great if we can extract this type to encapsulated interface and use it whenever needed

const config = {
projectRepo: 'microsoft/fluentui/react-components',
storybookStaticBuildDir: 'dist/storybook',
storybookConfigDir: '.storybook',
apiKey: screenerApiKey,
resolution: '1024x768',
baseBranch,
failureExitCode: 0,
alwaysAcceptBaseBranch: true,
...(sourceBranchName !== 'master' ? { commit: getCurrentHash() } : null),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is duplication in every config defined, can we make it DRY ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the configs for v8 and v9 are indeed almost identical, will check if it's possible to use only one file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they should live within scripts/screener domain, later on this will be separate package

Copy link
Contributor Author

@ralucapelin ralucapelin Sep 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will make this change in the same follow-up PR as the one mentioned here as this PR only deals with changes regarding env variables: https://github.com/microsoft/fluentui/pull/24739/files#r969406141

baseUrl: `${deployUrl}/react-components-screener/iframe.html`,
};
console.log('Screener config: ' + JSON.stringify({ ...config, apiKey: '...' }, null, 2));
return config;
}

const baseBranch = process.env.SYSTEM_PULLREQUEST_TARGETBRANCH
? process.env.SYSTEM_PULLREQUEST_TARGETBRANCH.replace(/^refs\/heads\//, '')
: 'master';

// https://github.com/screener-io/screener-storybook#additional-configuration-options
const config = {
projectRepo: 'microsoft/fluentui/react-components',
storybookStaticBuildDir: 'dist/storybook',
storybookConfigDir: '.storybook',
apiKey: process.env.SCREENER_API_KEY,
resolution: '1024x768',
baseBranch,
failureExitCode: 0,
alwaysAcceptBaseBranch: true,
...(process.env.BUILD_SOURCEBRANCH && process.env.BUILD_SOURCEBRANCH.indexOf('refs/pull') > -1
? { commit: getCurrentHash() }
: null),
baseUrl: `${process.env.DEPLOYURL}/react-components-screener/iframe.html`,
};
console.log('Screener config: ' + JSON.stringify({ ...config, apiKey: '...' }, null, 2));

module.exports = config;
module.exports = getConfig;
48 changes: 28 additions & 20 deletions apps/vr-tests/screener.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,33 @@ function getCurrentHash() {
return '';
}

const baseBranch = process.env.SYSTEM_PULLREQUEST_TARGETBRANCH
? process.env.SYSTEM_PULLREQUEST_TARGETBRANCH.replace(/^refs\/heads\//, '')
: 'master';
/**
*
* @param {Object} options
* @param {string} options.screenerApiKey
* @param {string} options.sourceBranchName
* @param {string} options.deployUrl
* @param {string} options.targetBranch
* @returns
*/
function getConfig({ screenerApiKey, sourceBranchName, deployUrl, targetBranch }) {
const baseBranch = targetBranch ? targetBranch.replace(/^refs\/heads\//, '') : 'master';

// https://github.com/screener-io/screener-storybook#additional-configuration-options
const config = {
projectRepo: 'microsoft/fluentui',
storybookStaticBuildDir: 'dist/storybook',
storybookConfigDir: '.storybook',
apiKey: process.env.SCREENER_API_KEY,
resolution: '1024x768',
baseBranch,
failureExitCode: 0,
alwaysAcceptBaseBranch: true,
...(process.env.BUILD_SOURCEBRANCH && process.env.BUILD_SOURCEBRANCH.indexOf('refs/pull') > -1
? { commit: getCurrentHash() }
: null),
baseUrl: `${process.env.DEPLOYURL}/react-screener/iframe.html`,
};
console.log('Screener config: ' + JSON.stringify({ ...config, apiKey: '...' }, null, 2));
// https://github.com/screener-io/screener-storybook#additional-configuration-options
const config = {
projectRepo: 'microsoft/fluentui',
storybookStaticBuildDir: 'dist/storybook',
storybookConfigDir: '.storybook',
apiKey: screenerApiKey,
resolution: '1024x768',
baseBranch,
failureExitCode: 0,
alwaysAcceptBaseBranch: true,
...(sourceBranchName !== 'master' ? { commit: getCurrentHash() } : null),
baseUrl: `${deployUrl}/react-screener/iframe.html`,
};
console.log('Screener config: ' + JSON.stringify({ ...config, apiKey: '...' }, null, 2));
return config;
}

module.exports = config;
module.exports = getConfig;
9 changes: 6 additions & 3 deletions scripts/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path';
import * as _ from 'lodash';
import * as webpack from 'webpack';
import { URL } from 'url';

// ------------------------------------
// Environment vars
Expand All @@ -9,14 +10,16 @@ const env = process.env.NODE_ENV || 'development';
const __DEV__ = env === 'development';
const __PERF__ = !!process.env.PERF;
const __PROD__ = env === 'production';
let __BASENAME__ = process.env.DEPLOYBASEPATH
const deployUrl = process.env.DEPLOYURL ? new URL(process.env.DEPLOYURL) : undefined;
const deployBasePath = deployUrl ? deployUrl.pathname : undefined;
let __BASENAME__ = deployBasePath
? // This needs a trailing slash or images won't work.
// The path is different for standard PR deploy and screener deploy.
`/${process.env.DEPLOYBASEPATH}/${process.env.SCREENER_BUILD ? 'react-northstar-screener' : 'react-northstar'}/`
`${deployBasePath}/${process.env.SCREENER_BUILD ? 'react-northstar-screener' : 'react-northstar'}/`
: '/';

if (process.env.OFFICIALRELEASE) {
__BASENAME__ = `/${process.env.DEPLOYBASEPATH}/`;
__BASENAME__ = `${deployBasePath}/`;
}

const __SKIP_ERRORS__ = !!process.env.SKIP_ERRORS;
Expand Down
6 changes: 5 additions & 1 deletion scripts/gulp/tasks/screener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ task('screener:runner', cb => {
process.exit(1);
});

const screenerConfig = require(screenerConfigPath);
const getConfig = require(screenerConfigPath);
const screenerConfig = getConfig({
screenerApiKey: process.env.SCREENER_API_KEY,
sourceBranchName: process.env.BUILD_SOURCEBRANCHNAME,
});

handlePromiseExit(screenerRunner(screenerConfig));
});
Expand Down
71 changes: 40 additions & 31 deletions scripts/screener/screener.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,43 @@ require('tsconfig-paths').register({
});

const baseBranch = 'master';
const sourceBranch = process.env.BUILD_SOURCEBRANCH;

// https://github.com/screener-io/screener-runner
module.exports = {
apiKey: process.env.SCREENER_API_KEY,
projectRepo: 'microsoft/fluentui/fluentui',

diffOptions: {
structure: true,
layout: true,
style: true,
content: true,
minLayoutPosition: 1, // Optional threshold for Layout changes. Defaults to 4 pixels.
minLayoutDimension: 1, // Optional threshold for Layout changes. Defaults to 10 pixels.
minShiftGraphic: 1, // Optional threshold for pixel shifts in graphics.
compareSVGDOM: false, // Pass if SVG DOM is the same. Defaults to false.
},

// screenshot every example in maximized mode
states: require('./screener.states').default,

alwaysAcceptBaseBranch: true,
baseBranch,
failureExitCode: 0,

...(sourceBranch && sourceBranch.indexOf('refs/pull') > -1
? {
commit: getCurrentHash(),
}
: null),
};

/**
ralucapelin marked this conversation as resolved.
Show resolved Hide resolved
*
* @param {Object} options
* @param {string} options.screenerApiKey
* @param {string} options.sourceBranchName
* @returns
*/
function getConfig({ screenerApiKey, sourceBranchName }) {
// https://github.com/screener-io/screener-runner
return {
apiKey: screenerApiKey,
projectRepo: 'microsoft/fluentui/fluentui',

diffOptions: {
structure: true,
layout: true,
style: true,
content: true,
minLayoutPosition: 1, // Optional threshold for Layout changes. Defaults to 4 pixels.
minLayoutDimension: 1, // Optional threshold for Layout changes. Defaults to 10 pixels.
minShiftGraphic: 1, // Optional threshold for pixel shifts in graphics.
compareSVGDOM: false, // Pass if SVG DOM is the same. Defaults to false.
},

// screenshot every example in maximized mode
states: require('./screener.states').default,

alwaysAcceptBaseBranch: true,
baseBranch,
failureExitCode: 0,

...(sourceBranchName !== 'master'
? {
commit: getCurrentHash(),
}
: null),
};
}
module.exports = getConfig;
4 changes: 2 additions & 2 deletions scripts/screener/screener.runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ export async function screenerRunner(screenerConfig: ScreenerRunnerConfig) {
// https://github.com/microsoft/azure-pipelines-tasks/issues/9801
const commit = process.env.SYSTEM_PULLREQUEST_SOURCECOMMITID;
// https://github.com/screener-io/screener-runner/blob/2a8291fb1b0219c96c8428ea6644678b0763a1a1/src/ci.js#L101
let branchName = process.env.SYSTEM_PULLREQUEST_SOURCEBRANCH || process.env.BUILD_SOURCEBRANCHNAME;
let branchName = process.env.BUILD_SOURCEBRANCHNAME;

if (!branchName) {
throw new Error('SYSTEM_PULLREQUEST_SOURCEBRANCH or BUILD_SOURCEBRANCHNAME env variable doesnt exist');
throw new Error('BUILD_SOURCEBRANCHNAME env variable doesnt exist');
}
if (!process.env.BUILD_BUILDID) {
throw new Error('BUILD_BUILDID env variable doesnt exist');
Expand Down
8 changes: 7 additions & 1 deletion scripts/tasks/screener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import { getStorybook } from '@storybook/react';
*/
export async function screener() {
const screenerConfigPath = path.resolve(process.cwd(), './screener.config.js');
const screenerConfig: ScreenerRunnerConfig = require(screenerConfigPath);
const getConfig = require(screenerConfigPath);
const screenerConfig: ScreenerRunnerConfig = getConfig({
screenerApiKey: process.env.SCREENER_API_KEY,
sourceBranchName: process.env.BUILD_SOURCEBRANCHNAME,
deployUrl: process.env.DEPLOYURL,
targetBranch: process.env.SYSYEM_PULLREQUEST_TARGETBRANCH,
});
console.log('screener config for run:');
console.log(JSON.stringify(screenerConfig, null, 2));

Expand Down