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
129 changes: 10 additions & 119 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,139 +127,30 @@ steps:
- if [ "$(gofmt -l .)" ]; then echo "Code not formatted properly"; exit 1; fi
- staticcheck ./...

- name: build-linux-amd64
image: golang:1.24
depends_on:
- build-gen-tag
- code-quality
volumes:
- name: deps
path: /go
commands:
- mkdir -p dist
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.version=$DRONE_TAG" -o dist/servflow-linux-amd64 .

- name: build-linux-arm64
image: golang:1.24
depends_on:
- build-gen-tag
- code-quality
volumes:
- name: deps
path: /go
commands:
- mkdir -p dist
- GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "-X main.version=$DRONE_TAG" -o dist/servflow-linux-arm64 .

- name: build-darwin-amd64
image: golang:1.24
depends_on:
- build-gen-tag
- code-quality
volumes:
- name: deps
path: /go
commands:
- mkdir -p dist
- GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.version=$DRONE_TAG" -o dist/servflow-darwin-amd64 .

- name: build-darwin-arm64
image: golang:1.24
depends_on:
- build-gen-tag
- code-quality
volumes:
- name: deps
path: /go
commands:
- mkdir -p dist
- GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "-X main.version=$DRONE_TAG" -o dist/servflow-darwin-arm64 .

- name: build-windows-amd64
image: golang:1.24
depends_on:
- build-gen-tag
- code-quality
volumes:
- name: deps
path: /go
commands:
- mkdir -p dist
- GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.version=$DRONE_TAG" -o dist/servflow-windows-amd64.exe .

- name: create-archives
image: alpine:latest
depends_on:
- build-linux-amd64
- build-linux-arm64
- build-darwin-amd64
- build-darwin-arm64
- build-windows-amd64
commands:
- apk add --no-cache tar gzip zip
- mkdir -p releases
- cd dist
- tar -czf ../releases/servflow-$DRONE_TAG-linux-amd64.tar.gz servflow-linux-amd64
- tar -czf ../releases/servflow-$DRONE_TAG-linux-arm64.tar.gz servflow-linux-arm64
- tar -czf ../releases/servflow-$DRONE_TAG-darwin-amd64.tar.gz servflow-darwin-amd64
- tar -czf ../releases/servflow-$DRONE_TAG-darwin-arm64.tar.gz servflow-darwin-arm64
- zip ../releases/servflow-$DRONE_TAG-windows-amd64.zip servflow-windows-amd64.exe
- cd ..
- cd releases && sha256sum * > checksums.txt && cd ..
- ls -la releases/

- name: docker-build-multiarch
image: docker:27.3.1
- name: goreleaser
image: goreleaser/goreleaser
privileged: true
depends_on:
- build-gen-tag
- code-quality
volumes:
- name: docker_cache
path: /var/lib/docker
- name: docker-sock
path: /var/run/docker.sock
environment:
DOCKER_BUILDKIT: 1
GITHUB_TOKEN:
from_secret: github_token
DOCKER_USERNAME:
from_secret: docker_username
DOCKER_PASSWORD:
from_secret: docker_password
DOCKER_REGISTRY: ""
commands:
- export IMAGE_TAG=$(cat .image-tag)
- export VERSION=$(cat .version)
- dockerd &
- sleep 5
- docker info
- docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"
- docker buildx create --use
- |
if echo "$DRONE_TAG" | grep -iqE '.*-rc[0-9]+$'; then
echo "Release candidate detected, skipping latest tag"
docker buildx build --platform linux/amd64,linux/arm64 --build-arg VERSION=$VERSION -t $IMAGE_TAG --push .
else
echo "Stable release detected, pushing to latest tag"
docker buildx build --platform linux/amd64,linux/arm64 --build-arg VERSION=$VERSION -t $IMAGE_TAG -t servflow/servflow:latest --push .
fi

- name: github-release
image: alpine:latest
depends_on:
- create-archives
- docker-build-multiarch
environment:
GITHUB_TOKEN:
from_secret: github_token
commands:
- apk add --no-cache curl jq bash
- chmod +x scripts/create-github-release.sh
- bash scripts/create-github-release.sh
when:
event:
- tag
- goreleaser release

