ci: adjusting to backend tests

This commit is contained in:
Reinaldy Rafli 2021-07-17 18:27:26 +07:00
parent 544530cd27
commit b8cfde8560
3 changed files with 65 additions and 21 deletions

View File

@ -8,36 +8,58 @@ jobs:
api-build: api-build:
name: Build name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: golang:1.16.6
services:
postgres:
image: postgres:13-alpine
env:
PGDATABASE: jokesbapak2
POSTGRES_DB: jokesbapak2
PGUSER: postgres
POSTGRES_USER: postgres
PGPASSWORD: password
POSTGRES_PASSWORD: password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:6.2-alpine
ports:
- 6379:6379
defaults: defaults:
run: run:
working-directory: ./api working-directory: ./api
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Install Go - name: cache go modules
uses: actions/setup-go@v2
with:
go-version: 1.16.x
- name: cache node_modules
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: ~/go/pkg/mod path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: | restore-keys: |
${{ runner.os }}-go- ${{ runner.os }}-go-
- name: Installling dependencies - name: Installling dependencies
if: steps.cache.outputs.cache-hit != 'true' if: steps.cache.outputs.cache-hit != 'true'
run: go mod vendor run: go mod vendor
- name: Build - name: Build
run: go build main.go run: go build main.go
- name: Run test & coverage - name: Run test & coverage
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./... run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
env:
ENV: development
PORT: 5000
DATABASE_URL: postgres://postgres:password@postgres:5432/jokesbapak2
REDIS_URL: redis://@redis:6379
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v1 uses: github/codeql-action/init@v1

View File

@ -33,7 +33,7 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: | restore-keys: |
${{ runner.os }}-yarn- ${{ runner.os }}-yarn-
- name: Installling dependencies - name: Installling dependencies
if: steps.cache.outputs.cache-hit != 'true' if: steps.cache.outputs.cache-hit != 'true'
run: yarn run: yarn

View File

@ -61,36 +61,58 @@ jobs:
api-build: api-build:
name: API name: API
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: golang:1.16.6
services:
postgres:
image: postgres:13-alpine
env:
PGDATABASE: jokesbapak2
POSTGRES_DB: jokesbapak2
PGUSER: postgres
POSTGRES_USER: postgres
PGPASSWORD: password
POSTGRES_PASSWORD: password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:6.2-alpine
ports:
- 6379:6379
defaults: defaults:
run: run:
working-directory: ./api working-directory: ./api
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Install Go - name: cache go modules
uses: actions/setup-go@v2
with:
go-version: 1.16.x
- name: cache node_modules
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: ~/go/pkg/mod path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: | restore-keys: |
${{ runner.os }}-go- ${{ runner.os }}-go-
- name: Installling dependencies - name: Installling dependencies
if: steps.cache.outputs.cache-hit != 'true' if: steps.cache.outputs.cache-hit != 'true'
run: go mod vendor run: go mod vendor
- name: Build - name: Build
run: go build main.go run: go build main.go
- name: Run test & coverage - name: Run test & coverage
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./... run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
env:
ENV: development
PORT: 5000
DATABASE_URL: postgres://postgres:password@postgres:5432/jokesbapak2
REDIS_URL: redis://@redis:6379
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v1 uses: github/codeql-action/init@v1