Skip to content

Commit

Permalink
Merge pull request #38 from PromptPal/fix/ci-postgres
Browse files Browse the repository at this point in the history
fix(ci): fix test in ci postgres
  • Loading branch information
AnnatarHe committed Mar 11, 2024
2 parents 6642b2a + 1e4845e commit 1adfa59
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -3,7 +3,7 @@
# top-most EditorConfig file
root = true

[*.gql]
[*.{gql,yaml}]
indent_style = space
indent_size = 2
end_of_line = crlf
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/pull_requests.yaml
@@ -0,0 +1,62 @@
name: Pull Requests check

on:
push:
branches-ignore: [main, master]

jobs:
build:
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: db_test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go 1.22
uses: actions/setup-go@v5
with:
go-version: ^1.22
cache: true
id: go
- name: setup env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
- name: Generate
run: |
echo "GH_TAG=$(echo $GITHUB_REF | awk -F / '{print $3}')" >> $GITHUB_ENV
go install github.com/vektra/mockery/v2@v2.42.0
go generate ./...
rm ./routes/.env.testing
echo "" > ./routes/.env.testing
rm ./schema/.env.testing
echo "" > ./schema/.env.testing
- name: Test
env:
JWT_TOKEN_KEY: "4a9bca7269a3a29eb1026b3c0999b29b929ab59a"
HASHID_SALT: "11111111"
PUBLIC_DOMAIN: "localhost:7788"
DB_TYPE: "postgres"
DB_DSN: "host=localhost user=postgres password=postgres port=5432 dbname=db_test sslmode=disable"
ADMIN_LIST: 0x4910c609fBC895434a0A5E3E46B1Eb4b64Cff2B8,0x7E63d899676756711d29DD989bb9F5a868C20e1D
OPENAI_BASE_URL: "https://api.openai.com/v1"
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Build
env:
GOARCH: amd64
CGO_ENABLED: 1
GOOS: linux
run: make release
204 changes: 98 additions & 106 deletions .github/workflows/release.yaml
@@ -1,106 +1,98 @@
name: Build and Release

on:
push:
branches:
- master

permissions:
contents: write # to create release commit (google-github-actions/release-please-action)
pull-requests: write # to create release PR (google-github-actions/release-please-action)

jobs:
build:
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: db_test
ports:
- 5432/tcp
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

