Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.24'
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.24'
- name: Run linters
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v8
with:
version: v1.52
version: v2.1.6

test:
strategy:
matrix:
go-version: [ '1.20', '1.19', '1.18']
go-version: [ '1.24' ]
platform: [ 'ubuntu-latest' ]
runs-on: ${{ matrix.platform }}
steps:
Expand All @@ -47,7 +47,7 @@ jobs:
if: success()
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.24'
- name: Checkout code
uses: actions/checkout@v2
- name: Calc coverage
Expand Down
16 changes: 9 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"context"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/apex/log"
logfmt_handler "github.com/apex/log/handlers/logfmt"
text_handler "github.com/apex/log/handlers/text"
"github.com/friendsofgo/errors"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/jwtauth/v5"
"github.com/joho/godotenv"
Expand Down Expand Up @@ -143,22 +143,24 @@ func loadDotenv(c *cli.Context) error {
for _, envFile := range envFiles {
err := loadEnvFile(envFile)
if err != nil {
return errors.Wrapf(err, "loading env file %s", envFile)
return fmt.Errorf("loading env file %s: %w", envFile, err)
}
}
}
return nil
}

func loadEnvFile(file string) error {
func loadEnvFile(file string) (err error) {
f, err := os.Open(file)
if os.IsNotExist(err) {
// Ignore not existing dotenv files
return nil
} else if err != nil {
return err
}
defer f.Close()
defer func(f *os.File) {
err = errors.Join(err, f.Close())
}(f)

log.
Debugf("Loading env from %q", file)
Expand Down Expand Up @@ -186,7 +188,7 @@ func appAction(c *cli.Context) error {

defs, err := definition.LoadRecursively(filepath.Join(c.String("path"), c.String("pattern")))
if err != nil {
return errors.Wrap(err, "loading definitions")
return fmt.Errorf("loading definitions: %w", err)
}

log.
Expand All @@ -197,12 +199,12 @@ func appAction(c *cli.Context) error {

outputStore, err := taskctl.NewOutputStore(path.Join(c.String("data"), "logs"))
if err != nil {
return errors.Wrap(err, "building output store")
return fmt.Errorf("building output store: %w", err)
}

dataStore, err := store.NewJSONDataStore(path.Join(c.String("data")))
if err != nil {
return errors.Wrap(err, "building pipeline runner store")
return fmt.Errorf("building pipeline runner store: %w", err)
}

// How signals are handled:
Expand Down
35 changes: 20 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package config

import (
"errors"
"fmt"
"os"

"github.com/apex/log"
"github.com/friendsofgo/errors"
"gopkg.in/yaml.v2"

"github.com/Flowpack/prunner/helper"
Expand All @@ -22,18 +23,18 @@ func (c Config) validate() error {
}
const minJWTSecretLength = 16
if len(c.JWTSecret) < minJWTSecretLength {
return errors.Errorf("jwt_secret must be at least %d characters long", minJWTSecretLength)
return fmt.Errorf("jwt_secret must be at least %d characters long", minJWTSecretLength)
}

return nil
}

func LoadOrCreateConfig(configPath string, cliConfig Config) (*Config, error) {
func LoadOrCreateConfig(configPath string, cliConfig Config) (c *Config, err error) {
if err := cliConfig.validate(); err == nil {
log.Debug("Using config from CLI")
return &cliConfig, nil
} else if err != ErrMissingJWTSecret {
return nil, errors.Wrap(err, "invalid CLI config")
return nil, fmt.Errorf("invalid CLI config: %w", err)
}

log.Debugf("Reading config from %s", configPath)
Expand All @@ -42,43 +43,47 @@ func LoadOrCreateConfig(configPath string, cliConfig Config) (*Config, error) {
log.Infof("No config found, creating file at %s", configPath)
return createDefaultConfig(configPath)
} else if err != nil {
return nil, errors.Wrap(err, "opening config file")
return nil, fmt.Errorf("opening config file: %w", err)
}
defer f.Close()
defer func(f *os.File) {
err = errors.Join(err, f.Close())
}(f)

c := new(Config)
c = new(Config)

err = yaml.NewDecoder(f).Decode(c)
if err != nil {
return nil, errors.Wrap(err, "decoding config")
return nil, fmt.Errorf("decoding config: %w", err)
}

err = c.validate()
if err != nil {
return nil, errors.Wrap(err, "invalid config")
return nil, fmt.Errorf("invalid config: %w", err)
}

return c, nil
}

func createDefaultConfig(configPath string) (*Config, error) {
func createDefaultConfig(configPath string) (c *Config, err error) {
f, err := os.Create(configPath)
if err != nil {
return nil, errors.Wrap(err, "creating config file")
return nil, fmt.Errorf("creating config file: %w", err)
}
defer f.Close()
defer func(f *os.File) {
err = errors.Join(err, f.Close())
}(f)

jwtSecret, err := helper.GenerateRandomString(32)
if err != nil {
return nil, errors.Wrap(err, "generating random string")
return nil, fmt.Errorf("generating random string: %w", err)
}
c := &Config{
c = &Config{
JWTSecret: jwtSecret,
}

err = yaml.NewEncoder(f).Encode(c)
if err != nil {
return nil, errors.Wrap(err, "encoding config")
return nil, fmt.Errorf("encoding config: %w", err)
}

return c, nil
Expand Down
23 changes: 13 additions & 10 deletions definition/loader.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package definition

import (
"errors"
"fmt"
"os"
"sort"

"github.com/friendsofgo/errors"
"github.com/mattn/go-zglob"
"gopkg.in/yaml.v2"
)

func LoadRecursively(pattern string) (*PipelinesDef, error) {
matches, err := zglob.GlobFollowSymlinks(pattern)
if err != nil {
return nil, errors.Wrap(err, "finding files with glob")
return nil, fmt.Errorf("finding files with glob: %w", err)
}

// Make globbing deterministic
Expand All @@ -25,36 +26,38 @@ func LoadRecursively(pattern string) (*PipelinesDef, error) {
for _, path := range matches {
err = pipelinesDef.Load(path)
if err != nil {
return nil, errors.Wrapf(err, "loading %s", path)
return nil, fmt.Errorf("loading %s: %w", path, err)
}
}

return pipelinesDef, nil
}

func (d *PipelinesDef) Load(path string) error {
func (d *PipelinesDef) Load(path string) (err error) {
f, err := os.Open(path)
if err != nil {
return errors.Wrap(err, "opening file")
return fmt.Errorf("opening file: %w", err)
}
defer f.Close()
defer func(f *os.File) {
err = errors.Join(err, f.Close())
}(f)

var localDef PipelinesDef

err = yaml.NewDecoder(f).Decode(&localDef)
if err != nil {
return errors.Wrap(err, "decoding YAML")
return fmt.Errorf("decoding YAML: %w", err)
}
localDef.setDefaults()

for pipelineName, pipelineDef := range localDef.Pipelines {
if p, exists := d.Pipelines[pipelineName]; exists {
return errors.Errorf("pipeline %q was already declared in %s", pipelineName, p.SourcePath)
return fmt.Errorf("pipeline %q was already declared in %s", pipelineName, p.SourcePath)
}

err := pipelineDef.validate()
err = pipelineDef.validate()
if err != nil {
return errors.Wrapf(err, "invalid pipeline definition %q", pipelineName)
return fmt.Errorf("invalid pipeline definition %q: %w", pipelineName, err)
}

pipelineDef.SourcePath = path
Expand Down
2 changes: 1 addition & 1 deletion definition/pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (d *PipelinesDef) Validate() error {
return nil
}

func (d PipelinesDef) Equals(otherDefs PipelinesDef) bool {
func (d *PipelinesDef) Equals(otherDefs PipelinesDef) bool {
if len(d.Pipelines) != len(otherDefs.Pipelines) {
return false
}
Expand Down
57 changes: 29 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
module github.com/Flowpack/prunner

go 1.18
go 1.24

require (
github.com/apex/log v1.9.0
github.com/friendsofgo/errors v0.9.2
github.com/go-chi/chi/v5 v5.0.7
github.com/go-chi/jwtauth/v5 v5.0.2
github.com/gofrs/uuid v4.2.0+incompatible
github.com/joho/godotenv v1.4.0
github.com/go-chi/chi/v5 v5.2.1
github.com/go-chi/jwtauth/v5 v5.3.3
github.com/gofrs/uuid v4.4.0+incompatible
github.com/joho/godotenv v1.5.1
github.com/json-iterator/go v1.1.12
github.com/liamylian/jsontime/v2 v2.0.0
github.com/mattn/go-isatty v0.0.14
github.com/mattn/go-zglob v0.0.3
github.com/stretchr/testify v1.7.1
github.com/mattn/go-isatty v0.0.20
github.com/mattn/go-zglob v0.0.6
github.com/stretchr/testify v1.10.0
github.com/taskctl/taskctl v1.3.1-0.20210426182424-d8747985c906
github.com/urfave/cli/v2 v2.4.0
github.com/urfave/cli/v2 v2.27.6
gopkg.in/yaml.v2 v2.4.0
mvdan.cc/sh/v3 v3.6.0
mvdan.cc/sh/v3 v3.11.0
)

require (
github.com/briandowns/spinner v1.18.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/briandowns/spinner v1.23.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/goccy/go-json v0.9.6 // indirect
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
github.com/lestrrat-go/blackmagic v1.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/lestrrat-go/blackmagic v1.0.4 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/httprc v1.0.6 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx v1.2.21 // indirect
github.com/lestrrat-go/option v1.0.0 // indirect
github.com/lestrrat-go/jwx/v2 v2.1.6 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/crypto v0.39.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/term v0.32.0 // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading