Skip to content

Commit

Permalink
Fix/ppdsc 2611 revert (#656)
Browse files Browse the repository at this point in the history
* fix(PPDSC-2611): Revert "Fix/ppdsc 2611 fix 1 (#629)"

This reverts commit 7ee4a68.

* fix(PPDSC-2611): Revert "fix(PPDSC-2611): fix pipeline (#596)"

This reverts commit 1c001a9.

* fix(PPDSC-2611): Revert "chore(PPDSC-2611): fewer tests for baseline updates (#588)"

This reverts commit fd4d458.
  • Loading branch information
mstuartf authored Feb 21, 2023
1 parent 85682f1 commit 9bdd5ab
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 203 deletions.
54 changes: 18 additions & 36 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -803,24 +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 CHECK_UPDATES=$(npx -y run-func scripts/check-baseline-updates.js run $PR_BRANCH_NAME)
echo "Result from check-baseline-updates.js: ${CHECK_UPDATES}"
if [ $CHECK_UPDATES = "UPDATES_REQUIRED" ]; then
echo "Baseline updates required; continuing job."
echo 'export PERCY_PARTIAL_BUILD=1' >> "$BASH_ENV"
elif [ $CHECK_UPDATES = "NO_UPDATES_REQUIRED" ]; then
echo "No baseline updates required; finishing job."
circleci-agent step halt
else
echo "Error checking PR"
exit 1
fi
- run:
name: 'Confirm partial build'
command: echo "PERCY_PARTIAL_BUILD is set to ${PERCY_PARTIAL_BUILD}"
{
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 @@ -835,24 +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_DOCSITE_TOKEN
export CHECK_UPDATES=$(npx -y run-func scripts/check-baseline-updates.js run $PR_BRANCH_NAME)
echo "Result from check-baseline-updates.js: ${CHECK_UPDATES}"
if [ $CHECK_UPDATES = "UPDATES_REQUIRED" ]; then
echo "Baseline updates required; continuing job."
echo 'export PERCY_PARTIAL_BUILD=1' >> "$BASH_ENV"
elif [ $CHECK_UPDATES = "NO_UPDATES_REQUIRED" ]; then
echo "No baseline updates required; finishing job."
circleci-agent step halt
else
echo "Error checking PR"
exit 1
fi
- run:
name: 'Confirm partial build'
command: echo "PERCY_PARTIAL_BUILD is set to ${PERCY_PARTIAL_BUILD}"
{
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'} : {}),
},
};
101 changes: 0 additions & 101 deletions scripts/__tests__/check-baseline-updates.test.js

This file was deleted.

76 changes: 23 additions & 53 deletions scripts/check-baseline-updates.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
#!/usr/bin/env node
const https = require('https');
const fs = require('fs');

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

const CONFIG_FILE = 'percy-storybook.config.json';

// Use stderr to stop logs being returned to parent process
const log = value => process.stderr.write(`${value}\n`);

const RESPONSES = {
ERROR: 'ERROR',
UPDATES_REQUIRED: 'UPDATES_REQUIRED',
NO_UPDATES_REQUIRED: 'NO_UPDATES_REQUIRED',
};
const log = value => process.stdout.write(`${value}\n`);

function apiCall(url, options) {
return new Promise((resolve, reject) => {
Expand All @@ -31,66 +21,46 @@ 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) {
throw Error(`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++) {
for (let i = 0; i <= builds.data.length; i++) {
const build = builds.data[i];
if (build.attributes.branch === branchName) {
return build;
}
}
throw Error(`No Percy build found for branch ${branchName}`);
log(`No Percy build found for branch ${branchName}`);
throw Error();
}

async function checkUpdates(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}$`);

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

return true;
}

const run = async headRefName =>
checkUpdates(headRefName)
.then(res =>
res ? RESPONSES.UPDATES_REQUIRED : RESPONSES.NO_UPDATES_REQUIRED,
)
.catch(err => {
log(err);
return RESPONSES.ERROR;
});

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 9bdd5ab

Please sign in to comment.