Skip to content

Commit

Permalink
Merge pull request #11 from nlnwa/fix-workflows
Browse files Browse the repository at this point in the history
ci: update workflows
  • Loading branch information
maeb authored Jul 18, 2024
2 parents c616dae + 084e967 commit ac84594
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 142 deletions.
77 changes: 0 additions & 77 deletions .github/workflows/dockerimage.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/documentation.yaml

This file was deleted.

48 changes: 48 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Release

on:
push:
branches:
- main
tags:
- "v[0-9]+.[0-9]+.[0-9]+**"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
container:
name: Create and publish container image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract metadata (tags, labels, version) for container image
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=ref,event=pr
- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
59 changes: 59 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Test

on: [push]

permissions:
contents: read

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
unit_test:
name: Golang unit tests
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Build
run: go build ./...
- name: Run test
run: go test ./...
lint:
name: Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 'stable'
- uses: golangci/golangci-lint-action@v6
with:
version: latest
build_container:
name: Build container image
runs-on: ubuntu-latest
steps:
- name: Extract metadata (tags, labels) for container image
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=ref,event=pr
- name: Build container image
uses: docker/build-push-action@v6
with:
push: false
build-args: |
VERSION=${{ steps.meta.outputs.version }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
10 changes: 6 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"github.com/opentracing/opentracing-go"
"github.com/rs/zerolog/log"
"os"
"os/signal"
"syscall"
Expand All @@ -11,9 +9,13 @@ import (
"veidemann-scopeservice/pkg/server"
"veidemann-scopeservice/pkg/telemetry"

"github.com/opentracing/opentracing-go"
"github.com/rs/zerolog/log"

"strings"

"github.com/spf13/pflag"
"github.com/spf13/viper"
"strings"
)

func main() {
Expand Down Expand Up @@ -60,7 +62,7 @@ func main() {
defer ms.Close()

go func() {
signals := make(chan os.Signal)
signals := make(chan os.Signal, 2)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)

select {
Expand Down
2 changes: 2 additions & 0 deletions pkg/script/canon_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var CrawlCanonicalizationProfile url.Parser
func InitializeCanonicalizationProfiles(includeFragment bool) {
opts := []url.ParserOption{
url.WithCollapseConsecutiveSlashes(),
url.WithSkipEqualsForEmptySearchParamsValue(),
canonicalizer.WithRemoveUserInfo(),
canonicalizer.WithRepeatedPercentDecoding(),
canonicalizer.WithSortQuery(canonicalizer.SortKeys),
Expand All @@ -23,6 +24,7 @@ func InitializeCanonicalizationProfiles(includeFragment bool) {

opts = []url.ParserOption{
url.WithCollapseConsecutiveSlashes(),
url.WithSkipEqualsForEmptySearchParamsValue(),
canonicalizer.WithRemoveUserInfo(),
canonicalizer.WithSortQuery(canonicalizer.SortKeys),
canonicalizer.WithDefaultScheme("http"),
Expand Down
16 changes: 12 additions & 4 deletions pkg/script/matchers.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package script

import (
"errors"
"fmt"
"go.starlark.net/starlark"
"strings"

"go.starlark.net/starlark"
)

func init() {
Expand All @@ -30,7 +32,10 @@ func isScheme(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple,
if err := starlark.UnpackPositionalArgs(b.Name(), args, kwargs, 1, &scheme); err != nil {
return nil, err
}
qUrl := thread.Local(urlKey).(*UrlValue)
qUrl, ok := thread.Local(urlKey).(*UrlValue)
if !ok {
return nil, fmt.Errorf("url not set")
}
s := strings.TrimRight(qUrl.parsedUri.Protocol(), ":")
scheme = strings.ToLower(scheme)
match := False
Expand All @@ -51,7 +56,10 @@ func isReferrer(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tupl
if err := starlark.UnpackPositionalArgs(b.Name(), args, kwargs, 1, &referrer); err != nil {
return nil, err
}
qUrl := thread.Local(urlKey).(*UrlValue)
qUrl, ok := thread.Local(urlKey).(*UrlValue)
if !ok {
return nil, fmt.Errorf("url not set")
}
s := strings.TrimSpace(qUrl.qUri.Referrer)
referrer = strings.ToLower(referrer)
match := False
Expand Down Expand Up @@ -116,7 +124,7 @@ func maxHopsFromSeed(thread *starlark.Thread, b *starlark.Builtin, args starlark
if h, err := parameterAsInt64(maxHops); err == nil {
match = len(discoveryPath) > int(h)
} else {
if err != None {
if errors.Is(err, None) {
return nil, err
}
}
Expand Down
32 changes: 17 additions & 15 deletions pkg/script/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package script

import (
"errors"
"os"
"strings"
"time"
"veidemann-scopeservice/pkg/telemetry"

"github.com/nlnwa/veidemann-api/go/commons/v1"
"github.com/nlnwa/veidemann-api/go/frontier/v1"
"github.com/nlnwa/veidemann-api/go/scopechecker/v1"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"
"go.starlark.net/resolve"
"go.starlark.net/starlark"
"os"
"strings"
"time"
"veidemann-scopeservice/pkg/telemetry"
"go.starlark.net/syntax"
)

const (
Expand All @@ -29,12 +30,11 @@ var scriptLogger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat:

// RunScopeScript runs the Scope checking script and returns the Scope status.
func RunScopeScript(name string, src interface{}, qUri *frontier.QueuedUri, debug bool) *scopechecker.ScopeCheckResponse {
resolve.AllowNestedDef = true // allow def statements within function bodies
resolve.AllowLambda = true // allow lambda expressions
resolve.AllowFloat = true // allow floating point literals, the 'float' built-in, and x / y
resolve.AllowSet = true // allow the 'set' built-in
resolve.AllowGlobalReassign = true // allow reassignment to top-level names; also, allow if/for/while at top-level
resolve.AllowRecursion = true // allow while statements and recursive functions
options := &syntax.FileOptions{
Set: true, // allow the 'set' built-in
Recursion: true, // allow while statements and recursive functions
GlobalReassign: true, // allow reassignment to top-level names; also, allow if/for/while at top-level
}

consoleLog := strings.Builder{}

Expand All @@ -58,7 +58,7 @@ func RunScopeScript(name string, src interface{}, qUri *frontier.QueuedUri, debu

// Compile source
t := prometheus.NewTimer(telemetry.CompileScriptSeconds)
_, prog, err := starlark.SourceProgram(name, src, starlark.StringDict{}.Has)
_, prog, err := starlark.SourceProgramOptions(options, name, src, starlark.StringDict{}.Has)
if err != nil {
return &scopechecker.ScopeCheckResponse{
Evaluation: scopechecker.ScopeCheckResponse_EXCLUDE,
Expand Down Expand Up @@ -101,11 +101,13 @@ func RunScopeScript(name string, src interface{}, qUri *frontier.QueuedUri, debu
_, err = prog.Init(thread, nil)
t.ObserveDuration()
if err != nil {
if evalErr, ok := err.(*starlark.EvalError); ok {
if evalErr.Unwrap() == EndOfComputation {
evalErr := new(starlark.EvalError)
if errors.As(err, &evalErr) {
if errors.Is(evalErr, EndOfComputation) {
// Computation was aborted
} else {
if w, ok := evalErr.Unwrap().(*wrappedError); ok {
w := new(wrappedError)
if errors.As(evalErr, &w) {
// Script returned Status wrapped as Error
e := (*commons.Error)(w)
return &scopechecker.ScopeCheckResponse{
Expand Down
Loading

0 comments on commit ac84594

Please sign in to comment.