-
Notifications
You must be signed in to change notification settings - Fork 2
refactor bootstrap gcp #166
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1080976
refac(bootstrap): big refactor of the gcp bootstrapper, add tests
siherrmann 4b3372e
update: small clean ups
siherrmann 3170884
chore(docs): Auto-update docs and licenses
siherrmann 2d0910a
fix: fix copilot review issues
siherrmann b8f5f08
Merge branch 'bootstrap-gcp-refac' of https://github.com/codesphere-c…
siherrmann 8a47f9d
fix: fix lint issues
siherrmann c011a53
Merge branch 'main' into bootstrap-gcp-refac
siherrmann 788a079
chore(docs): Auto-update docs and licenses
siherrmann 303efae
update: add ssh client caching, add ssh quiet flag
siherrmann 25c2cb0
Merge branch 'bootstrap-gcp-refac' of https://github.com/codesphere-c…
siherrmann e96ac96
fix: fix dependencies
siherrmann 2d6186a
chore(docs): Auto-update docs and licenses
siherrmann 23a1e1d
fix: fix go mod
siherrmann 8adbe41
Merge branch 'bootstrap-gcp-refac' of https://github.com/codesphere-c…
siherrmann 368b0a2
fix: fix go mod
siherrmann 02b5664
Merge branch 'main' into bootstrap-gcp-refac
siherrmann b73c0f1
chore(docs): Auto-update docs and licenses
siherrmann 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,87 @@ | ||
| // Copyright (c) Codesphere Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package bootstrap | ||
|
|
||
| import ( | ||
| "fmt" | ||
| ) | ||
|
|
||
| const ( | ||
| LINE_RESET = "\r\033[2K" | ||
| MOVE_UP = "\033[1A" | ||
| MOVE_UP_CLEAR_LINE = "\033[1A\033[K" | ||
| RESET_TEXT = "\033[0m" | ||
| RED_TEXT = "\033[31m" | ||
| GREEN_TEXT = "\033[32m" | ||
| ) | ||
|
|
||
| type StepLogger struct { | ||
| silent bool | ||
| subSteps int | ||
| currentStep string | ||
| } | ||
|
|
||
| func NewStepLogger(silent bool) *StepLogger { | ||
| return &StepLogger{ | ||
| silent: silent, | ||
| } | ||
| } | ||
|
|
||
| func (b *StepLogger) Step(name string, fn func() error) error { | ||
| if b.silent { | ||
| return fn() | ||
| } | ||
|
|
||
| b.subSteps = 0 | ||
| b.currentStep = name | ||
|
|
||
| fmt.Printf("%s%s%s...", LINE_RESET, RESET_TEXT, name) | ||
| err := fn() | ||
| if err != nil { | ||
| fmt.Printf("%s%s%s failed: %v%s\n", LINE_RESET, RED_TEXT, name, err, RESET_TEXT) | ||
| } else { | ||
| for i := 0; i < b.subSteps; i++ { | ||
| fmt.Printf("%s", MOVE_UP_CLEAR_LINE) | ||
| } | ||
| fmt.Printf("%s%s%s %s✓%s\n", LINE_RESET, RESET_TEXT, name, GREEN_TEXT, RESET_TEXT) | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| func (b *StepLogger) Substep(name string, fn func() error) error { | ||
| if b.silent { | ||
| return fn() | ||
| } | ||
|
|
||
| b.subSteps += 1 | ||
| b.currentStep = name | ||
|
|
||
| fmt.Printf("%s%s %s...", LINE_RESET, RESET_TEXT, name) | ||
| err := fn() | ||
| if err != nil { | ||
| fmt.Printf("%s%s %s failed: %v%s\n", LINE_RESET, RED_TEXT, name, err, RESET_TEXT) | ||
| } else { | ||
| fmt.Printf("%s%s %s %s✓%s\n", LINE_RESET, RESET_TEXT, name, GREEN_TEXT, RESET_TEXT) | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| // LogRetry prints a retry message for the current step. | ||
| func (b *StepLogger) LogRetry() { | ||
| if b.subSteps > 0 { | ||
| fmt.Printf("%s%s Retrying: %s...%s", LINE_RESET, RESET_TEXT, b.currentStep, RESET_TEXT) | ||
| } else { | ||
| fmt.Printf("%s%sRetrying: %s...%s", LINE_RESET, RESET_TEXT, b.currentStep, RESET_TEXT) | ||
| } | ||
| } | ||
|
|
||
| // Logf prints a log message for the current step. | ||
| func (b *StepLogger) Logf(message string, args ...interface{}) { | ||
| if b.silent { | ||
| return | ||
| } | ||
|
|
||
| b.subSteps += 1 | ||
| fmt.Printf("%s%s %s%s\n", LINE_RESET, RESET_TEXT, fmt.Sprintf(message, args...), RESET_TEXT) | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.