name: Build
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: go
- uses: actions/checkout@v4
- name: Set up Go 1.22
uses: actions/setup-go@v5
with:
go-version: ^1.22
cache: true
id: go
- name: setup env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
- name: Generate
run: |
echo "GH_TAG=$(echo $GITHUB_REF | awk -F / '{print $3}')" >> $GITHUB_ENV
go install github.com/vektra/mockery/v2@v2.42.0
go generate ./...
awk -v db_type="postgres" -v db_dsn="\"host=postgres user=postgres password=postgres port=5432 dbname=db_test sslmode=disable\"" '
BEGIN { FS = OFS = "=" }
$1 == "DB_TYPE" { $2 = db_type }
$1 == "DB_DSN" { $2 = db_dsn }
{ print }
' ./routes/.env.testing > routes/.env.testing2
rm ./routes/.env.testing
mv ./routes/.env.testing2 ./routes/.env.testing
- name: Test
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Build
if: ${{ steps.release.outputs.release_created }}
env:
GOARCH: amd64
CGO_ENABLED: 1
GOOS: linux
run: |
make release
chmod +x up-pp-api
- uses: dsaltares/fetch-gh-release-asset@master
if: ${{ steps.release.outputs.release_created }}
with:
repo: "PromptPal/web"
file: "dist.zip"
target: "dist.zip"
token: ${{ secrets.GH_PERSONAL_TOKEN }}
- uses: montudor/action-zip@v1
if: ${{ steps.release.outputs.release_created }}
with:
args: unzip -qq dist.zip -d public
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
if: ${{ steps.release.outputs.release_created }}
with:
images: annatarhe/prompt-pal
tags: ${{ steps.release.outputs.tag_name }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
if: ${{ steps.release.outputs.release_created }}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
if: ${{ steps.release.outputs.release_created }}
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' && steps.release.outputs.release_created }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
name: Build and Release

on:
push:
branches:
- master

permissions:
contents: write # to create release commit (google-github-actions/release-please-action)
pull-requests: write # to create release PR (google-github-actions/release-please-action)

jobs:
build:
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: db_test
ports:
- 5432/tcp
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

name: Build
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: go
- uses: actions/checkout@v4
- name: Set up Go 1.22
uses: actions/setup-go@v5
with:
go-version: ^1.22
cache: true
id: go
- name: setup env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
- name: Generate
run: |
echo "GH_TAG=$(echo $GITHUB_REF | awk -F / '{print $3}')" >> $GITHUB_ENV
go install github.com/vektra/mockery/v2@v2.42.0
go generate ./...
- name: Test
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Build
if: ${{ steps.release.outputs.release_created }}
env:
GOARCH: amd64
CGO_ENABLED: 1
GOOS: linux
run: |
make release
chmod +x up-pp-api
- uses: dsaltares/fetch-gh-release-asset@master
if: ${{ steps.release.outputs.release_created }}
with:
repo: "PromptPal/web"
file: "dist.zip"
target: "dist.zip"
token: ${{ secrets.GH_PERSONAL_TOKEN }}
- uses: montudor/action-zip@v1
if: ${{ steps.release.outputs.release_created }}
with:
args: unzip -qq dist.zip -d public
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
if: ${{ steps.release.outputs.release_created }}
with:
images: annatarhe/prompt-pal
tags: ${{ steps.release.outputs.tag_name }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
if: ${{ steps.release.outputs.release_created }}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
if: ${{ steps.release.outputs.release_created }}
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' && steps.release.outputs.release_created }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
5 changes: 5 additions & 0 deletions schema/call_test.go
Expand Up @@ -11,7 +11,9 @@ import (
"time"

"github.com/PromptPal/PromptPal/config"
"github.com/PromptPal/PromptPal/ent/project"
"github.com/PromptPal/PromptPal/ent/prompt"
"github.com/PromptPal/PromptPal/ent/promptcall"
"github.com/PromptPal/PromptPal/ent/schema"
dbSchema "github.com/PromptPal/PromptPal/ent/schema"
"github.com/PromptPal/PromptPal/routes"
Expand Down Expand Up @@ -295,6 +297,9 @@ func (s *callTestSuite) TestPerformCall() {
}

func (s *callTestSuite) TearDownSuite() {
service.EntClient.PromptCall.Delete().Where(promptcall.HasProjectWith(project.ID(s.pjID))).ExecX(context.Background())
service.EntClient.Prompt.DeleteOneID(s.promptID).ExecX(context.Background())
service.EntClient.Project.DeleteOneID(s.pjID).ExecX(context.Background())
service.Close()
}

Expand Down
1 change: 1 addition & 0 deletions schema/openToken_test.go
Expand Up @@ -114,6 +114,7 @@ func (s *openTokenTestSuite) TestPurgeOpenToken() {
}

func (s *openTokenTestSuite) TearDownSuite() {
service.EntClient.Project.DeleteOneID(s.pjID).ExecX(context.Background())
service.Close()
}

Expand Down
14 changes: 13 additions & 1 deletion schema/project.go
Expand Up @@ -122,9 +122,21 @@ type deleteProjectArgs struct {
}

func (q QueryResolver) DeleteProject(ctx context.Context, args deleteProjectArgs) (bool, error) {
err := service.EntClient.Project.DeleteOneID(int(args.ID)).Exec(ctx)

tx, err := service.EntClient.Tx(ctx)

if err != nil {
return false, NewGraphQLHttpError(http.StatusInternalServerError, err)
}

// tx.PromptCall.Delete().Where(promptcall.ProjectIDEQ(int(args.ID))).Exec(ctx)
// tx.History.Delete().Where(history.ProjectIDEQ(int(args.ID))).Exec(ctx)

err = tx.Project.DeleteOneID(int(args.ID)).Exec(ctx)
if err != nil {
tx.Rollback()
return false, NewGraphQLHttpError(http.StatusInternalServerError, err)
}
tx.Commit()
return true, nil
}

0 comments on commit 1adfa59

Please sign in to comment.