Skip to content

chore: implement new api for the workspace package#4166

Merged
mergify[bot] merged 19 commits intoaws:mainlinefrom
Lou1415926:workspace/newapi
Nov 11, 2022
Merged

chore: implement new api for the workspace package#4166
mergify[bot] merged 19 commits intoaws:mainlinefrom
Lou1415926:workspace/newapi

Conversation

@Lou1415926
Copy link
Copy Markdown
Contributor

This PR implements a new API for the workspace package. With the new API, a workspace client that gets returned to the caller always have the copilotDirAbs field in it. This means that the method calls can assume non-empty value of that field.
This addresses the proposal made in #4147 (comment)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.

@Lou1415926 Lou1415926 requested a review from a team as a code owner November 10, 2022 00:04
@Lou1415926 Lou1415926 requested review from dannyrandall and removed request for a team November 10, 2022 00:04
@Lou1415926 Lou1415926 changed the title chore: implement new api for the workspace interface chore: implement new api for the workspace package Nov 10, 2022
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Nov 10, 2022

🍕 Here are the new binary sizes!

Name New size (kiB) v1.23.0 size (kiB) Delta (%)
macOS (amd) 47572 47548 +0.05
macOS (arm) 47572 48200 ❤️ -1.30
linux (amd) 41836 41812 +0.06
linux (arm) 41836 41220 🥺 +1.49
windows (amd) 38684 38664 +0.05

Comment thread internal/pkg/workspace/workspace.go Outdated
workingDirAbs, err := os.Getwd()
// Use returns an existing workspace, searching for a copilot/ directory from the current wd,
// up to 5 levels above. It returns ErrWorkspaceNotFound if no copilot/ directory is found.
func Use(fs *afero.Afero, workingDirAbs string) (*Workspace, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't read the PR 😂 I thought I could leave this early feedback to see what you think:

  1. Is it possible to use the afero.Fs interface as the input instead of the concrete type? or are we depending on some more specific functionality

  2. Can we make the "workingDirAbs" optional? could the constructor by default use os.Getwd unless the user specified workspace.Use(&afero.Afero{Fs: afero.NewOsFs()}, workspace.WithWorkingDir("some/other/path"))
    Would that simplify the life of the cli pkg?

Copy link
Copy Markdown
Contributor Author

@Lou1415926 Lou1415926 Nov 10, 2022

Choose a reason for hiding this comment

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

Addressed both!

The whole reason why we needed to pass workingDir as a param was for the unit tests - specifically, the ones that test that Copilot is able to find a workspace in a parent directory. I fixed the unit tests such that it doesn't need to do so. This way, we don't need it as a param anymore, not even as an optional param.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Nov 10, 2022

Codecov Report

Merging #4166 (d848049) into mainline (b956464) will increase coverage by 0.04%.
The diff coverage is 49.20%.

@@             Coverage Diff              @@
##           mainline    #4166      +/-   ##
============================================
+ Coverage     69.24%   69.28%   +0.04%     
============================================
  Files           250      250              
  Lines         35927    35882      -45     
  Branches        264      264              
============================================
- Hits          24876    24862      -14     
+ Misses         9856     9828      -28     
+ Partials       1195     1192       -3     
Impacted Files Coverage Δ
internal/pkg/cli/app_delete.go 26.19% <0.00%> (ø)
internal/pkg/cli/deploy.go 28.14% <0.00%> (ø)
internal/pkg/cli/deploy/svc.go 48.48% <0.00%> (+0.20%) ⬆️
internal/pkg/cli/env_deploy.go 57.29% <0.00%> (ø)
internal/pkg/cli/env_init.go 65.07% <0.00%> (+0.18%) ⬆️
internal/pkg/cli/env_package.go 41.79% <0.00%> (-0.23%) ⬇️
internal/pkg/cli/init.go 22.59% <0.00%> (+0.05%) ⬆️
internal/pkg/cli/job_deploy.go 35.41% <0.00%> (+0.14%) ⬆️
internal/pkg/cli/job_init.go 62.54% <0.00%> (+0.42%) ⬆️
internal/pkg/cli/job_list.go 17.91% <0.00%> (ø)
... and 23 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Lou1415926 Lou1415926 added the WIP Pull requests that are being modified now. label Nov 10, 2022
sel: selector.NewLocalEnvironmentSelector(prompt.New(), cfgStore, ws),
caller: identity.New(defaultSess),
fs: &afero.Afero{Fs: afero.NewOsFs()},
fs: fs,
Copy link
Copy Markdown
Contributor Author

@Lou1415926 Lou1415926 Nov 10, 2022

Choose a reason for hiding this comment

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

This are a couple of refactors like this that are unrelated to the main purpose of this PR.

The fs field of packageEnvOpts needs to just implement afero.Fs, and afero.NewFs() already does this. We don't need the other methods in *afero.Afero.

@Lou1415926 Lou1415926 removed the WIP Pull requests that are being modified now. label Nov 10, 2022
Copy link
Copy Markdown
Contributor

@efekarakus efekarakus left a comment

Choose a reason for hiding this comment

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

Amazing work!! 💅

Comment thread internal/pkg/addon/addons.go Outdated
Comment on lines -202 to -204
workspacePath, err := ws.Path()
if err != nil {
return nil, fmt.Errorf("get workspace path: %w", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💅

Comment on lines +67 to +70
require.NoError(t, err)
fs := afero.NewMemMapFs()
_ = fs.MkdirAll(fmt.Sprintf("%s/copilot", wd), 0755)
_ = afero.WriteFile(fs, fmt.Sprintf("%s/copilot/.workspace", wd), []byte(fmt.Sprintf("---\napplication: %s", "DavidsApp")), 0644)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome improvement! 💅 but terrible app name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

:sus

Comment thread internal/pkg/workspace/workspace.go
@iamhopaul123 iamhopaul123 added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Nov 10, 2022
@Lou1415926 Lou1415926 removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Nov 11, 2022
@mergify mergify Bot merged commit ba5f300 into aws:mainline Nov 11, 2022
KollaAdithya pushed a commit to KollaAdithya/copilot-cli that referenced this pull request Nov 21, 2022
This PR implements a new API for the `workspace` package. With the new API, a workspace client that gets returned to the caller always have the `copilotDirAbs` field in it. This means that the method calls can assume non-empty value of that field.
This addresses the proposal made in aws#4147 (comment)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
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.

5 participants