Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: run the update example deps script in master and not in ci (#3515)
Browse files Browse the repository at this point in the history
Do the work all in the js script, not half in js and half in the npm
script.
  • Loading branch information
achingbrain authored Jan 30, 2021
1 parent ba240fd commit 7e188f2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"release:post:remove-hoisted-modules": "json -I -f ./lerna.json -e \"delete this.command.bootstrap.nohoist\"",
"release:post:remove-examples": "json -I -f ./lerna.json -e \"this.packages = this.packages.filter(p => !p.includes('examples'))\"",
"release:post:revert-ignore-changes-to-lerna-config": "git update-index --no-assume-unchanged ./lerna.json",
"release:post:update-example-dependencies": "node scripts/update-example-deps.js && git add examples && git commit -m 'chore: updated example dependencies' && git push",
"release:post:update-example-dependencies": "node scripts/update-example-deps.js",
"release:rc": "run-s release:pre:* release:canary release:post:*",
"release:canary": "lerna publish --canary --preid rc --dist-tag next --force-publish --yes",
"docker:rc": "run-s docker:rc:*",
Expand All @@ -57,6 +57,7 @@
"docker:rc:push-rc": "docker push ipfs/js-ipfs:v`npm show ipfs@next version -q`"
},
"devDependencies": {
"execa": "^5.0.0",
"json": "^10.0.0",
"lerna": "^3.22.0",
"npm-run-all": "^4.1.5",
Expand Down
36 changes: 35 additions & 1 deletion scripts/update-example-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const path = require('path')
const fs = require('fs')
const execa = require('execa')

// Where an example depends on `"ipfs": "^0.51.0"` and we've just released `ipfs@0.52.0`,
// go through all of the examples and update the version to `"ipfs": "^0.52.0"` - do
Expand All @@ -12,6 +13,22 @@ const EXAMPLES_DIR = path.resolve(__dirname, '../examples')
const DEP_TYPES = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']

async function main () {
const {
stdout: branch
} = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'])

if (branch !== 'master') {
console.info(`Not running on branch ${branch}`)
return
}

if (process.env.CI) {
console.info('Not running in CI')
return
}

console.info('Running on branch', branch)

for (const dir of fs.readdirSync(PACKAGES_DIR)) {
const projectPkgPath = path.resolve(PACKAGES_DIR, dir, 'package.json')

Expand Down Expand Up @@ -45,9 +62,26 @@ async function main () {
}
}
}

await execa('git', ['add', 'examples'])

const {
stdout: updated
} = await execa('git', ['status', '--porcelain'])

console.info(updated)

if (!updated.match(/^M\s+examples/g)) {
console.info('No examples were updated')
return
}

console.info('Pushing updated dependencies')
await execa('git', ['commit', '-m', '"chore: updated example dependencies"'])
await execa('git', ['push'])
}

main().catch(err => {
console.error(err)
process.exit(1)
})
})

0 comments on commit 7e188f2

Please sign in to comment.