Skip to content

Commit 44e97bb

Browse files
authored
Merge branch 'main' into chore/database/housekeeping
2 parents f3970d2 + adf4f65 commit 44e97bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2550
-200
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# name of the action
2+
name: integration-test
3+
4+
# trigger on pull_request events that modify this file or any database files
5+
on:
6+
pull_request:
7+
paths:
8+
- '.github/workflows/integration-test.yml'
9+
- 'database/**'
10+
11+
# pipeline to execute
12+
jobs:
13+
database:
14+
runs-on: ubuntu-latest
15+
16+
services:
17+
postgres:
18+
image: postgres:15-alpine
19+
env:
20+
POSTGRES_DB: vela
21+
POSTGRES_PASSWORD: notARealPassword12345
22+
POSTGRES_USER: vela
23+
options: >-
24+
--health-cmd pg_isready
25+
--health-interval 10s
26+
--health-timeout 5s
27+
--health-retries 5
28+
ports:
29+
- 5432:5432
30+
31+
env:
32+
POSTGRES_ADDR: postgres://vela:notARealPassword12345@localhost:5432/vela
33+
SQLITE_ADDR: vela.db
34+
35+
steps:
36+
- name: clone
37+
uses: actions/checkout@v3
38+
39+
- name: install go
40+
uses: actions/setup-go@v4
41+
with:
42+
# use version from go.mod file
43+
go-version-file: 'go.mod'
44+
cache: true
45+
check-latest: true
46+
47+
- name: test
48+
run: |
49+
make integration-test

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ jobs:
2525

2626
- name: test
2727
run: |
28-
go test -race -covermode=atomic -coverprofile=coverage.out ./...
28+
make test
2929
3030
- name: coverage
3131
uses: codecov/codecov-action@v3
3232
with:
3333
token: ${{ secrets.CODECOV_TOKEN }}
34-
file: coverage.out
34+
file: coverage.out

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Use of this source code is governed by the LICENSE file in this repository.
44

5-
FROM alpine as certs
5+
FROM alpine:3.18.2@sha256:25fad2a32ad1f6f510e528448ae1ec69a28ef81916a004d3629874104f8a7f70 as certs
66

77
RUN apk add --update --no-cache ca-certificates
88

Dockerfile-alpine

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Use of this source code is governed by the LICENSE file in this repository.
44

5-
FROM alpine
5+
FROM alpine:3.18.2@sha256:25fad2a32ad1f6f510e528448ae1ec69a28ef81916a004d3629874104f8a7f70
66

77
RUN apk add --update --no-cache ca-certificates
88

Makefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ fix:
9191
@echo "### Fixing Go Code"
9292
@go fix ./...
9393

94+
# The `integration-test` target is intended to run all integration tests for the Go source code.
95+
.PHONY: integration-test
96+
integration-test:
97+
@echo
98+
@echo "### Integration Testing"
99+
INTEGRATION=1 go test -run TestDatabase_Integration ./...
100+
94101
# The `test` target is intended to run
95102
# the tests for the Go source code.
96103
#
@@ -99,18 +106,15 @@ fix:
99106
test:
100107
@echo
101108
@echo "### Testing Go Code"
102-
@go test -race ./...
109+
@go test -race -covermode=atomic -coverprofile=coverage.out ./...
103110

104111
# The `test-cover` target is intended to run
105112
# the tests for the Go source code and then
106113
# open the test coverage report.
107114
#
108115
# Usage: `make test-cover`
109116
.PHONY: test-cover
110-
test-cover:
111-
@echo
112-
@echo "### Creating test coverage report"
113-
@go test -race -covermode=atomic -coverprofile=coverage.out ./...
117+
test-cover: test
114118
@echo
115119
@echo "### Opening test coverage report"
116120
@go tool cover -html=coverage.out

api/admin/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func UpdateRepo(c *gin.Context) {
6666
}
6767

6868
// send API call to update the repo
69-
err = database.FromContext(c).UpdateRepo(input)
69+
r, err := database.FromContext(c).UpdateRepo(input)
7070
if err != nil {
7171
retErr := fmt.Errorf("unable to update repo %d: %w", input.GetID(), err)
7272

@@ -75,5 +75,5 @@ func UpdateRepo(c *gin.Context) {
7575
return
7676
}
7777

78-
c.JSON(http.StatusOK, input)
78+
c.JSON(http.StatusOK, r)
7979
}

api/build/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func CreateBuild(c *gin.Context) {
329329
}
330330

