Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanSussman committed Aug 2, 2023
2 parents 7506a1b + adf4f65 commit 37238e6
Show file tree
Hide file tree
Showing 70 changed files with 2,832 additions and 298 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# name of the action
name: integration-test

# trigger on pull_request events that modify this file or any database files
on:
pull_request:
paths:
- '.github/workflows/integration-test.yml'
- 'database/**'

# pipeline to execute
jobs:
database:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_DB: vela
POSTGRES_PASSWORD: notARealPassword12345
POSTGRES_USER: vela
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

env:
POSTGRES_ADDR: postgres://vela:notARealPassword12345@localhost:5432/vela
SQLITE_ADDR: vela.db

steps:
- name: clone
uses: actions/checkout@v3

- name: install go
uses: actions/setup-go@v4
with:
# use version from go.mod file
go-version-file: 'go.mod'
cache: true
check-latest: true

- name: test
run: |
make integration-test
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:

- name: test
run: |
go test -race -covermode=atomic -coverprofile=coverage.out ./...
make test
- name: coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.out
file: coverage.out
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Use of this source code is governed by the LICENSE file in this repository.

FROM alpine as certs
FROM alpine:3.18.2@sha256:25fad2a32ad1f6f510e528448ae1ec69a28ef81916a004d3629874104f8a7f70 as certs

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

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-alpine
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Use of this source code is governed by the LICENSE file in this repository.

FROM alpine
FROM alpine:3.18.2@sha256:25fad2a32ad1f6f510e528448ae1ec69a28ef81916a004d3629874104f8a7f70

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

Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ fix:
@echo "### Fixing Go Code"
@go fix ./...

# The `integration-test` target is intended to run all integration tests for the Go source code.
.PHONY: integration-test
integration-test:
@echo
@echo "### Integration Testing"
INTEGRATION=1 go test -run TestDatabase_Integration ./...

# The `test` target is intended to run
# the tests for the Go source code.
#
Expand All @@ -99,18 +106,15 @@ fix:
test:
@echo
@echo "### Testing Go Code"
@go test -race ./...
@go test -race -covermode=atomic -coverprofile=coverage.out ./...

# The `test-cover` target is intended to run
# the tests for the Go source code and then
# open the test coverage report.
#
# Usage: `make test-cover`
.PHONY: test-cover
test-cover:
@echo
@echo "### Creating test coverage report"
@go test -race -covermode=atomic -coverprofile=coverage.out ./...
test-cover: test
@echo
@echo "### Opening test coverage report"
@go tool cover -html=coverage.out
Expand Down
4 changes: 2 additions & 2 deletions api/admin/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func UpdateRepo(c *gin.Context) {
}

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

Expand All @@ -75,5 +75,5 @@ func UpdateRepo(c *gin.Context) {
return
}

c.JSON(http.StatusOK, input)
c.JSON(http.StatusOK, r)
}
2 changes: 1 addition & 1 deletion api/build/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func CreateBuild(c *gin.Context) {
}

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

Expand Down
29 changes: 28 additions & 1 deletion api/build/list_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ import (
// required: true
// type: string
// - in: query
// name: event
// description: Filter by build event
// type: string
// enum:
// - comment
// - deployment
// - pull_request
// - push
// - schedule
// - tag
// - in: query
// name: branch
// description: Filter builds by branch
// type: string
// - in: query
// name: status
// description: Filter by build status
// type: string
// enum:
// - canceled
// - error
// - failure
// - killed
// - pending
// - running
// - success
// - in: query
// name: page
// description: The page of results to retrieve
// type: integer
Expand Down Expand Up @@ -109,7 +136,7 @@ func ListBuildsForOrg(c *gin.Context) {
// verify the event provided is a valid event type
if event != constants.EventComment && event != constants.EventDeploy &&
event != constants.EventPush && event != constants.EventPull &&
event != constants.EventTag {
event != constants.EventTag && event != constants.EventSchedule {
retErr := fmt.Errorf("unable to process event %s: invalid event type provided", event)

util.HandleError(c, http.StatusBadRequest, retErr)
Expand Down
9 changes: 5 additions & 4 deletions api/build/list_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ import (
// description: Filter by build event
// type: string
// enum:
// - push
// - comment
// - deployment
// - pull_request
// - push
// - schedule
// - tag
// - deployment
// - comment
// - in: query
// name: commit
// description: Filter builds based on the commit hash
Expand Down Expand Up @@ -159,7 +160,7 @@ func ListBuildsForRepo(c *gin.Context) {
// verify the event provided is a valid event type
if event != constants.EventComment && event != constants.EventDeploy &&
event != constants.EventPush && event != constants.EventPull &&
event != constants.EventTag {
event != constants.EventTag && event != constants.EventSchedule {
retErr := fmt.Errorf("unable to process event %s: invalid event type provided", event)

util.HandleError(c, http.StatusBadRequest, retErr)
Expand Down
2 changes: 1 addition & 1 deletion api/build/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func RestartBuild(c *gin.Context) {
}

// send API call to update repo for ensuring counter is incremented
err = database.FromContext(c).UpdateRepo(r)
r, err = database.FromContext(c).UpdateRepo(r)
if err != nil {
retErr := fmt.Errorf("unable to restart build: failed to update repo %s: %w", r.GetFullName(), err)
util.HandleError(c, http.StatusBadRequest, retErr)
Expand Down
2 changes: 1 addition & 1 deletion api/pipeline/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func CompilePipeline(c *gin.Context) {
compiler := compiler.FromContext(c).Duplicate().WithCommit(p.GetCommit()).WithMetadata(m).WithRepo(r).WithUser(u)

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

Expand Down
2 changes: 1 addition & 1 deletion api/pipeline/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func ExpandPipeline(c *gin.Context) {
compiler := compiler.FromContext(c).Duplicate().WithCommit(p.GetCommit()).WithMetadata(m).WithRepo(r).WithUser(u)

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

Expand Down
2 changes: 1 addition & 1 deletion api/pipeline/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func ValidatePipeline(c *gin.Context) {
}

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

Expand Down
2 changes: 1 addition & 1 deletion api/repo/chown.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func ChownRepo(c *gin.Context) {
r.SetUserID(u.GetID())

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

Expand Down
10 changes: 2 additions & 8 deletions api/repo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,30 +285,24 @@ func CreateRepo(c *gin.Context) {
dbRepo.SetActive(true)

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

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

return
}

// send API call to capture the updated repo
r, _ = database.FromContext(c).GetRepoForOrg(dbRepo.GetOrg(), dbRepo.GetName())
} else {
// send API call to create the repo
err = database.FromContext(c).CreateRepo(r)
r, err = database.FromContext(c).CreateRepo(r)
if err != nil {
retErr := fmt.Errorf("unable to create new repo %s: %w", r.GetFullName(), err)

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

return
}

// send API call to capture the created repo
r, _ = database.FromContext(c).GetRepoForOrg(r.GetOrg(), r.GetName())
}

// create init hook in the DB after repo has been added in order to capture its ID
Expand Down
2 changes: 1 addition & 1 deletion api/repo/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func DeleteRepo(c *gin.Context) {
// Mark the repo as inactive
r.SetActive(false)

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

Expand Down
2 changes: 1 addition & 1 deletion api/repo/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func RepairRepo(c *gin.Context) {
r.SetActive(true)

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

Expand Down
5 changes: 1 addition & 4 deletions api/repo/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func UpdateRepo(c *gin.Context) {
}

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

Expand All @@ -304,8 +304,5 @@ func UpdateRepo(c *gin.Context) {
return
}

// send API call to capture the updated repo
r, _ = database.FromContext(c).GetRepoForOrg(r.GetOrg(), r.GetName())

c.JSON(http.StatusOK, r)
}
36 changes: 23 additions & 13 deletions api/schedule/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,31 @@ func validateEntry(minimum time.Duration, entry string) error {
return fmt.Errorf("invalid entry of %s", entry)
}

// check the previous occurrence of the entry
prevTime, err := gronx.PrevTick(entry, true)
if err != nil {
return err
}
// iterate 5 times through ticks in an effort to catch scalene entries
tickForward := 5

// check the next occurrence of the entry
nextTime, err := gronx.NextTick(entry, true)
if err != nil {
return err
}
// start with now
t := time.Now().UTC()

for i := 0; i < tickForward; i++ {
// check the previous occurrence of the entry
prevTime, err := gronx.PrevTickBefore(entry, t, true)
if err != nil {
return err
}

// check the next occurrence of the entry
nextTime, err := gronx.NextTickAfter(entry, t, false)
if err != nil {
return err
}

// ensure the time between previous and next schedule exceeds the minimum duration
if nextTime.Sub(prevTime) < minimum {
return fmt.Errorf("entry needs to occur less frequently than every %s", minimum)
}

// ensure the time between previous and next schedule exceeds the minimum duration
if nextTime.Sub(prevTime) < minimum {
return fmt.Errorf("entry needs to occur less frequently than every %s", minimum)
t = nextTime
}

return nil
Expand Down
16 changes: 16 additions & 0 deletions api/schedule/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ func Test_validateEntry(t *testing.T) {
},
wantErr: true,
},
{
name: "exceeds minimum frequency with scalene entry pattern",
args: args{
minimum: 30 * time.Minute,
entry: "1,2,45 * * * *",
},
wantErr: true,
},
{
name: "meets minimum frequency",
args: args{
Expand All @@ -51,6 +59,14 @@ func Test_validateEntry(t *testing.T) {
},
wantErr: false,
},
{
name: "meets minimum frequency with comma entry pattern",
args: args{
minimum: 15 * time.Minute,
entry: "0,15,30,45 * * * *",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading

0 comments on commit 37238e6

Please sign in to comment.