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

ci(examples): on release please version update bump example deps #32

Merged
merged 2 commits into from
Oct 26, 2023
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
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
- [ ] linter/style run on changed files
- [ ] Tests added for new functionality
- [ ] Regression tests added for bug fixes
- [ ] Tested in a corresponding example app
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn update-examples
2 changes: 1 addition & 1 deletion examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"dependencies": {
"@openfeature/js-sdk": "^1.6.1",
"@spotify-confidence/openfeature-server-provider": "^0.0.3"
"@spotify-confidence/openfeature-server-provider": "0.0.4"
},
"scripts": {
"dev": "node src/index.js"
Expand Down
2 changes: 1 addition & 1 deletion examples/nodeCJS/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"dependencies": {
"@openfeature/js-sdk": "^1.6.1",
"@spotify-confidence/openfeature-server-provider": "^0.0.3"
"@spotify-confidence/openfeature-server-provider": "0.0.4"
},
"scripts": {
"dev": "node src/index.js"
Expand Down
4 changes: 2 additions & 2 deletions examples/react18/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"@babel/plugin-syntax-flow": "^7.22.5",
"@babel/plugin-transform-react-jsx": "^7.22.15",
"@openfeature/web-sdk": "^0.4.0",
"@spotify-confidence/integration-react": "^0.0.4",
"@spotify-confidence/openfeature-web-provider": "^0.0.3",
"@spotify-confidence/integration-react": "0.0.5",
"@spotify-confidence/openfeature-web-provider": "0.0.3",
"@testing-library/dom": "^7.29.6",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"prepare": "husky install",
"cm": "git-cz",
"release": "lerna version",
"publish-if-missing": "lerna publish from-package --yes"
"publish-if-missing": "lerna publish from-package --yes",
"update-examples": "node scripts/bump-example-deps.js"
},
"devDependencies": {
"@commitlint/cli": "^17.6.7",
Expand Down
39 changes: 39 additions & 0 deletions scripts/bump-example-deps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const glob = require('glob');
const fs = require('fs');

// load all package jsons from example dir
const exampleAppPackageJsons = glob.sync('examples/*/package.json');

// load versions of confidence packages from .release-please-manifest.json
const releasePleaseManifestJSON = JSON.parse(fs.readFileSync('.release-please-manifest.json', 'utf-8'));

// For each package in the release please manifest, find that package in the deps of all the examples and update
console.log('Checking for required updates to example app dependencies...');
for (const dep of Object.keys(releasePleaseManifestJSON)) {
for (const packageJsonPath of exampleAppPackageJsons) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
const [_, depName] = dep.split('/');

const currentPackageVersion = packageJson.dependencies[`@spotify-confidence/${depName}`];

if (!currentPackageVersion) {
continue;
}

if (currentPackageVersion === releasePleaseManifestJSON[dep]) {
console.log('No update needed for: @spotify-confidence/%s in %s', depName, packageJson.name);
continue;
}

packageJson.dependencies[`@spotify-confidence/${depName}`] = releasePleaseManifestJSON[dep];
fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`);
Billlynch marked this conversation as resolved.
Show resolved Hide resolved
console.log(
'Updated @spotify-confidence/%s in %s. %s -> %s',
depName,
packageJson.name,
currentPackageVersion,
releasePleaseManifestJSON[dep],
);
}
}
console.log('Done updating example apps.');
Loading