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

Interactive cli #83

Merged
merged 47 commits into from
Jul 7, 2022
Merged

Interactive cli #83

merged 47 commits into from
Jul 7, 2022

Conversation

juampynr
Copy link
Member

@juampynr juampynr commented Jul 1, 2022

For #82

This is raw and lacks error handling and best practices but already does something:

  1. Upon compiling the Go application, you get a drupal9ci executable.
  2. Copying this executable into a Drupal project and running it shows the following prompt:
/Users/jrequena/projects/drupal [master] ./drupal9ci 
Use the arrow keys to navigate: ↓ ↑ → ← 
? Select CI provider: 
  ▸ Bitbucket
    CircleCI
    GitHub Actions
    GitLab CI
    Travis CI
  1. Selecting an option above performs the curl request to the installer command and executes it.

As I am writing this I think that I can simply run the script without having to download it since it is packaged within the executable. I will fix this in this pull request.

Once we have this in place we could:

  • Set up a job that creates releases automatically out of tags. Users would simply download the executable and run it.
  • Start replacing the bash scripts by actual Go code that we can test easily.

import (
"fmt"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
Copy link
Member Author

Choose a reason for hiding this comment

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

cobra is a tool to create CLI interfaces in Go.

"fmt"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Copy link
Member Author

Choose a reason for hiding this comment

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

viper is a tool to manage configuration. It pairs well with cobra. I have not used it yet but decided to get it in already since I am sure that we will make use of it.

cmd/root.go Outdated
var setupScript string
var err error

if len(os.Args) > 1 {
Copy link
Member Author

Choose a reason for hiding this comment

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

Had to add this in order to set a CI provider at the CircleCI job that tests the application.

@juampynr
Copy link
Member Author

juampynr commented Jul 4, 2022

@fjgarlin thoughts about this so far?

@juampynr juampynr marked this pull request as ready for review July 5, 2022 08:15
@juampynr juampynr requested a review from fjgarlin July 5, 2022 08:15
@fjgarlin
Copy link
Collaborator

fjgarlin commented Jul 5, 2022

Code-wise, it all looks good (my knowledge of go is limited but it's all very readable).

  1. I'd also expect as part of this PR changes in the readme file explaining how to use the new tool.
  2. Looking at the code, do we need to compile the command with go first locally, and then run it?

--
starts reading the very first comment...

@fjgarlin
Copy link
Collaborator

fjgarlin commented Jul 5, 2022

  1. You just addressed it
  2. Users would simply download the executable and run it. that would address it.

I'll test it all locally, just wanted to give some quick feedback as I found it.

@juampynr
Copy link
Member Author

juampynr commented Jul 5, 2022

Code-wise, it all looks good (my knowledge of go is limited but it's all very readable).

  1. I'd also expect as part of this PR changes in the readme file explaining how to use the new tool.
  2. Looking at the code, do we need to compile the command with go first locally, and then run it?

-- starts reading the very first comment...

1: yep! I just adjusted that
2: no, I added a GitHub action that should create a release with the resulted binary that should be ready to use.

@fjgarlin
Copy link
Collaborator

fjgarlin commented Jul 5, 2022

This is so awesome, it opens the door to future improvements like rewriting bash scripts in go, choosing the PHP version (once we figure out images), etc. And most importantly, it lowers the entry barrier to this project.

A super small suggestion. When you run the command, after choosing the platform, it takes around 5~10 seconds until you get the first line of output. For a second I wasn't sure if my machine was hanging, so it might be good to put a Starting... line so the user knows they'll need to wait a few seconds.

So something like:

? Select CI provider: 
  ▸ Bitbucket
    CircleCI
    GitHub Actions
    GitLab CI
    Travis CI
    
 ✔ Bitbucket
 Starting... 
 (5~10 seconds later)
 output: + wget -O...

Could be Starting... or This might take a few seconds... or something like that.

cmd/root.go Outdated
if len(args) > 1 {
return &args[1], nil
}
ciProviders := []string{"Bitbucket", "CircleCI", "GitHub Actions", "GitLab CI", "Travis CI"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm new to go language. Can we not import/use the const defined in scripts/scripts.go to avoid repetition? If we can't that's totally fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure!

@fjgarlin
Copy link
Collaborator

fjgarlin commented Jul 5, 2022

You missed replacing the old command with the new one here: https://github.com/Lullabot/drupal9ci/blob/82-interactive-cli/README.md#github-actions

@juampynr
Copy link
Member Author

juampynr commented Jul 5, 2022

@fjgarlin this is ready for another look.

@juampynr juampynr requested a review from fjgarlin July 5, 2022 22:07
@codecov-commenter
Copy link

codecov-commenter commented Jul 6, 2022

Codecov Report

❗ No coverage uploaded for pull request base (master@519a879). Click here to learn what that means.
The diff coverage is n/a.

@@            Coverage Diff            @@
##             master      #83   +/-   ##
=========================================
  Coverage          ?   40.54%           
=========================================
  Files             ?        1           
  Lines             ?       37           
  Branches          ?        0           
=========================================
  Hits              ?       15           
  Misses            ?       21           
  Partials          ?        1           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 519a879...6309765. Read the comment docs.

@juampynr
Copy link
Member Author

juampynr commented Jul 6, 2022

@fjgarlin I will merge this tomorrow. Let me know if you find any issues. We can work on further changes in new pull requests.

@fjgarlin
Copy link
Collaborator

fjgarlin commented Jul 7, 2022

I was away from the computer yesterday and couldn't check the activity. I've been checking the code changes and everything looks really solid.

I think it's good to be merged. Approving the PR. Great work!


jobs:
publish-docker-image:
name: Publish Docker image
Copy link
Collaborator

Choose a reason for hiding this comment

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

Additional questions, but PR is good to be merged:

  • Does this publish the image generated from Dockerfile into github? or is it another unrelated thing?
  • If it's the image from Dockerfile, how would we use it later in the different platforms?

Copy link
Member Author

@juampynr juampynr Jul 7, 2022

Choose a reason for hiding this comment

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

Additional questions, but PR is good to be merged:

  • Does this publish the image generated from Dockerfile into github? or is it another unrelated thing?

Yes, here: https://github.com/Lullabot/drupal9ci/pkgs/container/drupal9ci

  • If it's the image from Dockerfile, how would we use it later in the different platforms?

I suggest that we start supporting only the Dockerile9 (I replaced Dockerfile with Dockerfile9). Next, we can improve the cli so it asks for Drupal version and picks the right Dockerfile (at which point we could restore the old Dockerfile and build and publish both images in this job). Alternatively, I wonder if we can detect the version and pick the Dockerfile automatically. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think giving the user the option to choose might be enough. We can just give them options like this:

* Dockerfile9: php8.1, composer 2, npm 16...
* Dockerfile: php7.4, composer 1, npm 12...
* Choose your own image: this might not work out of the box. You'll be prompted to type it.

Then with that info, we can search/replace the config file of the platform they've used.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep! I like that.

@@ -0,0 +1,41 @@
name: Test
Copy link
Collaborator

Choose a reason for hiding this comment

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

Loving the additional tests

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep! This is just the beginning. I want to move the shell scripts into easily testable Go code as you suggested.

Notice that I kind of hacked the default Cobra command: I removed sub-commands so you can just run drupal9ci but you can certainly have multiple sub commands so you could do, for example drupal9ci check to check for requirements and, when ready, run drupal9ci install to run the installer. We could also do this in a follow up.

Copy link
Member Author

Choose a reason for hiding this comment

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

At some point (sorry I am throwing out a lot of thoughts here), I would like to rename (again, I know) this repository to drupalci since we will be able to support multiple Drupal versions. Thoughts about this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

100% on this.

@juampynr
Copy link
Member Author

juampynr commented Jul 7, 2022

@fjgarlin I may have broken some of the providers by updating the Docker images. I am going to merge and then will start testing them one by one with a sample repository. Feel free to suggest whatever fixes you may consider.

@juampynr juampynr merged commit db09477 into master Jul 7, 2022
@fjgarlin
Copy link
Collaborator

fjgarlin commented Jul 7, 2022

Not a problem. As this is not a package that is updated on people's projects, but rather a "use once, then tweak in your own copy", we will not be breaking people's projects.

If new users find issues I'm sure they'll report them. But yeah, in any case, it's a good idea to give it a quick try by yourself and if I find time next week I can also do the same, but all of it as follow-ups.

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.

None yet

3 participants