Skip to content

Commit

Permalink
wip: add poller and webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Feb 19, 2024
1 parent e6a596d commit 07ce508
Show file tree
Hide file tree
Showing 18 changed files with 516 additions and 55 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# .github/workflows/automerge.yml

name: Dependabot (auto-merge)

on:
pull_request:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47 changes: 47 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# .github/workflows/main.yml

name: Test & Lint

on:
workflow_call:
push:
branches:
- main
- release/*
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
permissions:
checks: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- run: make test
- uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Go Test Results
path: .test/reports/**-test.xml
reporter: java-junit
fail-on-error: 'true'
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: Test Reports
path: .test/reports/**

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
check-latest: true
- run: make lint
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# .github/workflows/release.yml

name: Release

on:
push:
tags:
- 'v*'

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
test:
permissions:
checks: write
uses: ./.github/workflows/main.yml

release:
runs-on: ubuntu-latest
needs: [ test ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- run: make release
if: success()
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ build: ## Build the binary file.
generate: ## Generate code.
$(GO) generate ./...
$(GO_RUN_TOOLS) github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -config ./api/config.models.yml ./api/api.yml
$(GO_RUN_TOOLS) github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -config ./api/config.client.yml ./api/api.yml
$(GO_RUN_TOOLS) github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -config ./api/config.server.yml ./api/api.yml
$(GO_RUN_TOOLS) github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -config ./api/config.client.yml ./api/api.yml
$(GO_RUN_TOOLS) github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -config ./api/config.server.yml ./api/api.yml

.PHONY: fmt
fmt: ## Run go fmt against code.
Expand Down
57 changes: 45 additions & 12 deletions api/api.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.0
openapi: 3.1.0

info:
version: 1.0.0
Expand Down Expand Up @@ -54,6 +54,8 @@ paths:
parameters:
- $ref: '#/components/parameters/offsetParam'
- $ref: '#/components/parameters/limitParam'
security:
- bearerAuth: ['read:teams']
responses:
'200':
description: Successfull response
Expand Down Expand Up @@ -184,6 +186,10 @@ components:
$ref: '#/components/schemas/Team'

securitySchemes:
cookieAuth:
type: apiKey
in: cookie
name: JSESSIONID
bearerAuth:
type: http
scheme: bearer
Expand All @@ -207,6 +213,41 @@ components:
type: array
items:

System:
type: object
required:
- name
properties:
id:
type: string
format: uuid
readOnly: true
x-oapi-codegen-extra-tags:
gorm: "type:uuid;default:gen_random_uuid()"
name:
type: string
description: Name of the system
example: "eu-west-1"
description:
type: string
description: A description of the system.
createdAt:
type: string
format: date-time
description: Creation date and time
example: "2021-01-30T08:30:00Z"
updatedAt:
type: string
format: date-time
description: Creation date and time
example: "2021-01-30T08:30:00Z"
deletedAt:
type: string
format: date-time
description: Creation date and time
example: "2021-01-30T08:30:00Z"


Team:
type: object
required:
Expand Down Expand Up @@ -251,22 +292,14 @@ components:
type: string
date:
type: string
System:
type: object
required:
- id
- name
properties:
id:
type: string
name:
type: string

Systems:
type: array
maxItems: 100
items:
$ref: "#/components/schemas/System"

security:
- bearer_auth: []
- cookieAuth: []
- bearerAuth: []
- api_key: []
2 changes: 1 addition & 1 deletion api/config.models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package: api
generate:
models: true
embedded-spec: true
output: api/models.gen.go
output: examples/api/models.gen.go
output-options:
skip-prune: true
63 changes: 39 additions & 24 deletions api/models.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions api/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions api/sources/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ var WebhookResource = schema.GroupResource{
Group: GroupName,
Resource: "webhook",
}

// HTTPResource ...
var HTTPResource = schema.GroupResource{
Group: GroupName,
Resource: "http",
}
6 changes: 4 additions & 2 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/katallaxie/pkg/logger"
"github.com/katallaxie/pkg/server"
models "github.com/zeiss/typhoon/api"

"github.com/spf13/cobra"
"gorm.io/driver/postgres"
Expand Down Expand Up @@ -62,7 +61,10 @@ func run(ctx context.Context) error {
return err
}

conn.AutoMigrate(&models.Team{})
err = config.RunMigrations(conn)
if err != nil {
return err
}

db := adapter.NewDB(conn)
srv, _ := server.WithContext(ctx)
Expand Down
16 changes: 16 additions & 0 deletions internal/config/migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package config

import (
"github.com/zeiss/typhoon/internal/models"
"gorm.io/gorm"
)

// RunMigrations ...
func RunMigrations(db *gorm.DB) error {
return db.AutoMigrate(
&models.Role{},
&models.Team{},
&models.User{},
&models.UserRole{},
)
}
Loading

0 comments on commit 07ce508

Please sign in to comment.