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

refactor: rename stage struct #25

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
) {
defer wg.Done()

if err := CheckContextActivity(ctx); err != nil {
if err := CheckContext(ctx); err != nil {

Check warning on line 27 in internal/fs.go

View check run for this annotation

Codecov / codecov/patch

internal/fs.go#L27

Added line #L27 was not covered by tests
errCh <- err
return
}
Expand All @@ -51,7 +51,7 @@
jobs := make(chan struct{}, 10)

err := filepath.Walk(from, func(path string, info os.FileInfo, err error) error {
if ctxErr := CheckContextActivity(ctx); ctxErr != nil {
if ctxErr := CheckContext(ctx); ctxErr != nil {

Check warning on line 54 in internal/fs.go

View check run for this annotation

Codecov / codecov/patch

internal/fs.go#L54

Added line #L54 was not covered by tests
errCh <- ctxErr
return ctxErr
}
Expand Down Expand Up @@ -117,7 +117,7 @@
) {
defer wg.Done()

if err := CheckContextActivity(ctx); err != nil {
if err := CheckContext(ctx); err != nil {

Check warning on line 120 in internal/fs.go

View check run for this annotation

Codecov / codecov/patch

internal/fs.go#L120

Added line #L120 was not covered by tests
errCh <- err
return
}
Expand Down Expand Up @@ -153,7 +153,7 @@
}
}(in)

if err := CheckContextActivity(ctx); err != nil {
if err := CheckContext(ctx); err != nil {

Check warning on line 156 in internal/fs.go

View check run for this annotation

Codecov / codecov/patch

internal/fs.go#L156

Added line #L156 was not covered by tests
errCh <- err
return
}
Expand Down Expand Up @@ -185,7 +185,7 @@
}
}(out)

if err := CheckContextActivity(ctx); err != nil {
if err := CheckContext(ctx); err != nil {

Check warning on line 188 in internal/fs.go

View check run for this annotation

Codecov / codecov/patch

internal/fs.go#L188

Added line #L188 was not covered by tests
errCh <- err
return
}
Expand All @@ -196,7 +196,7 @@
return
}

if err := CheckContextActivity(ctx); err != nil {
if err := CheckContext(ctx); err != nil {

Check warning on line 199 in internal/fs.go

View check run for this annotation

Codecov / codecov/patch

internal/fs.go#L199

Added line #L199 was not covered by tests
errCh <- err
return
}
Expand Down
14 changes: 12 additions & 2 deletions internal/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"bytes"
"context"
"errors"
"fmt"
"log"
Expand Down Expand Up @@ -237,7 +238,7 @@

for _, item := range module.Stages {
wg.Add(1)
go func(wg *sync.WaitGroup, item Item) {
go func(wg *sync.WaitGroup, item Stage) {

Check warning on line 241 in internal/helpers.go

View check run for this annotation

Codecov / codecov/patch

internal/helpers.go#L241

Added line #L241 was not covered by tests
defer wg.Done()
checkPaths(item, errCh)
}(&wg, item)
Expand All @@ -258,7 +259,16 @@
return nil
}

func checkPaths(item Item, ch chan<- error) {
func CheckContext(ctx context.Context) error {
select {
case <-ctx.Done():
return fmt.Errorf("context canceled: %w", ctx.Err())
default:
return nil

Check warning on line 267 in internal/helpers.go

View check run for this annotation

Codecov / codecov/patch

internal/helpers.go#L262-L267

Added lines #L262 - L267 were not covered by tests
}
}

func checkPaths(item Stage, ch chan<- error) {

Check warning on line 271 in internal/helpers.go

View check run for this annotation

Codecov / codecov/patch

internal/helpers.go#L271

Added line #L271 was not covered by tests
for _, path := range item.From {
err := CheckPath(path)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
ReplaceIfNewer FileExistsAction = "replace_if_newer"
)

type Item struct {
type Stage struct {
Name string `yaml:"name"`
To string `yaml:"to"`
ActionIfFileExists FileExistsAction `yaml:"actionIfFileExists"`
Expand All @@ -29,7 +29,7 @@ type Module struct {
Repository string `yaml:"repository,omitempty"`
BuildDirectory string `yaml:"buildDirectory,omitempty"`
LogDirectory string `yaml:"logDirectory,omitempty"`
Stages []Item `yaml:"stages"`
Stages []Stage `yaml:"stages"`
Ignore []string `yaml:"ignore"`
}

Expand Down
10 changes: 5 additions & 5 deletions internal/module_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)

func (m *Module) Build() error {
if err := CheckContextActivity(m.Ctx); err != nil {
if err := CheckContext(m.Ctx); err != nil {

Check warning on line 15 in internal/module_builder.go

View check run for this annotation

Codecov / codecov/patch

internal/module_builder.go#L15

Added line #L15 was not covered by tests
return err
}

Expand Down Expand Up @@ -154,7 +154,7 @@
errCh := make(chan error, len(m.Stages))

for _, item := range m.Stages {
if err := CheckContextActivity(m.Ctx); err != nil {
if err := CheckContext(m.Ctx); err != nil {

Check warning on line 157 in internal/module_builder.go

View check run for this annotation

Codecov / codecov/patch

internal/module_builder.go#L157

Added line #L157 was not covered by tests
return err
}

Expand Down Expand Up @@ -193,12 +193,12 @@
wg *sync.WaitGroup,
errCh chan<- error,
ignore *[]string,
item Item,
item Stage,
buildDirectory string,
) {
defer wg.Done()

if err := CheckContextActivity(ctx); err != nil {
if err := CheckContext(ctx); err != nil {

Check warning on line 201 in internal/module_builder.go

View check run for this annotation

Codecov / codecov/patch

internal/module_builder.go#L201

Added line #L201 was not covered by tests
errCh <- err
return
}
Expand All @@ -210,7 +210,7 @@
}

for _, from := range item.From {
if err := CheckContextActivity(ctx); err != nil {
if err := CheckContext(ctx); err != nil {

Check warning on line 213 in internal/module_builder.go

View check run for this annotation

Codecov / codecov/patch

internal/module_builder.go#L213

Added line #L213 was not covered by tests
errCh <- err
return
}
Expand Down
10 changes: 0 additions & 10 deletions internal/validators.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package internal

import (
"context"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -39,12 +38,3 @@ func ValidateVersion(version string) error {

return fmt.Errorf("invalid module version %s", version)
}

func CheckContextActivity(ctx context.Context) error {
select {
case <-ctx.Done():
return fmt.Errorf("context canceled: %w", ctx.Err())
default:
return nil
}
}