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

[FEATURE] Introduces homebrew task #67

Merged
merged 13 commits into from Jun 20, 2018
Merged

Conversation

mlhamel
Copy link
Collaborator

@mlhamel mlhamel commented May 3, 2018

Resolves #65

@pior
Copy link
Member

pior commented May 3, 2018

😍

pkg/env/env.go Outdated
// Os returns the current running operating system
func (e *Env) Os() string {
return runtime.GOOS
}
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this indirection? Why not just call runtime.GOOS directly?

func NewHomebrewWithPrefix(prefix string) *Homebrew {
if !utils.PathExists(filepath.Join(prefix, "Cellar")) {

path := strings.Split(env.NewFromOS().Get("PATH"), ":")
Copy link
Member

Choose a reason for hiding this comment

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

We could probably update the Env api to make getAndSplitPath() public.
Renaming the 2 symmetric methods could be a good idea: GetPathParts()/SetPathParts()


if len(path) > 0 && utils.PathExists(path[0]) {
prefix = filepath.Dir(path[0])
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't get this. Are we making an assumption on what the first PATH member is?

return &Homebrew{prefix: prefix}
}

func pathToPackage(filename string) string {
Copy link
Member

Choose a reason for hiding this comment

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

Just a thought: maybe the helpers should get their own package (pkg/helpers/homebrew) to scope function like this pathToPackage().
Otherwise we should either namespace it with homebrew or attach it to Homebrew

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea the sub-package cause i fear this might end-up has a mess of name collisions

func (h *Homebrew) PackageIsInCaskroom(pkg string) bool {
path := "/opt/homebrew-cask/Caskroom"

if !utils.PathExists("/opt/homebrew-cask/Caskroom") {
Copy link
Member

Choose a reason for hiding this comment

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

-> path

path := filepath.Join(h.prefix, "Cellar")

path = filepath.Join(path, pkg)
return utils.PathExists(path)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: return utils.PathExists(filepath.Join(h.prefix, "Cellar", pkg))

)

func TestPackageIsInCellar(t *testing.T) {
prefix, err := ioutil.TempDir("/tmp", "dad-brew")
Copy link
Member

Choose a reason for hiding this comment

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

  • is there a reason to specify the tmpdir? ioutil.TempDir("", ...)
  • we should clean this folder up after the test.

But all that is annoying, let's use Filet (it's already used in this project):
https://github.com/Flaque/filet#creating-temporary-directories

@pior pior changed the title Introduces homebrew task [FEATURE] Introduces homebrew task May 27, 2018
@mlhamel
Copy link
Collaborator Author

mlhamel commented Jun 13, 2018

ping @pior I've updated the homebrew feature

Just a few notes, I've decided not installing the formulas from the helper as we've discussed but directly in the TaskAction cause we might needs to refactor a bit the task api for that and I would prefer doing this in a separated PR.

@pior pior mentioned this pull request Jun 14, 2018
15 tasks
pkg/env/env.go Outdated
@@ -62,30 +62,32 @@ func (e *Env) Environ() (vars []string) {
return vars
}

func (e *Env) getAndSplitPath() []string {
// GetPathParts gets paths in PATH environment variable
func (e *Env) GetPathParts() []string {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: do we need this to be public in the end?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not really...

return h.cellar.IsInstalled(path) || h.caskroom.IsInstalled(path)
}

func buildFormulaPath(filename string) string {
Copy link
Member

Choose a reason for hiding this comment

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

The logic doesn't seem so obvious, I feel like we should explain what happens here.

}

// IsInstalled returns true if formulua was installed in Caskrook
func (c *caskroom) IsInstalled(formula string) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Those methods (also on cellar) looks like they should be private.


h := NewHomebrewWithPrefix(prefix)

require.Truef(t, h.IsInstalled("curl"), "Curl is properly installed in Cellar %s", cellarPath)
Copy link
Member

Choose a reason for hiding this comment

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

I missed those require functions, nice!

brew := helpers.NewHomebrew()

if !brew.IsInstalled(b.formula) {
err := command(ctx, "brew", "install", b.formula).AddOutputFilter("already satisfied").Run()
Copy link
Member

Choose a reason for hiding this comment

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

Does this AddOutputFilter make sense with brew?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah not really cause anyway we should just display those informations

func (b *brewInstall) run(ctx *context) error {
brew := helpers.NewHomebrew()

if !brew.IsInstalled(b.formula) {
Copy link
Member

Choose a reason for hiding this comment

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

This condition should be in the needed method, so the TaskRunner knows whether this action should be run or not.

Copy link
Member

@pior pior left a comment

Choose a reason for hiding this comment

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

🚀

@mlhamel mlhamel merged commit e40c3f5 into master Jun 20, 2018
@mlhamel mlhamel deleted the introduces-homebrew-task branch June 20, 2018 00:51
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

2 participants