Skip to content

Commit

Permalink
chore: add multi-gitter script for auto upgrading repos
Browse files Browse the repository at this point in the history
  • Loading branch information
kabaros committed Oct 21, 2024
1 parent 93ccf76 commit 1fd217b
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
8 changes: 8 additions & 0 deletions multi-gitter/README.md
Original file line number Diff line number Diff line change
@@ -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`
16 changes: 16 additions & 0 deletions multi-gitter/config.yml
Original file line number Diff line number Diff line change
@@ -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

77 changes: 77 additions & 0 deletions multi-gitter/script.js
Original file line number Diff line number Diff line change
@@ -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' })

0 comments on commit 1fd217b

Please sign in to comment.