Skip to content

Commit

Permalink
fix(PPDSC-2611): Revert "chore(PPDSC-2611): fewer tests for baseline …
Browse files Browse the repository at this point in the history
…updates (#588)"

This reverts commit fd4d458.
  • Loading branch information
mstuartf committed Feb 20, 2023
1 parent 6a9384e commit 438b5f6
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 166 deletions.
40 changes: 18 additions & 22 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -803,17 +803,15 @@ jobs:
- run:
name: 'Check if updates required'
command: |
export PR_BRANCH_NAME=$(gh pr list --search $CIRCLE_SHA1 --state merged --json headRefName --jq '.[].headRefName')
echo "Found branch name: ${PR_BRANCH_NAME}"
export PERCY_TOKEN=$PERCY_COMPS_TOKEN
export UPDATES_REQUIRED=$(npx -y run-func scripts/check-baseline-updates.js run $PR_BRANCH_NAME)
if [ $UPDATES_REQUIRED = "true" ]; then
echo "Baseline updates required; continuing job."
export PERCY_PARTIAL_BUILD=1
else
echo "No baseline updates required; finishing job." &&
circleci-agent step halt
fi
{
export PR_BRANCH_NAME=$(gh pr list --search $CIRCLE_SHA1 --state merged --json headRefName --jq '.[].headRefName') &&
echo "Found branch name: ${PR_BRANCH_NAME}" &&
node scripts/check-baseline-updates.js $PR_BRANCH_NAME "comps" &&
echo "No baseline updates required; finishing job." &&
circleci-agent step halt
} || {
echo "Baseline updates required; continuing job."
}
- run_test_visual_comps_percy
- slack/notify:
<<: *slack_notify
Expand All @@ -828,17 +826,15 @@ jobs:
- run:
name: 'Check if updates required'
command: |
export PR_BRANCH_NAME=$(gh pr list --search $CIRCLE_SHA1 --state merged --json headRefName --jq '.[].headRefName')
echo "Found branch name: ${PR_BRANCH_NAME}"
export PERCY_TOKEN=$PERCY_COMPS_TOKEN
export UPDATES_REQUIRED=$(npx -y run-func scripts/check-baseline-updates.js run $PR_BRANCH_NAME)
if [ $UPDATES_REQUIRED = "true" ]; then
echo "Baseline updates required; continuing job."
export PERCY_PARTIAL_BUILD=1
else
echo "No baseline updates required; finishing job." &&
circleci-agent step halt
fi
{
export PR_BRANCH_NAME=$(gh pr list --search $CIRCLE_SHA1 --state merged --json headRefName --jq '.[].headRefName') &&
echo "Found branch name: ${PR_BRANCH_NAME}" &&
node scripts/check-baseline-updates.js $PR_BRANCH_NAME "docsite" &&
echo "No baseline updates required; finishing job." &&
circleci-agent step halt
} || {
echo "Baseline updates required; continuing job."
}
- run_test_visual_docs_percy
- slack/notify:
<<: *slack_notify
Expand Down
6 changes: 1 addition & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module.exports = {
projects: [
'<rootDir>/src/jest.config.js',
'<rootDir>/site/jest.config.js',
'<rootDir>/scripts/jest.config.js',
],
projects: ['<rootDir>/src/jest.config.js', '<rootDir>/site/jest.config.js'],
coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/test'],
coverageReporters: ['lcov', 'text-summary'],
collectCoverage: true,
Expand Down
1 change: 0 additions & 1 deletion percy-storybook.config.json

This file was deleted.

2 changes: 0 additions & 2 deletions percy.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const SKIP_GITHUB_CHECK = process.env.SKIP_PERCY_CHECK === 'true';
const storybookConfig = require('./percy-storybook.config.json');

module.exports = {
version: 2,
snapshot: {
widths: [375, 1280],
},
storybook: {
...storybookConfig,
...(SKIP_GITHUB_CHECK ? {include: 'skip-percy-tests'} : {}),
},
};
99 changes: 0 additions & 99 deletions scripts/__tests__/check-baseline-updates.test.js

This file was deleted.

50 changes: 18 additions & 32 deletions scripts/check-baseline-updates.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#!/usr/bin/env node
const https = require('https');
const fs = require('fs');

const PERCY_URL = 'https://percy.io';

const CONFIG_FILE = 'percy-storybook.config.json';
const PERCY_URL = 'https://percy.io/api/v1';

const log = value => process.stdout.write(`${value}\n`);

Expand All @@ -24,20 +21,16 @@ function apiCall(url, options) {
});
}

function percyApiCall(path) {
const token = process.env.PERCY_TOKEN;
async function getPercyBuildForBranch(branchName, project) {
log(`Looking for Percy ${project} build for branch ${branchName}`);
const token = process.env[`PERCY_${project.toUpperCase()}_TOKEN`];
if (!token) {
log(`No Percy token found`);
log(`No Percy token found for project ${project}`);
throw Error();
}
return apiCall(`${PERCY_URL}${path}`, {
const builds = await apiCall(`${PERCY_URL}/builds`, {
headers: {Authorization: `Token ${token}`},
});
}

async function getPercyBuildForBranch(branchName) {
log(`Looking for Percy build for branch ${branchName}`);
const builds = await percyApiCall('/api/v1/builds');
for (let i = 0; i <= builds.data.length; i++) {
const build = builds.data[i];
if (build.attributes.branch === branchName) {
Expand All @@ -48,33 +41,26 @@ async function getPercyBuildForBranch(branchName) {
throw Error();
}

async function run(headRefName) {
async function checkIfBaselineUpdatesRequired(headRefName, project) {
const branchName = headRefName.trim();
log(`Checking if baselines to be updated after ${branchName} was merged`);
log(
`Checking if baselines for ${project} need to be updated after ${branchName} was merged`,
);

const build = await getPercyBuildForBranch(branchName);
const build = await getPercyBuildForBranch(branchName, project);
const reviewState = build.attributes['review-state'];
const nbDiffs = build.attributes['total-comparisons-diff'];

log(`Build is in state ${reviewState} with ${nbDiffs} diffs`);
if (reviewState !== 'approved' || !nbDiffs) {
log(`No diffs requiring updates`);
return false;
throw Error();
}

const snapshots = await percyApiCall(
build.relationships.snapshots.links.related,
);

const include = snapshots.data
.filter(
({attributes}) => attributes['review-state-reason'] === 'user_approved',
)
.map(({attributes: {name}}) => `^${name}$`);

fs.writeFileSync(`./${CONFIG_FILE}`, JSON.stringify({include}));

return true;
}

module.exports = {run};
// this script fails if updates are required
const headRefName = process.argv[2];
const project = process.argv[3];
checkIfBaselineUpdatesRequired(headRefName, project)
.then(() => process.exit(1))
.catch(() => process.exit(0));
5 changes: 0 additions & 5 deletions scripts/jest.config.js

This file was deleted.

0 comments on commit 438b5f6

Please sign in to comment.