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

feat: add server mode #12

Merged
merged 11 commits into from
May 9, 2024
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
114 changes: 0 additions & 114 deletions .github/workflows/build.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ name: "CodeQL"

on:
push:
tags:
- v*
branches:
- main
pull_request:

jobs:
# ------------------------------
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Gitleaks

on:
push:
branches:
- "main"
tags:
- "v*"
- v*
branches:
- main
pull_request:

permissions:
Expand All @@ -20,6 +20,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- uses: gitleaks/gitleaks-action@v2
env:
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/grype.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Grype

on:
push:
branches:
- "main"
tags:
- "v*"
- v*
branches:
- main
pull_request:

jobs:
Expand All @@ -22,6 +22,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: anchore/scan-action@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: actions/setup-go@v5
with:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
DOCKER_CLI_EXPERIMENTAL: "enabled"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: arduino/setup-task@v2
with:
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Security

on:
push:
tags:
- v*
branches:
- main
pull_request:

permissions:
contents: read

jobs:
# ------------------------------

govulncheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: setup
run: task setup

- name: install govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest

- name: run govulncheck
run: govulncheck ./...

# ------------------------------

semgrep:
runs-on: ubuntu-latest
container:
image: returntocorp/semgrep
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: actions/checkout@v4
with:
repository: dgryski/semgrep-go
path: rules

- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: semgrep
run: semgrep scan --error --enable-nosem -f ./rules .
59 changes: 59 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Test

on:
push:
tags:
- v*
branches:
- main
pull_request:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: setup-tparse
run: go install github.com/mfridman/tparse@latest

- uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: setup
run: |
task setup
task build

- name: test
run: ./scripts/test.sh

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Ensure scm-engine binary work
run: ./scm-engine -h

- name: Test scm-engine against test GitLab project
run: ./scm-engine evaluate 1
env:
SCM_ENGINE_TOKEN: "${{ secrets.GITLAB_INTEGRATION_TEST_API_TOKEN }}"
SCM_ENGINE_CONFIG_FILE: ".scm-engine.example.yml"
GITLAB_PROJECT: "jippi/scm-engine-schema-test"
GITLAB_BASEURL: https://gitlab.com/

- name: Show any diff that may be in the project
run: git diff
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ linters-settings:
- i
- id
- ok
- r
- w

tagalign:
# Align and sort can be used together or separately.
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ builds:
flags:
- -trimpath
ldflags:
- -s -w -X {{.ModulePath}}/cmd.version={{.Version}} -X {{.ModulePath}}/cmd.commit={{.Commit}} -X {{.ModulePath}}/cmd.date={{ .CommitDate }} -X {{.ModulePath}}/cmd.treeState={{ .IsGitDirty }}
- -s -w -X {{.ModulePath}.version={{.Version}} -X {{.ModulePath}}.commit={{.Commit}} -X {{.ModulePath}}.date={{ .CommitDate }} -X {{.ModulePath}}.treeState={{ .IsGitDirty }}

universal_binaries:
- replace: false
Expand Down
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ tasks:

build:
desc: Build the binary
cmds:
- go build -o scm-engine .
sources:
- ./**/*.go
generates:
- ./scm-engine
cmds:
- go build -o scm-engine .

test:
desc: Run tests
Expand Down
6 changes: 3 additions & 3 deletions cmd/cmd_evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ func Evaluate(cCtx *cli.Context) error {
}

for _, mr := range res {
if err := ProcessMR(ctx, client, cfg, mr.ID); err != nil {
if err := ProcessMR(ctx, client, cfg, mr.ID, nil); err != nil {
return err
}
}

// If the flag is set, use that for evaluation
case cCtx.String(FlagMergeRequestID) != "":
return ProcessMR(ctx, client, cfg, cCtx.String(FlagMergeRequestID))
return ProcessMR(ctx, client, cfg, cCtx.String(FlagMergeRequestID), nil)

// If no flag is set, we require arguments
case cCtx.Args().Len() == 0:
return fmt.Errorf("Missing required argument: %s", FlagMergeRequestID)

default:
for _, mr := range cCtx.Args().Slice() {
if err := ProcessMR(ctx, client, cfg, mr); err != nil {
if err := ProcessMR(ctx, client, cfg, mr, nil); err != nil {
return err
}
}
Expand Down
Loading
Loading