-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Janos Bonic
committed
Sep 12, 2022
0 parents
commit a089c38
Showing
11 changed files
with
830 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "gomod" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" |
This file contains 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,11 @@ | ||
## Please describe the change you are making | ||
|
||
... | ||
|
||
## Are you the owner of the code you are sending in, or do you have permission of the owner? | ||
|
||
... | ||
|
||
## The code will be published under the BSD 3 clause license. Have you read and understood this license? | ||
|
||
... |
This file contains 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,27 @@ | ||
#!/bin/bash | ||
|
||
export NOLINT=1 | ||
go generate >/tmp/gogenerate.output 2>/tmp/gogenerate.output | ||
if [ $? -ne 0 ]; then | ||
echo -e "::group::\e[0;31m❌ Go generate failed.\e[0m" | ||
cat /tmp/gogenerate.output | ||
echo "::endgroup::" | ||
exit 1 | ||
fi | ||
|
||
echo -e "::group::\e[0;32m✅ Go generate succeeded.\e[0m" | ||
cat /tmp/gogenerate.output | ||
echo "::endgroup::" | ||
|
||
git diff >/tmp/gogenerate.diff | ||
if [ "$(cat /tmp/gogenerate.diff | wc -l)" -ne 0 ]; then | ||
echo -e "::group::\e[0;31m❌ Git changes after go generate.\e[0m" | ||
echo "The following is the diff of files:" | ||
cat /tmp/gogenerate.diff | ||
echo "::endgroup::" | ||
echo -e "\e[0;31m⚙ Please run go generate before pushing your changes.\e[0m" | ||
exit 1 | ||
fi | ||
|
||
echo -e "::group::\e[0;32m✅ No changes after go generate.\e[0m" | ||
echo "::endgroup::" |
This file contains 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,65 @@ | ||
name: Build | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
jobs: | ||
golangci-lint: | ||
name: golangci-lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Run golangci-lint | ||
uses: golangci/golangci-lint-action@v2 | ||
test: | ||
name: go test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.18 | ||
- name: Set up gotestfmt | ||
uses: haveyoudebuggedit/gotestfmt-action@v2 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
key: go-test-${{ hashFiles('**/go.sum') }} | ||
restore-keys: go-test- | ||
- name: Run go test | ||
run: | | ||
set -euo pipefail | ||
go generate | ||
go test -json -v ./... 2>&1 | tee /tmp/gotest.log | gotestfmt | ||
- name: Upload test log | ||
uses: actions/upload-artifact@v2 | ||
if: always() | ||
with: | ||
name: test-log | ||
path: /tmp/gotest.log | ||
if-no-files-found: error | ||
generate: | ||
name: go generate | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.16 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
key: go-test-${{ hashFiles('**/go.sum') }} | ||
restore-keys: go-generate- | ||
- name: Run go generate | ||
run: ./.github/scripts/gogenerate.sh |
This file contains 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,93 @@ | ||
run: | ||
timeout: 5m | ||
linters: | ||
enable: | ||
# region General | ||
|
||
# Add depguard to prevent adding additional dependencies. This is a client library, we really don't want | ||
# additional dependencies. | ||
- depguard | ||
# Prevent improper directives in go.mod. | ||
- gomoddirectives | ||
# Prevent improper nolint directives. | ||
- nolintlint | ||
|
||
# endregion | ||
|
||
|
||
# region Code Quality and Comments | ||
|
||
# Inspect source code for potential security problems. This check has a fairly high false positive rate, | ||
# comment with // nolint:gosec where not relevant. | ||
- gosec | ||
# Replace golint. | ||
- revive | ||
# Complain about deeply nested if cases. | ||
- nestif | ||
# Prevent naked returns in long functions. | ||
- nakedret | ||
# Make Go code more readable. | ||
- gocritic | ||
# We don't want hidden global scope, so disallow global variables. You can disable this with | ||
# Check if comments end in a period. This helps prevent incomplete comment lines, such as half-written sentences. | ||
- godot | ||
# Complain about comments as these indicate incomplete code. | ||
- godox | ||
# Keep the cyclomatic complexity of functions to a reasonable level. | ||
- gocyclo | ||
# Complain about cognitive complexity of functions. | ||
- gocognit | ||
# Find repeated strings that could be converted into constants. | ||
- goconst | ||
# Complain about unnecessary type conversions. | ||
- unconvert | ||
# Complain about unused parameters. These should be replaced with underscores. | ||
- unparam | ||
# Check for non-ASCII identifiers. | ||
- asciicheck | ||
# Check for HTTP response body being closed. Sometimes, you may need to disable this using // nolint:bodyclose. | ||
- bodyclose | ||
# Check for duplicate code. You may want to disable this with // nolint:dupl if the source code is the same, but | ||
# legitimately exists for different reasons. | ||
- dupl | ||
# Check for pointers in loops. This is a typical bug source. | ||
- exportloopref | ||
# Enforce a reasonable function length of 60 lines or 40 instructions. In very rare cases you may want to disable | ||
# this with // nolint:funlen if there is absolutely no way to split the function in question. | ||
- funlen | ||
# Prevent dogsledding (mass-ignoring return values). This typically indicates missing error handling. | ||
- dogsled | ||
# Enforce consistent import aliases across all files. | ||
- importas | ||
# Make code properly formatted. | ||
- gofmt | ||
# Prevent faulty error checks. | ||
- nilerr | ||
# Prevent direct error checks that won't work with wrapped errors. | ||
- errorlint | ||
# Find slice usage that could potentially be preallocated. | ||
- prealloc | ||
# Check for improper duration handling. | ||
- durationcheck | ||
# Enforce tests being in the _test package. | ||
- testpackage | ||
|
||
# endregion | ||
linters-settings: | ||
depguard: | ||
list-type: whitelist | ||
include-go-root: false | ||
packages: | ||
- go.flow.arcalot.io/pluginsdk/schema | ||
govet: | ||
enable-all: true | ||
check-shadowing: false | ||
disable: | ||
# We don't care about variable shadowing. | ||
- shadow | ||
- fieldalignment | ||
stylecheck: | ||
checks: | ||
- all | ||
issues: | ||
exclude-use-default: false |
This file contains 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,3 @@ | ||
module go.flow.arcalot.io/pluginsdk | ||
|
||
go 1.18 |
This file contains 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,2 @@ | ||
// Package schema contains the Arcaflow schema system. | ||
package schema |
This file contains 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,80 @@ | ||
package schema | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ConstraintError indicates that the passed data violated one or more constraints defined in the schema. | ||
// The message holds the exact path of the problematic field, as well as a message explaining the error. | ||
// If this error is not easily understood, please open an issue on the Arcaflow plugin SDK. | ||
type ConstraintError struct { | ||
Message string | ||
Path []string | ||
Cause error | ||
} | ||
|
||
// Error returns the error message. | ||
func (c ConstraintError) Error() string { | ||
result := fmt.Sprintf("Validation failed for '%s': %s", strings.Join(c.Path, "' -> '"), c.Message) | ||
if c.Cause != nil { | ||
result += " (" + c.Cause.Error() + ")" | ||
} | ||
return result | ||
} | ||
|
||
// Unwrap returns the underlying error if any. | ||
func (c ConstraintError) Unwrap() error { | ||
return c.Cause | ||
} | ||
|
||
// NoSuchStepError indicates that the given step is not supported by the plugin. | ||
type NoSuchStepError struct { | ||
Step string | ||
} | ||
|
||
// Error returns the error message. | ||
func (n NoSuchStepError) Error() string { | ||
return fmt.Sprintf("No such step: %s", n.Step) | ||
} | ||
|
||
// BadArgumentError indicates that an invalid configuration was passed to a schema component. The message will | ||
// explain what exactly the problem is, but may not be able to locate the exact error as the schema may be manually | ||
// built. | ||
type BadArgumentError struct { | ||
Message string | ||
Cause error | ||
} | ||
|
||
// Error returns the error message. | ||
func (b BadArgumentError) Error() string { | ||
result := b.Message | ||
if b.Cause != nil { | ||
result += " (" + b.Cause.Error() + ")" | ||
} | ||
return result | ||
} | ||
|
||
// Unwrap returns the underlying error if any. | ||
func (b BadArgumentError) Unwrap() error { | ||
return b.Cause | ||
} | ||
|
||
// UnitParseError indicates that it failed to parse a unit string. | ||
type UnitParseError struct { | ||
Message string | ||
Cause error | ||
} | ||
|
||
func (u UnitParseError) Error() string { | ||
result := u.Message | ||
if u.Cause != nil { | ||
result += " (" + u.Cause.Error() + ")" | ||
} | ||
return result | ||
} | ||
|
||
// Unwrap returns the underlying error if any. | ||
func (u UnitParseError) Unwrap() error { | ||
return u.Cause | ||
} |
This file contains 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,44 @@ | ||
package schema | ||
|
||
// AbstractType describes the common methods all types need to implement. | ||
type AbstractType interface { | ||
ValidateSerialized(data any, path []string) error | ||
} | ||
|
||
// DisplayValue holds the data related to displaying fields. | ||
type DisplayValue struct { | ||
Name *string `json:"name" name:"Name" description:"Short text serving as a name or title for this item." examples:"[\"Fruit\"]" min:"1"` | ||
Description *string `json:"description" name:"Description" description:"Description for this item if needed." examples:"[\"Please select the fruit you would like.\"]" min:"1"` | ||
Icon *string `json:"icon" name:"Icon" description:"SVG icon for this item. Must have the declared size of 64x64, must not include additional namespaces, and must not reference external resources." examples:"[\"<svg ...></svg>\"]" min:"1"` | ||
} | ||
|
||
type enumValueType interface { | ||
int | string | ||
} | ||
|
||
type enumType[T enumValueType] struct { | ||
} | ||
|
||
func (e enumType[T]) ValidateSerialized(data any, path []string) error { | ||
return nil | ||
} | ||
|
||
// EnumStringType is an enum type with string values. | ||
type EnumStringType struct { | ||
enumType[string] | ||
} | ||
|
||
// EnumIntType is an enum type with integer values. | ||
type EnumIntType struct { | ||
enumType[int] | ||
} | ||
|
||
// MapKeyType are types that can be used as map keys. | ||
type MapKeyType interface { | ||
int64 | string | ||
} | ||
|
||
// NumberType is a type collection of number types. | ||
type NumberType interface { | ||
int64 | float64 | ||
} |
Oops, something went wrong.