Skip to content

Commit 46821ec

Browse files
authored
feat: add server mode (#12)
* feat: add server mode * fix: remove unneeded struct field from server payload * feat: add support for gitlab webhook secrets * feat: expose full webhook payload in expr as 'webhook_event' * build: go mod tidy * feat: add tui package and reorganize log output * feat: configure what ip/port server should listen to * build: include version in build artefacts * ci: omit -h flag in build test * ci: full clone
1 parent c61feef commit 46821ec

35 files changed

+1987
-331
lines changed

.github/workflows/build.yml

-114
This file was deleted.

.github/workflows/codeql.yml

+3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ name: "CodeQL"
22

33
on:
44
push:
5+
tags:
6+
- v*
57
branches:
68
- main
9+
pull_request:
710

811
jobs:
912
# ------------------------------

.github/workflows/gitleaks.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: Gitleaks
22

33
on:
44
push:
5-
branches:
6-
- "main"
75
tags:
8-
- "v*"
6+
- v*
7+
branches:
8+
- main
99
pull_request:
1010

1111
permissions:
@@ -20,6 +20,7 @@ jobs:
2020
- uses: actions/checkout@v4
2121
with:
2222
fetch-depth: 0
23+
ref: ${{ github.event.pull_request.head.sha }}
2324

2425
- uses: gitleaks/gitleaks-action@v2
2526
env:

.github/workflows/grype.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: Grype
22

33
on:
44
push:
5-
branches:
6-
- "main"
75
tags:
8-
- "v*"
6+
- v*
7+
branches:
8+
- main
99
pull_request:
1010

1111
jobs:
@@ -22,6 +22,8 @@ jobs:
2222

2323
steps:
2424
- uses: actions/checkout@v4
25+
with:
26+
ref: ${{ github.event.pull_request.head.sha }}
2527

2628
- uses: anchore/scan-action@v3
2729
with:

.github/workflows/lint.yml

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
runs-on: ubuntu-latest
2727
steps:
2828
- uses: actions/checkout@v4
29+
with:
30+
ref: ${{ github.event.pull_request.head.sha }}
2931

3032
- uses: actions/setup-go@v5
3133
with:

.github/workflows/release.yml

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
DOCKER_CLI_EXPERIMENTAL: "enabled"
2020
steps:
2121
- uses: actions/checkout@v4
22-
with:
23-
fetch-depth: 0
2422

2523
- uses: arduino/setup-task@v2
2624
with:

.github/workflows/security.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Security
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
branches:
8+
- main
9+
pull_request:
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
# ------------------------------
16+
17+
govulncheck:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
ref: ${{ github.event.pull_request.head.sha }}
23+
24+
- uses: actions/setup-go@v5
25+
with:
26+
go-version-file: go.mod
27+
28+
- uses: arduino/setup-task@v2
29+
with:
30+
version: 3.x
31+
repo-token: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: setup
34+
run: task setup
35+
36+
- name: install govulncheck
37+
run: go install golang.org/x/vuln/cmd/govulncheck@latest
38+
39+
- name: run govulncheck
40+
run: govulncheck ./...
41+
42+
# ------------------------------
43+
44+
semgrep:
45+
runs-on: ubuntu-latest
46+
container:
47+
image: returntocorp/semgrep
48+
steps:
49+
- uses: actions/checkout@v4
50+
with:
51+
ref: ${{ github.event.pull_request.head.sha }}
52+
53+
- uses: actions/checkout@v4
54+
with:
55+
repository: dgryski/semgrep-go
56+
path: rules
57+
58+
- uses: actions/setup-go@v5
59+
with:
60+
go-version-file: go.mod
61+
62+
- name: semgrep
63+
run: semgrep scan --error --enable-nosem -f ./rules .

.github/workflows/test.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
branches:
8+
- main
9+
pull_request:
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
ref: ${{ github.event.pull_request.head.sha }}
21+
22+
- uses: actions/setup-go@v5
23+
with:
24+
go-version-file: go.mod
25+
26+
- name: setup-tparse
27+
run: go install github.com/mfridman/tparse@latest
28+
29+
- uses: arduino/setup-task@v2
30+
with:
31+
version: 3.x
32+
repo-token: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: setup
35+
run: |
36+
task setup
37+
task build
38+
39+
- name: test
40+
run: ./scripts/test.sh
41+
42+
- name: Upload coverage reports to Codecov
43+
uses: codecov/codecov-action@v4
44+
with:
45+
token: ${{ secrets.CODECOV_TOKEN }}
46+
47+
- name: Ensure scm-engine binary work
48+
run: ./scm-engine -h
49+
50+
- name: Test scm-engine against test GitLab project
51+
run: ./scm-engine evaluate 1
52+
env:
53+
SCM_ENGINE_TOKEN: "${{ secrets.GITLAB_INTEGRATION_TEST_API_TOKEN }}"
54+
SCM_ENGINE_CONFIG_FILE: ".scm-engine.example.yml"
55+
GITLAB_PROJECT: "jippi/scm-engine-schema-test"
56+
GITLAB_BASEURL: https://gitlab.com/
57+
58+
- name: Show any diff that may be in the project
59+
run: git diff

.golangci.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ linters-settings:
179179
- i
180180
- id
181181
- ok
182+
- r
183+
- w
182184

183185
tagalign:
184186
# Align and sort can be used together or separately.

.goreleaser.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ builds:
4141
flags:
4242
- -trimpath
4343
ldflags:
44-
- -s -w -X {{.ModulePath}}/cmd.version={{.Version}} -X {{.ModulePath}}/cmd.commit={{.Commit}} -X {{.ModulePath}}/cmd.date={{ .CommitDate }} -X {{.ModulePath}}/cmd.treeState={{ .IsGitDirty }}
44+
- -s -w -X {{.ModulePath}.version={{.Version}} -X {{.ModulePath}}.commit={{.Commit}} -X {{.ModulePath}}.date={{ .CommitDate }} -X {{.ModulePath}}.treeState={{ .IsGitDirty }}
4545

4646
universal_binaries:
4747
- replace: false

Taskfile.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ tasks:
2020

2121
build:
2222
desc: Build the binary
23+
cmds:
24+
- go build -o scm-engine .
2325
sources:
2426
- ./**/*.go
2527
generates:
2628
- ./scm-engine
27-
cmds:
28-
- go build -o scm-engine .
2929

3030
test:
3131
desc: Run tests

cmd/cmd_evaluate.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ func Evaluate(cCtx *cli.Context) error {
3232
}
3333

3434
for _, mr := range res {
35-
if err := ProcessMR(ctx, client, cfg, mr.ID); err != nil {
35+
if err := ProcessMR(ctx, client, cfg, mr.ID, nil); err != nil {
3636
return err
3737
}
3838
}
3939

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

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

4848
default:
4949
for _, mr := range cCtx.Args().Slice() {
50-
if err := ProcessMR(ctx, client, cfg, mr); err != nil {
50+
if err := ProcessMR(ctx, client, cfg, mr, nil); err != nil {
5151
return err
5252
}
5353
}

0 commit comments

Comments
 (0)