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

Refreshed and improved, glitchless edition #148

Merged
merged 8 commits into from
Oct 21, 2024
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Options:
-d, --default-config, --default Override update-node configuration
default path [boolean]
-c, --clean Run on a clean state [boolean]
--sync-lock Run npm install or yarn after patching
package.json (default, disable with
--no-sync-lock) [boolean] [default: true]
-b, --pre-commit-bump-command Command to run before to commit (changes
will be commited) [array]
-p, --pre-clean-command Run before to clean state [array]
-P, --post-clean-command Run on a clean state [array]
-f, --force Git Push with force changes
Expand Down
65 changes: 33 additions & 32 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
"semver": "^7.6.3",
"split2": "^3.2.2",
"through2": "^4.0.2",
"yaml": "^2.5.1",
"yaml": "^2.6.0",
"yargs": "^17.7.2"
},
"devDependencies": {
"@coorpacademy/eslint-plugin-coorpacademy": "14.0.0",
"ava": "^5.3.1",
"eslint": "^8.57.0",
"eslint": "^8.57.1",
"nyc": "^17.1.0"
}
}
1 change: 1 addition & 0 deletions scripts/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -e
echo "> Linking update-node"
npm link
echo
export NVM_DIR="$(realpath "$(dirname "$0")/../test/integration")"

cd test/integration
if [ -d .git ]; then
Expand Down
12 changes: 11 additions & 1 deletion src/bump-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ const {
} = require('./updatees/package');
const updateDockerfile = require('./updatees/dockerfile');
const {commitFiles, currentUser} = require('./core/git');
const {executeScript} = require('./core/script');
const {syncGithub} = require('./core/github');
const {findLatest} = require('./core/node');
const {makeError, formatEventualSuffix} = require('./core/utils');

const LOAD_NVM = '. ${NVM_DIR:-$HOME/.nvm}/nvm.sh && nvm use'; // eslint-disable-line no-template-curly-in-string

const bumpNodeVersion = async (latestNode, config) => {
process.stdout.write(c.bold.blue(`\n\n⬆️ About to bump node version:\n`));
const {exact, loose} = config.node;
const {scope} = config.argv;
const {scope, preCommitBumpCommand, syncLock} = config.argv;
const nodeVersion = _.trimCharsStart('v', latestNode.version);
await Promise.all([
updateServerless(nodeVersion, config.node.serverless),
Expand All @@ -32,6 +35,13 @@ const bumpNodeVersion = async (latestNode, config) => {
updateDockerfile(nodeVersion, config.node.dockerfile),
config.lernaMonorepo && updateLearnaPackageEngines(nodeVersion, latestNode.npm, {exact, loose})
]);
// Post commands to synchronise the package-lock.json
if (syncLock)
await executeScript([
LOAD_NVM,
config.packageManager === 'npm' ? 'npm install' : 'yarn --ignore-engines --ignore-scripts'
]);
if (!_.isEmpty(preCommitBumpCommand)) await executeScript([LOAD_NVM, ...preCommitBumpCommand]);

const messageSuffix = formatEventualSuffix(config.argv.message);

Expand Down
15 changes: 6 additions & 9 deletions src/bump-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const main = async config => {
if (!config.local)
await pushFiles('master', config.token, config.repoSlug, {
tags: true,
forceFlag: config.forceFlag
forceFlag: '--force'
});
process.stdout.write(c.bold.green(`Successfully made a ${releaseType} release\n`));
if (autoBumpConfig.publish || autoBumpConfig['publish-command']) {
Expand All @@ -119,15 +119,12 @@ const main = async config => {
if (autoBumpConfig['merge-branch']) {
const branch = autoBumpConfig['merge-branch'];
await executeScript([
`git config remote.gh.url >/dev/null || git remote add gh https://${config.token}@github.com/${config.repoSlug}.git`
]);
await executeScript([
`git fetch gh && git checkout -B ${branch} gh/${branch} && git merge master`
]);
await executeScript([
`git push gh ${branch}:refs/heads/${branch} || (git remote remove gh && exit 12)`
`git config remote.gh.url >/dev/null || git remote add gh https://${config.token}@github.com/${config.repoSlug}.git`,
`git fetch gh && git checkout -B ${branch} gh/${branch} && git merge master`,
`git push gh ${branch}:refs/heads/${branch} || (git remote remove gh && exit 12)`,
'git remote remove gh'
]);
await executeScript(['git remote remove gh']);

process.stdout.write(c.bold.green(`Successfully merged branch ${branch}\n`));
}
};
Expand Down
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@
boolean: true,
alias: 'c'
})
.option('sync-lock', {
describe:
'Run npm install or yarn after patching package.json (default, disable with --no-sync-lock)',
boolean: true,
default: true
})
.option('pre-commit-bump-command', {
describe: 'Command to run before to commit (changes will be commited)',
string: true,
alias: 'b',
array: true
})
.option('pre-clean-command', {
describe: 'Run before to clean state',
string: true,
Expand Down Expand Up @@ -203,7 +215,7 @@
error.exitCode = 22;
throw error;
}
// FIXME perform schema validation

Check warning on line 218 in src/index.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected 'fixme' comment: 'FIXME perform schema validation'

Check warning on line 218 in src/index.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected 'fixme' comment: 'FIXME perform schema validation'

Check warning on line 218 in src/index.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Unexpected 'fixme' comment: 'FIXME perform schema validation'

Check warning on line 218 in src/index.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected 'fixme' comment: 'FIXME perform schema validation'

Check warning on line 218 in src/index.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected 'fixme' comment: 'FIXME perform schema validation'

Check warning on line 218 in src/index.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Unexpected 'fixme' comment: 'FIXME perform schema validation'
const mainArg =
commandType === 'config'
? config || (await getConfig(argv)) // do not recompute config if already done
Expand Down
2 changes: 1 addition & 1 deletion src/updatees/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
const getSemverPrefix = _.pipe(s => s && s.match(/^(\D*)\d+/), _.at(1));

const updatePackageEngines = async (node, npm, pkg, {exact = false, loose = true}) => {
// TODO: maybe support forcing the choice of prefix (example, to restore loose range like >=)

Check warning on line 27 in src/updatees/package.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected 'todo' comment: 'TODO: maybe support forcing the choice...'

Check warning on line 27 in src/updatees/package.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected 'todo' comment: 'TODO: maybe support forcing the choice...'

Check warning on line 27 in src/updatees/package.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Unexpected 'todo' comment: 'TODO: maybe support forcing the choice...'

Check warning on line 27 in src/updatees/package.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected 'todo' comment: 'TODO: maybe support forcing the choice...'

Check warning on line 27 in src/updatees/package.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected 'todo' comment: 'TODO: maybe support forcing the choice...'

Check warning on line 27 in src/updatees/package.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Unexpected 'todo' comment: 'TODO: maybe support forcing the choice...'
if (_.isArray(pkg)) return pMap(pkg, p => updatePackageEngines(node, npm, p, {exact, loose}));

if (!pkg) return;
Expand Down Expand Up @@ -93,7 +93,7 @@
process.stdout.write(`+ Updating dependencies lock with ${c.bold.yellow(packageManager)} 🔐 :\n`);

await executeScript([
packageManager === 'npm' ? 'npm install' : 'yarn --ignore-engines --ignore-scripts ',
packageManager === 'npm' ? 'npm install' : 'yarn --ignore-engines --ignore-scripts',
'echo "Updated Locks"'
]);
};
Expand Down
5 changes: 5 additions & 0 deletions test/integration/nvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

nvm () {
echo nope nope
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:trollface:

}
Loading