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

Add UpdateCommand #111

Merged
merged 58 commits into from
Dec 8, 2022
Merged

Add UpdateCommand #111

merged 58 commits into from
Dec 8, 2022

Conversation

Giuspepe
Copy link
Contributor

@Giuspepe Giuspepe commented Nov 17, 2022

Fixes #96

Scope of this PR

  • pubspec.yaml template now contains a field sidekick: cli_version: <version> which contains the sidekick version the CLI was generated with
  • Checks whether an update is available whenever a command is executed
  • Add UpdateCommand which calls the latest available version of update_sidekick_cli.dart
  • update_sidekick_cli currently updates the following:
    • shell scripts in tool (download_dart.sh, install.sh, run.sh, sidekick_config.sh)
    • entrypoint executable
    • sidekick_core dependency to latest available version
    • sidekick->cli_version in pubspec.yaml to latest available sidekick version

Necessary work in following PRs

Update sidekick_core in sidekick and pass new sidekick version parameter to SidekickTemplateProperties

When generating a new sidekick CLI package, we have to save the version of sidekick which generated the CLI in the generated CLI's <generated-cli>/pubspec.yaml. However, we can't read the global sidekick's version because its executable is compiled and thus does not have access to its own <global-sidekick>/pubspec.yaml because it isn't bundled with the compiled executable.
Instead we could use an automatically generated source file which contains the version information
See e.g. https://stackoverflow.com/a/69048343/9905602 or how mason_cli implements this in a version.dart file: https://github.com/felangel/mason/pull/538/files

We should save the version of sidekick_core from sidekick's pubspec.lock in a Dart file

Add migration functions

Whenever additional steps (besides regenerating shell scripts) are needed to migrate from an old to the latest version, add them to update_sidekick_cli.dart. This script receives the current and the latest version. This information can be used to call migration functions to do additional update steps (e.g. modifying certain lines in dart files).

How to test this PR

There is a update_command_test.dart which already tests this command.
If you want to test this manually, do the following:

  1. Edit the pubspec.yaml of an old sidekick CLI
dependencies:
  sidekick_core: '>=0.11.0 <1.0.0'

dependency_overrides:
  sidekick_core:
    path: /Users/pepe/repos/sidekick/sidekick_core
  1. Add SidekickCommand to the cli
  2. Run <cli> sidekick update
  3. Verify the following:
    1. the 4 shell scripts in tool have been updated
    2. cli_version has been updated to the latest version of sidekick (0.7.1)
    3. the sidekick_core dependency has been updated to sidekick_core: '>=0.11.1 <1.0.0'
    4. A success message has been printed (Successfully updated sidekick CLI <cli> from version 0.0.0 to 0.7.1!)

@Giuspepe
Copy link
Contributor Author

Maybe we should also uses this command to update the bundled dart runtime (sidekickDartRuntime). See #57

@Giuspepe
Copy link
Contributor Author

When running <cli> sidekick update as described above in an outdated sidekick CLI almost everything works. This is the output:

Updating sidekick CLI iv from version 0.0.0 to 0.7.1 ...
Successfully updated sidekick CLI iv from version 0.0.0 to 0.7.1!
/Users/pepe/repos/invo-frontend/packages/iv_sidekick/tool/run.sh: line 70: unexpected EOF while looking for matching `"'

Everything is correctly updated and executed from the dart side, but an error (exit code 2) is thrown from the run.sh script:

/Users/pepe/repos/invo-frontend/packages/iv_sidekick/tool/run.sh: line 70: unexpected EOF while looking for matching `"'

I guess because we're modifying the file which is currently being executed? 🤔

sidekick_core/pubspec.yaml Outdated Show resolved Hide resolved
@Giuspepe Giuspepe mentioned this pull request Dec 7, 2022
Giuspepe and others added 5 commits December 8, 2022 18:33
# Conflicts:
#	sidekick/test/util/cli_runner.dart
#	sidekick_test/lib/src/local_testing.dart
# Conflicts:
#	sidekick_core/lib/sidekick_core.dart
#	sidekick_test/lib/src/local_testing.dart
# Conflicts:
#	sidekick_core/lib/src/version_checker.dart
#	sidekick_core/test/version_checker_test.dart
@passsy passsy merged commit f1607e2 into main Dec 8, 2022
@passsy passsy deleted the update-command branch December 8, 2022 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

<cli> sidekick upgrade
2 participants