This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
181 lines (181 loc) · 6.31 KB
/
test-deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: test
on: push
jobs:
rust-image:
uses: ./.github/workflows/docker-builder.yml
with:
file: "dockerfiles/rust.Dockerfile"
name: "api-rust"
go-builder-image:
uses: ./.github/workflows/docker-builder.yml
with:
file: "dockerfiles/go.Dockerfile"
name: "go-builder"
ui-builder-image:
needs: [wasm-builder-image]
uses: ./.github/workflows/docker-builder.yml
with:
file: "dockerfiles/ui.Dockerfile"
name: "ui-builder"
wasm-builder-image:
uses: ./.github/workflows/docker-builder.yml
with:
file: "dockerfiles/wasm.Dockerfile"
name: "wasm-builder"
build-main-docker:
needs: [go-builder-image, ui-builder-image]
name: main docker
uses: ./.github/workflows/docker-builder.yml
with:
file: "dockerfiles/main.Dockerfile"
name: "api-go"
golangci:
name: go lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6.1.1
with:
version: latest
test-ui:
needs: [wasm-builder-image]
name: vitest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Extract branch name
shell: bash
run: echo "branch=$(echo sha-${GITHUB_SHA})" >>$GITHUB_OUTPUT
id: extract_branch
- name: extract wasm for UI
run: |
docker create --name=temp ghcr.io/nickysemenza/gourd-wasm-builder:${{steps.extract_branch.outputs.branch}}
docker cp temp:/wasm ui/src/wasm
- run: yarn install
working-directory: ui/
- run: npx vitest --coverage
working-directory: ui/
- name: "Report Coverage"
if: always() # Also generate the report if tests are failing
uses: davelosert/vitest-coverage-report-action@v2
with:
working-directory: ui/
- uses: codecov/codecov-action@v4
with:
working-directory: ui/
test-e2e:
needs: [build-main-docker]
name: cypress
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "stable"
- name: Extract branch name
shell: bash
run: echo "branch=$(echo sha-${GITHUB_SHA})" >>$GITHUB_OUTPUT
id: extract_branch
- name: extract wasm for UI
run: |
docker create --name=temp ghcr.io/nickysemenza/gourd-wasm-builder:${{steps.extract_branch.outputs.branch}}
docker cp temp:/wasm ui/src/wasm
- name: start postgres db
run: DOCKER_TAG=${{steps.extract_branch.outputs.branch}} docker compose -f dockerfiles/docker-compose-deps.yml -f dockerfiles/docker-compose-gourd.yml up -d db
- run: go mod vendor
- name: migrate db
run: make migrate
- name: start rust + go servers
run: DOCKER_TAG=${{steps.extract_branch.outputs.branch}} docker compose -f dockerfiles/docker-compose-deps.yml -f dockerfiles/docker-compose-gourd.yml up -d rs gourd
- name: smoke test rust server
run: |
curl -v http://localhost:8080/parse?text=1%20cup
curl -v http://localhost:8080/debug/scrape?url=https://thewoksoflife.com/ma-po-tofu-real-deal/
- uses: codecov/codecov-action@v4
- name: Cypress run
uses: cypress-io/github-action@v5
with:
working-directory: ui/
start: npx vite --host
wait-on: http://localhost:5173
record: true
env:
CYPRESS_RECORD_KEY: 265312e3-7b8c-4031-ad0a-5f825b95cfce
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: codecov/codecov-action@v4
- name: Archive cypress results
uses: actions/upload-artifact@v4
if: always()
with:
name: cypress-results
path: ui/cypress/
if-no-files-found: error
- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v2
test-integration:
needs: [rust-image]
name: API integration
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "stable"
- name: Extract branch name
shell: bash
run: echo "branch=$(echo sha-${GITHUB_SHA})" >>$GITHUB_OUTPUT
id: extract_branch
- run: go mod vendor
- name: start postgres db + rust server
run: DOCKER_TAG=${{steps.extract_branch.outputs.branch}} docker compose -f dockerfiles/docker-compose-deps.yml -f dockerfiles/docker-compose-gourd.yml up -d db rs
- name: smoke test rust server
run: |
curl -v http://localhost:8080/parse?text=1%20cup
curl -v http://localhost:8080/debug/scrape?url=https://thewoksoflife.com/ma-po-tofu-real-deal/
- name: go integration tests
run: make integration-test-go
env:
MIGRATIONS_DIR: file://../../internal/db/migrations
PDFLATEX_BINARY: /usr/bin/pdflatex
- uses: codecov/codecov-action@v4
test-rust:
name: rust tests
runs-on: ubuntu-latest
# https://github.com/xd009642/tarpaulin#github-actions
container:
image: xd009642/tarpaulin:develop-nightly
options: --security-opt seccomp=unconfined
steps:
- uses: actions/checkout@v4
- run: |
cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 --out xml
working-directory: rust
- name: Upload to codecov.io
uses: codecov/codecov-action@v4
with:
working-directory: rust
deploy:
needs: ["test-e2e", "test-ui", "test-integration", "test-rust", "golangci"]
if: github.ref == 'refs/heads/main'
name: Deploy
runs-on: ubuntu-latest
environment: production
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
steps:
- uses: actions/checkout@v4
- run: curl -L https://fly.io/install.sh | sh
- run: /home/runner/.fly/bin/flyctl deploy deploy/ --image ghcr.io/nickysemenza/gourd-api-go:main
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- run: /home/runner/.fly/bin/flyctl deploy rust/ --image ghcr.io/nickysemenza/gourd-api-rust:main
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}