volumes:
- name: deps
host:
path: /var/lib/cache/drone/go
- name: docker_cache
- name: docker-sock
host:
path: /var/lib/cache/drone/docker
path: /var/run/docker.sock
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ servflow-debug
*.test
*.out
data/
.DS_Store
.DS_Store
# Added by goreleaser init:
dist/
53 changes: 53 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 2

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

archives:
- formats: [tar.gz]
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
formats: [zip]

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

release:
footer: >-

---

Released by [GoReleaser](https://github.com/goreleaser/goreleaser).
2 changes: 1 addition & 1 deletion cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func ValidateConfigs(configFolder string, verbose bool) error {
validCount := 0

for _, cfg := range configs {
if err := cfg.SchemaValidation(); err != nil {
if err := cfg.Validate(); err != nil {
validationErrors = append(validationErrors, ValidationError{
ConfigID: cfg.ID,
Error: err,
Expand Down
38 changes: 38 additions & 0 deletions pkg/agent/agent_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 29 additions & 1 deletion pkg/definitions/apiconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
_ "embed"
"encoding/json"
"fmt"
"strings"

"git.servflow.io/servflow/definitions/proto"
"github.com/Servflow/servflow/pkg/engine/actions"
"github.com/santhosh-tekuri/jsonschema/v6"
)

Expand Down Expand Up @@ -128,7 +130,18 @@ func (d *DatasourceConfig) UnmarshalYAML(unmarshal func(interface{}) error) erro
d.NewConfig = tmp.NewConfig
return nil
}
func (a *APIConfig) SchemaValidation() error {

func (a *APIConfig) Validate() error {
if err := a.schemaValidation(); err != nil {
return err
}
if err := a.validateActions(); err != nil {
return err
}
return nil
}

func (a *APIConfig) schemaValidation() error {
compiler := jsonschema.NewCompiler()

var schemaData interface{}
Expand Down Expand Up @@ -161,3 +174,18 @@ func (a *APIConfig) SchemaValidation() error {

return nil
}

func (a *APIConfig) validateActions() error {
var invalidActions []string
for i := range a.Actions {
action := a.Actions[i]
if !actions.HasRegisteredActionType(action.Type) {
invalidActions = append(invalidActions, action.Type)
}
}

if len(invalidActions) > 0 {
return fmt.Errorf("invalid actions: %s", strings.Join(invalidActions, ", "))
}
return nil
}
26 changes: 24 additions & 2 deletions pkg/definitions/apiconfig_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package apiconfig

import (
"encoding/json"
"testing"

"github.com/Servflow/servflow/pkg/engine/actions"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAPIConfig_SchemaValidate(t *testing.T) {
func TestAPIConfig_Validate(t *testing.T) {
validConfig := APIConfig{
ID: "test-api",
Actions: map[string]Action{
Expand Down Expand Up @@ -71,6 +74,20 @@ func TestAPIConfig_SchemaValidate(t *testing.T) {
},
wantError: false,
},
{
name: "valid config with invalid action",
config: func() APIConfig {
newConfig := validConfig
newConfig.Actions = map[string]Action{
"action1": {
Type: "http2",
Next: "action2",
},
}
return newConfig
},
wantError: true,
},
{
name: "invalid config - empty ID",
config: func() APIConfig {
Expand Down Expand Up @@ -135,10 +152,15 @@ func TestAPIConfig_SchemaValidate(t *testing.T) {
},
}

err := actions.RegisterAction("http", func(config json.RawMessage) (actions.ActionExecutable, error) {
return nil, nil
})
require.NoError(t, err)

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfg := tt.config()
err := cfg.SchemaValidation()
err := cfg.Validate()
if tt.wantError {
assert.Error(t, err)
} else {
Expand Down
6 changes: 3 additions & 3 deletions pkg/engine/actions/executables/delete_action/delete_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/engine/actions/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ func GetActionExecutable(actionType string, config json.RawMessage) (ActionExecu
func GetRegisteredActionTypes() []string {
return actionManager.GetRegisteredActionTypes()
}

func HasRegisteredActionType(actionType string) bool {
_, ok := actionManager.availableConstructors[actionType]
return ok
}
Loading