Skip to content

Commit

Permalink
ci: calling pre and post commands inside main for new yarn (#5093)
Browse files Browse the repository at this point in the history
* ci: calling pre and post commands inside main for new yarn

* chore: add build artifacts verification step

* chore: update script to trigger husky

* chore: address PR feedback

---------

Co-authored-by: Rajdeep Chandra <rajdeepchandra@Rajdeeps-MacBook-Pro-2.local>
Co-authored-by: Ruben Carvalho <rcarvalho@adobe.com>
  • Loading branch information
3 people authored Feb 13, 2025
1 parent e7c6610 commit 5c1d532
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 6 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"icons": "wireit",
"icons:ui": "wireit",
"icons:workflow": "wireit",
"lerna-publish": "lerna publish --message \"chore: release new versions #publish\" --force-publish",
"lerna-publish": "yarn prelerna-publish && lerna publish --message \"chore: release new versions #publish\" --force-publish && yarn post lerna-publish",
"lint": "run-p lint:js lint:docs lint:ts lint:css lint:packagejson",
"lint:css": "stylelint \"packages/**/*.css\" \"tools/**/*.css\"",
"lint:docs": "eslint -f pretty \"projects/documentation/**/*.ts\"",
Expand All @@ -48,12 +48,12 @@
"new-package": "cd projects/templates && plop",
"postcustom-element-json": "lerna exec --ignore \"{@spectrum-web-components/{base,bundle,clear-button,close-button,iconset,modal,shared,opacity-checkerboard,styles,custom-vars-viewer,reactive-controllers,vrt-compare,eslint-plugin},stylelint-header,@swc-react/*,documentation,example-project-rollup,example-project-webpack,swc-templates,@types/swc}\" -- node ../../tasks/check-cem.js",
"postdocs:analyze": "node ./scripts/add-custom-properties.js --src=\"projects/documentation/custom-elements.json\"",
"postinstall": "patch-package && yarn get-ready",
"postinstall": "husky && patch-package && yarn get-ready",
"postlerna-publish": "yarn publish:react",
"postpublish:react": "git reset --hard HEAD^ && git prune",
"precustom-element-json": "lerna exec --ignore \"{@spectrum-web-components/{base,bundle,iconset,modal,shared,opacity-checkerboard,styles,custom-vars-viewer,reactive-controllers,eslint-plugin},stylelint-header,@swc-react/*,documentation,example-project-rollup,example-project-webpack,swc-templates,@types/swc}\" -- rm custom-elements.json ||:",
"preeleventy": "yarn docs:analyze",
"prelerna-publish": "rimraf react && yarn get-ready && yarn custom-element-json && yarn build:confirm",
"prelerna-publish": "rimraf react && yarn get-ready && yarn custom-element-json && yarn verify-build-artifacts && yarn build:confirm",
"prepare": "husky",
"prepublish:react": "yarn build:react && sed -i \"\" \"s/react/# react/g\" .gitignore && git commit -am \"Commit React Wrappers\" --no-verify",
"prestorybook": "wireit",
Expand All @@ -62,7 +62,7 @@
"pretest:visual": "yarn build && yarn build",
"process-icons": "wireit",
"process-spectrum": "wireit",
"publish:react": "lerna publish from-package --message \"chore: release new Reach Wrapper versions #publish\"",
"publish:react": "yarn prepublish:react && lerna publish from-package --message \"chore: release new Reach Wrapper versions #publish\" & yarn postpublish:react",
"spectrum-css": "wireit",
"spectrum-tokens": "wireit",
"spectrum-vars": "wireit",
Expand Down Expand Up @@ -91,7 +91,8 @@
"update:spectrum-css:cleanup": "yarn lint:packagejson && yarn --ignore-scripts && yarn process-spectrum",
"update:spectrum-css:nonbreaking": "node ./scripts/update-spectrum-css.js || yarn update:spectrum-css:cleanup",
"vrt:preview": "yarn wds --config test/visual/wds-vrt.config.js",
"vrt:quick-link": "yarn netlify deploy --alias=vrt --dir=projects/vrt-quick-link"
"vrt:quick-link": "yarn netlify deploy --alias=vrt --dir=projects/vrt-quick-link",
"verify-build-artifacts": "node ./scripts/verify-build-artifacts.js"
},
"peerDependencies": {
"common-tags": "^1.8.0"
Expand Down
147 changes: 147 additions & 0 deletions scripts/verify-build-artifacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
Copyright 2025 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

import fs from 'fs';
import path from 'path';
import glob from 'fast-glob';
import 'colors';

async function verifyCustomElementsJson() {
// Components that don't need their own custom-elements.json manifest
const customElementsIgnoreList = new Set([
'packages/modal',
'packages/iconset',
'packages/clear-button',
'packages/close-button',
]);

const packages = glob.sync('packages/*/', { onlyDirectories: true });
const checks = packages.map(async (pkg) => {
const pkgPath = pkg.replace(/\/$/, '');
if (customElementsIgnoreList.has(pkgPath)) {
return;
}
const customElementsPath = path.join(pkg, 'custom-elements.json');
if (!fs.existsSync(customElementsPath)) {
throw new Error(`Missing custom-elements.json in ${pkg}`);
}
});
await Promise.all(checks);
}

function verifyVersionJs() {
let basePackageJson;
try {
basePackageJson = JSON.parse(
fs.readFileSync('tools/base/package.json', 'utf8')
);
} catch (error) {
throw new Error('Failed to read tools/base/package.json');
}
const versionJsPath = 'tools/base/src/version.js';

if (!fs.existsSync(versionJsPath)) {
throw new Error('version.js file is missing');
}

const versionContent = fs.readFileSync(versionJsPath, 'utf8');
const versionMatch = versionContent.match(/version = ['"]([^'"]+)['"]/);

if (!versionMatch) {
throw new Error('Could not find version in version.js');
}

const versionJs = versionMatch[1];
if (versionJs !== basePackageJson.version) {
throw new Error(
`Version mismatch: version.js (${versionJs}) does not match tools/base/package.json (${basePackageJson.version})`
);
}
}

async function verifyBuildArtifacts() {
const packages = glob.sync('packages/*/', { onlyDirectories: true });
const requiredFilesIgnoreList = new Set([
'packages/clear-button', // extends button
'packages/close-button', // extends button
'packages/search-button', // extends button
'packages/icons-ui', // extends icon
'packages/icons-workflow', // extends icon
'packages/iconset', // extends icon
'packages/modal', // extends dialog
]);

// Required files for each package
const requiredFiles = [
['src/index.js', 'main compiled JS file'],
['src/index.dev.js', 'dev build file'],
['src/*.d.ts', 'TypeScript declaration files'],
['sp-*.js', 'component definition file'],
['sp-*.dev.js', 'dev component definition file'],
['sp-*.d.ts', 'component definition type file'],
];

const checks = packages.map(async (pkg) => {
const pkgPath = pkg.replace(/\/$/, '');

const srcPath = path.join(pkg, 'src');
if (!fs.existsSync(srcPath)) {
throw new Error(`Missing src directory in ${pkg}`);
}

// Check if src directory is empty
const srcFiles = fs.readdirSync(srcPath);
if (srcFiles.length === 0) {
throw new Error(`src directory is empty in ${pkg}`);
}

if (requiredFilesIgnoreList.has(pkgPath)) {
return;
}

// Verify all required files exist for this package
for (const [filePattern, description] of requiredFiles) {
const pattern = path.join(pkg, filePattern);
const files = glob.sync(pattern);
if (files.length === 0) {
throw new Error(
`Missing ${description} in ${pkg} (pattern: ${filePattern})`
);
}
}
});
await Promise.all(checks);
}

async function main() {
try {
console.log('Verifying custom-elements.json files...'.cyan);
await verifyCustomElementsJson();

console.log('Verifying version.js...'.cyan);
verifyVersionJs();

console.log('Verifying build artifacts...'.cyan);
await verifyBuildArtifacts();

console.log('All build artifacts verified successfully'.green.bold);
process.exit(0);
} catch (error) {
console.error(
'Build artifact verification failed:'.red.bold,
error.message.red
);
process.exit(1);
}
}

main();
2 changes: 1 addition & 1 deletion tools/base/src/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5c1d532

Please # to comment.