-
Notifications
You must be signed in to change notification settings - Fork 31
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
Feat: Create Plugin updates as migrations #1479
Open
jackw
wants to merge
2
commits into
main
Choose a base branch
from
updates-as-migrations-pt1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,4 @@ playwright/.auth | |
|
||
# Used in CI to pass built packages to the next job | ||
packed-artifacts/ | ||
.mise.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,49 @@ | ||
import chalk from 'chalk'; | ||
import minimist from 'minimist'; | ||
import { UDPATE_CONFIG } from '../constants.js'; | ||
import { printBlueBox, printRedBox } from '../utils/utils.console.js'; | ||
import { getOnlyExistingInCwd, removeFilesInCwd } from '../utils/utils.files.js'; | ||
import { standardUpdate } from './update.standard.command.js'; | ||
import { migrationUpdate } from './update.migrate.command.js'; | ||
import { isGitDirectory, isGitDirectoryClean } from '../utils/utils.git.js'; | ||
import { updateGoSdkAndModules } from '../utils/utils.goSdk.js'; | ||
import { updateNpmScripts, updatePackageJson } from '../utils/utils.npm.js'; | ||
import { getPackageManagerFromUserAgent } from '../utils/utils.packageManager.js'; | ||
import { isPluginDirectory, updateDotConfigFolder } from '../utils/utils.plugin.js'; | ||
import { getGrafanaRuntimeVersion, getVersion } from '../utils/utils.version.js'; | ||
import { printRedBox } from '../utils/utils.console.js'; | ||
import chalk from 'chalk'; | ||
import { isPluginDirectory } from '../utils/utils.plugin.js'; | ||
|
||
export const update = async (argv: minimist.ParsedArgs) => { | ||
const { packageManagerName } = getPackageManagerFromUserAgent(); | ||
try { | ||
if (!(await isGitDirectory()) && !argv.force) { | ||
printRedBox({ | ||
title: 'You are not inside a git directory', | ||
content: `In order to proceed please run "git init" in the root of your project and commit your changes.\n | ||
if (!(await isGitDirectory()) && !argv.force) { | ||
printRedBox({ | ||
title: 'You are not inside a git directory', | ||
content: `In order to proceed please run "git init" in the root of your project and commit your changes.\n | ||
(This check is necessary to make sure that the updates are easy to revert and don't mess with any changes you currently have. | ||
In case you want to proceed as is please use the ${chalk.bold('--force')} flag.)`, | ||
}); | ||
}); | ||
|
||
process.exit(1); | ||
} | ||
process.exit(1); | ||
} | ||
|
||
if (!(await isGitDirectoryClean()) && !argv.force) { | ||
printRedBox({ | ||
title: 'Please clean your repository working tree before updating.', | ||
subtitle: '(Commit your changes or stash them.)', | ||
content: `(This check is necessary to make sure that the updates are easy to revert and don't mess with any changes you currently have. | ||
if (!(await isGitDirectoryClean()) && !argv.force) { | ||
printRedBox({ | ||
title: 'Please clean your repository working tree before updating.', | ||
subtitle: '(Commit your changes or stash them.)', | ||
content: `(This check is necessary to make sure that the updates are easy to revert and don't mess with any changes you currently have. | ||
In case you want to proceed as is please use the ${chalk.bold('--force')} flag.)`, | ||
}); | ||
|
||
process.exit(1); | ||
} | ||
|
||
if (!isPluginDirectory() && !argv.force) { | ||
printRedBox({ | ||
title: 'Are you inside a plugin directory?', | ||
subtitle: 'We couldn\'t find a "src/plugin.json" file under your current directory.', | ||
content: `(Please make sure to run this command from the root of your plugin folder. In case you want to proceed as is please use the ${chalk.bold( | ||
'--force' | ||
)} flag.)`, | ||
}); | ||
}); | ||
|
||
process.exit(1); | ||
} | ||
process.exit(1); | ||
} | ||
|
||
// Updating the plugin (.config/, NPM package dependencies, package.json scripts) | ||
// (More info on the why: https://docs.google.com/document/d/15dm4WV9v7Ga9Z_Hp3CJMf2D3meuTyEWqBc3omqiOksQ) | ||
// ------------------- | ||
await updateDotConfigFolder(); | ||
updateNpmScripts(); | ||
updatePackageJson({ | ||
onlyOutdated: true, | ||
ignoreGrafanaDependencies: false, | ||
if (!isPluginDirectory() && !argv.force) { | ||
printRedBox({ | ||
title: 'Are you inside a plugin directory?', | ||
subtitle: 'We couldn\'t find a "src/plugin.json" file under your current directory.', | ||
content: `(Please make sure to run this command from the root of your plugin folder. In case you want to proceed as is please use the ${chalk.bold( | ||
'--force' | ||
)} flag.)`, | ||
}); | ||
await updateGoSdkAndModules(process.cwd()); | ||
|
||
const filesToRemove = getOnlyExistingInCwd(UDPATE_CONFIG.filesToRemove); | ||
if (filesToRemove.length) { | ||
removeFilesInCwd(filesToRemove); | ||
} | ||
|
||
printBlueBox({ | ||
title: 'Update successful ✔', | ||
content: `${chalk.bold('@grafana/* package version:')} ${getGrafanaRuntimeVersion()} | ||
${chalk.bold('@grafana/create-plugin version:')} ${getVersion()} | ||
process.exit(1); | ||
} | ||
|
||
${chalk.bold.underline('Next steps:')} | ||
- 1. Run ${chalk.bold(`${packageManagerName} install`)} to install the package updates | ||
- 2. Check if you encounter any breaking changes | ||
(refer to our migration guide: https://grafana.com/developers/plugin-tools/migration-guides/update-from-grafana-versions/) | ||
${chalk.bold('Do you have questions?')} | ||
Please don't hesitate to reach out in one of the following ways: | ||
- Open an issue in https://github.com/grafana/plugin-tools | ||
- Ask a question in the community forum at https://community.grafana.com/c/plugin-development/30 | ||
- Join our community slack channel at https://slack.grafana.com/`, | ||
}); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
printRedBox({ | ||
title: 'Something went wrong while updating your plugin.', | ||
content: error.message, | ||
}); | ||
} else { | ||
console.error(error); | ||
} | ||
if (argv.experimentalUpdates) { | ||
return await migrationUpdate(argv); | ||
} | ||
|
||
return await standardUpdate(); | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/create-plugin/src/commands/update.migrate.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import minimist from 'minimist'; | ||
import { gte } from 'semver'; | ||
import { getMigrationsToRun, runMigrations } from '../migrations/manager.js'; | ||
import { getConfig } from '../utils/utils.config.js'; | ||
import { getVersion } from '../utils/utils.version.js'; | ||
import { printHeader } from '../utils/utils.console.js'; | ||
|
||
export const migrationUpdate = async (argv: minimist.ParsedArgs) => { | ||
try { | ||
const projectCpVersion = getConfig().version; | ||
const packageCpVersion = getVersion(); | ||
|
||
if (gte(projectCpVersion, packageCpVersion)) { | ||
console.warn('Nothing to update, exiting.'); | ||
process.exit(0); | ||
} | ||
|
||
console.log(`Running migrations from ${projectCpVersion} to ${packageCpVersion}.`); | ||
|
||
const commitEachMigration = argv.commit; | ||
const migrations = getMigrationsToRun(projectCpVersion, packageCpVersion); | ||
await runMigrations(migrations, { commitEachMigration }); | ||
printHeader('the update command completed successfully.'); | ||
console.log(''); | ||
} catch (error) { | ||
printHeader('the update command encountered an error.'); | ||
console.log(''); | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice addition to this feature!