331331
// send API call to update repo for ensuring counter is incremented
332-
err = database.FromContext(c).UpdateRepo(r)
332+
r, err = database.FromContext(c).UpdateRepo(r)
333333
if err != nil {
334334
retErr := fmt.Errorf("unable to create new build: failed to update repo %s: %w", r.GetFullName(), err)
335335

api/build/restart.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func RestartBuild(c *gin.Context) {
320320
}
321321

322322
// send API call to update repo for ensuring counter is incremented
323-
err = database.FromContext(c).UpdateRepo(r)
323+
r, err = database.FromContext(c).UpdateRepo(r)
324324
if err != nil {
325325
retErr := fmt.Errorf("unable to restart build: failed to update repo %s: %w", r.GetFullName(), err)
326326
util.HandleError(c, http.StatusBadRequest, retErr)

api/pipeline/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func CompilePipeline(c *gin.Context) {
9797
compiler := compiler.FromContext(c).Duplicate().WithCommit(p.GetCommit()).WithMetadata(m).WithRepo(r).WithUser(u)
9898

9999
// compile the pipeline
100-
pipeline, _, err := compiler.CompileLite(p.GetData(), true, true, nil)
100+
pipeline, _, err := compiler.CompileLite(p.GetData(), true, true)
101101
if err != nil {
102102
retErr := fmt.Errorf("unable to compile pipeline %s: %w", entry, err)
103103

api/pipeline/expand.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func ExpandPipeline(c *gin.Context) {
9898
compiler := compiler.FromContext(c).Duplicate().WithCommit(p.GetCommit()).WithMetadata(m).WithRepo(r).WithUser(u)
9999

100100
// expand the templates in the pipeline
101-
pipeline, _, err := compiler.CompileLite(p.GetData(), true, false, nil)
101+
pipeline, _, err := compiler.CompileLite(p.GetData(), true, false)
102102
if err != nil {
103103
retErr := fmt.Errorf("unable to expand pipeline %s: %w", entry, err)
104104

api/pipeline/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func ValidatePipeline(c *gin.Context) {
105105
}
106106

107107
// validate the pipeline
108-
pipeline, _, err := compiler.CompileLite(p.GetData(), template, false, nil)
108+
pipeline, _, err := compiler.CompileLite(p.GetData(), template, false)
109109
if err != nil {
110110
retErr := fmt.Errorf("unable to validate pipeline %s: %w", entry, err)
111111

api/repo/chown.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func ChownRepo(c *gin.Context) {
6868
r.SetUserID(u.GetID())
6969

7070
// send API call to update the repo
71-
err := database.FromContext(c).UpdateRepo(r)
71+
_, err := database.FromContext(c).UpdateRepo(r)
7272
if err != nil {
7373
retErr := fmt.Errorf("unable to change owner of repo %s to %s: %w", r.GetFullName(), u.GetName(), err)
7474

api/repo/create.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,30 +285,24 @@ func CreateRepo(c *gin.Context) {
285285
dbRepo.SetActive(true)
286286

287287
// send API call to update the repo
288-
err = database.FromContext(c).UpdateRepo(dbRepo)
288+
r, err = database.FromContext(c).UpdateRepo(dbRepo)
289289
if err != nil {
290290
retErr := fmt.Errorf("unable to set repo %s to active: %w", dbRepo.GetFullName(), err)
291291

292292
util.HandleError(c, http.StatusInternalServerError, retErr)
293293

294294
return
295295
}
296-
297-
// send API call to capture the updated repo
298-
r, _ = database.FromContext(c).GetRepoForOrg(dbRepo.GetOrg(), dbRepo.GetName())
299296
} else {
300297
// send API call to create the repo
301-
err = database.FromContext(c).CreateRepo(r)
298+
r, err = database.FromContext(c).CreateRepo(r)
302299
if err != nil {
303300
retErr := fmt.Errorf("unable to create new repo %s: %w", r.GetFullName(), err)
304301

305302
util.HandleError(c, http.StatusInternalServerError, retErr)
306303

307304
return
308305
}
309-
310-
// send API call to capture the created repo
311-
r, _ = database.FromContext(c).GetRepoForOrg(r.GetOrg(), r.GetName())
312306
}
313307

314308
// create init hook in the DB after repo has been added in order to capture its ID

api/repo/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func DeleteRepo(c *gin.Context) {
8888
// Mark the repo as inactive
8989
r.SetActive(false)
9090

91-
err = database.FromContext(c).UpdateRepo(r)
91+
_, err = database.FromContext(c).UpdateRepo(r)
9292
if err != nil {
9393
retErr := fmt.Errorf("unable to set repo %s to inactive: %w", r.GetFullName(), err)
9494

api/repo/repair.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func RepairRepo(c *gin.Context) {
122122
r.SetActive(true)
123123

124124
// send API call to update the repo
125-
err := database.FromContext(c).UpdateRepo(r)
125+
_, err := database.FromContext(c).UpdateRepo(r)
126126
if err != nil {
127127
retErr := fmt.Errorf("unable to set repo %s to active: %w", r.GetFullName(), err)
128128

api/repo/update.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func UpdateRepo(c *gin.Context) {
295295
}
296296

297297
// send API call to update the repo
298-
err = database.FromContext(c).UpdateRepo(r)
298+
r, err = database.FromContext(c).UpdateRepo(r)
299299
if err != nil {
300300
retErr := fmt.Errorf("unable to update repo %s: %w", r.GetFullName(), err)
301301

@@ -304,8 +304,5 @@ func UpdateRepo(c *gin.Context) {
304304
return
305305
}
306306

307-
// send API call to capture the updated repo
308-
r, _ = database.FromContext(c).GetRepoForOrg(r.GetOrg(), r.GetName())
309-
310307
c.JSON(http.StatusOK, r)
311308
}

api/scm/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func SyncRepo(c *gin.Context) {
8080
r.SetActive(false)
8181

8282
// update repo in database
83-
err := database.FromContext(c).UpdateRepo(r)
83+
_, err := database.FromContext(c).UpdateRepo(r)
8484
if err != nil {
8585
retErr := fmt.Errorf("unable to update repo for org %s: %w", o, err)
8686

api/scm/sync_org.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func SyncReposForOrg(c *gin.Context) {
113113
if err != nil {
114114
repo.SetActive(false)
115115

116-
err := database.FromContext(c).UpdateRepo(repo)
116+
_, err := database.FromContext(c).UpdateRepo(repo)
117117
if err != nil {
118118
retErr := fmt.Errorf("unable to update repo for org %s: %w", o, err)
119119

api/webhook/post.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ func PostWebhook(c *gin.Context) {
621621
} // end of retry loop
622622

623623
// send API call to update repo for ensuring counter is incremented
624-
err = database.FromContext(c).UpdateRepo(repo)
624+
repo, err = database.FromContext(c).UpdateRepo(repo)
625625
if err != nil {
626626
retErr := fmt.Errorf("%s: failed to update repo %s: %w", baseErr, repo.GetFullName(), err)
627627
util.HandleError(c, http.StatusBadRequest, retErr)
@@ -759,7 +759,7 @@ func handleRepositoryEvent(c *gin.Context, m *types.Metadata, h *library.Hook, r
759759
}
760760

761761
// update repo object in the database after applying edits
762-
err = database.FromContext(c).UpdateRepo(dbRepo)
762+
dbRepo, err = database.FromContext(c).UpdateRepo(dbRepo)
763763
if err != nil {
764764
retErr := fmt.Errorf("%s: failed to update repo %s: %w", baseErr, r.GetFullName(), err)
765765

@@ -891,7 +891,7 @@ func renameRepository(h *library.Hook, r *library.Repo, c *gin.Context, m *types
891891
dbR.SetPreviousName(r.GetPreviousName())
892892

893893
// update the repo in the database
894-
err = database.FromContext(c).UpdateRepo(dbR)
894+
dbR, err = database.FromContext(c).UpdateRepo(dbR)
895895
if err != nil {
896896
retErr := fmt.Errorf("%s: failed to update repo %s/%s in database", baseErr, prevOrg, prevRepo)
897897
util.HandleError(c, http.StatusBadRequest, retErr)

cmd/vela-server/schedule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ func processSchedule(s *library.Schedule, compiler compiler.Engine, database dat
373373
} // end of retry loop
374374

375375
// send API call to update repo for ensuring counter is incremented
376-
err = database.UpdateRepo(r)
376+
r, err = database.UpdateRepo(r)
377377
if err != nil {
378378
return fmt.Errorf("unable to update repo %s: %w", r.GetFullName(), err)
379379
}

compiler/engine.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Engine interface {
2525
// CompileLite defines a function that produces an light executable
2626
// representation of a pipeline from an object. This calls
2727
// Parse internally to convert the object to a yaml configuration.
28-
CompileLite(interface{}, bool, bool, []string) (*yaml.Build, *library.Pipeline, error)
28+
CompileLite(interface{}, bool, bool) (*yaml.Build, *library.Pipeline, error)
2929

3030
// Duplicate defines a function that
3131
// creates a clone of the Engine.
@@ -130,6 +130,9 @@ type Engine interface {
130130
// WithLocal defines a function that sets
131131
// the compiler local field in the Engine.
132132
WithLocal(bool) Engine
133+
// WithLocalTemplates defines a function that sets
134+
// the compiler local templates field in the Engine.
135+
WithLocalTemplates([]string) Engine
133136
// WithMetadata defines a function that sets
134137
// the compiler Metadata type in the Engine.
135138
WithMetadata(*types.Metadata) Engine

0 commit comments

Comments
 (0)