From 1fd217b357b7536c131e2ecda2ae73eeadf08751 Mon Sep 17 00:00:00 2001 From: Mozafar Haider Date: Mon, 21 Oct 2024 18:59:33 +0100 Subject: [PATCH] chore: add multi-gitter script for auto upgrading repos --- multi-gitter/README.md | 8 +++++ multi-gitter/config.yml | 16 +++++++++ multi-gitter/script.js | 77 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 multi-gitter/README.md create mode 100644 multi-gitter/config.yml create mode 100644 multi-gitter/script.js diff --git a/multi-gitter/README.md b/multi-gitter/README.md new file mode 100644 index 00000000..cfdd94cd --- /dev/null +++ b/multi-gitter/README.md @@ -0,0 +1,8 @@ +# PoC for multi-gitter + +PoC for using [multi-gitter](https://github.com/lindell/multi-gitter) to do bulk upgrade over multiple repos + +## Steps +1. install multi-gitter as [described in the repo](https://github.com/lindell/multi-gitter?tab=readme-ov-file#install) +1. update the `config.yml` as you see fit (i.e. to include certain repos) +1. run `multi-gitter run "node $PWD/script.js" --config ./config.yml` \ No newline at end of file diff --git a/multi-gitter/config.yml b/multi-gitter/config.yml new file mode 100644 index 00000000..2db99551 --- /dev/null +++ b/multi-gitter/config.yml @@ -0,0 +1,16 @@ +commit-message: "fix(app-platform): upgrade platform tools to use vite and react 18" +repo: # this could be replaced by a regex that targets all repos containing "-app" + - dhis2/maintenance-app-beta + - dhis2/scheduler-app + - dhis2/login-app + - dhis2/dashboard-app + - dhis2/maps-app + - dhis2/data-exchange-app +draft: true +clone-dir: . +# token: GITHUB_TOKEN +log-level: debug +branch: upgrade-vite-react +conflict-strategy: replace +pr-body: This is a test PR to see if we can automate upgrading app-platform + diff --git a/multi-gitter/script.js b/multi-gitter/script.js new file mode 100644 index 00000000..c4a5a21f --- /dev/null +++ b/multi-gitter/script.js @@ -0,0 +1,77 @@ +/** + * script to be run on all repos to upgrade to the latest version of app-platform tools + * which uses Vite and upgrades to React 18 + */ + +const { execSync } = require('child_process') +const path = require('path') + +const packageFile = require(path.join(process.cwd(), './package.json')) + +const dependencies = [ + ...Object.keys(packageFile.dependencies), + ...Object.keys(packageFile.devDependencies), +] + +console.info('upgrading cli-app-scripts') +execSync('yarn add --dev "@dhis2/cli-app-scripts@alpha"', { stdio: 'inherit' }) + +console.info('upgrading cli-style') +execSync('yarn add --dev "@dhis2/cli-style@alpha"', { stdio: 'inherit' }) + +console.info('upgrading the UI library') +execSync('yarn add --dev "@dhis2/ui"', { stdio: 'inherit' }) // get the latest version to avoid warnings about defaultProps in React 18 + +console.info('Run migration script from d2-app-scripts') +execSync('yarn d2-app-scripts migrate js-to-jsx', { stdio: 'inherit' }) + +console.info('Deduping dependencies') +execSync('npx yarn-deduplicate yarn.lock && yarn', { stdio: 'inherit' }) + +if (dependencies.includes('@testing-library/react')) { + console.info('upgrading @testing-library/react') + execSync('yarn add @testing-library/react', { stdio: 'inherit' }) +} + +if (dependencies.includes('@testing-library/user-event')) { + console.info('upgrading @testing-library/user-event') + execSync('yarn add @testing-library/user-event', { stdio: 'inherit' }) +} + +if (dependencies.includes('@testing-library/jest-dom')) { + console.info('upgrading @testing-library/jest-dom') + execSync('yarn add @testing-library/jest-dom', { stdio: 'inherit' }) +} + +if (dependencies.includes('@testing-library/react-hooks')) { + console.info('removing @testing-library/react-hooks') + execSync('yarn remove @testing-library/react-hooks', { stdio: 'inherit' }) + // ToDo: next do a codemod to upgrade uses of old react-hooks + // ! this is a naive version of such a codemod + execSync( + `find ./src -type f -exec sed -i "s#import { renderHook } from '@testing-library/react-hooks'#import { renderHook } from '@testing-library/react'#g" {} \\;`, + { stdio: 'inherit' } + ) +} + +if (dependencies.includes('enzyme-adapter-react-16')) { + console.info( + 'replace enzyme-adapter-react-16 with @cfaester/enzyme-adapter-react-18' + ) + execSync('yarn remove enzyme-adapter-react-16', { + stdio: 'inherit', + }) + execSync('yarn add --dev @cfaester/enzyme-adapter-react-18', { + stdio: 'inherit', + }) + + execSync( + `find ./src -type f -exec sed -i "s#enzyme-adapter-react-16#@cfaester/enzyme-adapter-react-18#g" {} \\;`, + { stdio: 'inherit' } + ) +} +// ToDo: run codemod for changing default props?? + +// ToDo: what to do about resolutions in package.json? + +execSync('npx yarn-deduplicate yarn.lock && yarn', { stdio: 'inherit' })