-
Notifications
You must be signed in to change notification settings - Fork 109
262 lines (218 loc) · 8.3 KB
/
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
name: DEPLOY
on:
push:
branches:
- dev
workflow_dispatch:
inputs:
cmd:
description: Command
required: true
type: choice
options:
- deploy
- test
tags:
description: Tags
required: false
type: string
# if deploy on release
# release:
# types: [published]
# needed for github/git auth
permissions:
contents: write
issues: write # Only add other permissions if necessary for your workflow
env:
CI: true
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
APOLLO_API_KEY: ${{ secrets.APOLLO_API_KEY }}
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_ACCESS_KEY_SECRET: ${{ secrets.AWS_ACCESS_KEY_SECRET }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_BUCKET_MEDIA: ${{ secrets.AWS_BUCKET_MEDIA }}
REDIS_URL: ${{ secrets.REDIS_URL }}
CLICKHOUSE_URL: ${{ secrets.CLICKHOUSE_URL }}
STRIPE_SECRET_KEY_TEST: ${{ secrets.STRIPE_SECRET_KEY_TEST }}
TOKEN_SECRET: ${{ secrets.TOKEN_SECRET }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
SMTP_HOST: ${{ secrets.SMTP_HOST }}
SMTP_USER: ${{ secrets.SMTP_USER }}
SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
UNSPLASH_ACCESS_KEY: ${{ secrets.UNSPLASH_ACCESS_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SHOULD_DEPLOY: ${{ contains(github.event.head_commit.message, '-d') }}
SHOULD_RELEASE: ${{ contains(github.event.head_commit.message, '-r') }}
BETTER_STACK_SOURCE_TOKEN: ${{ secrets.BETTER_STACK_SOURCE_TOKEN }}
jobs:
test:
if: 'contains(github.event.head_commit.message, ''skip'') == false'
env:
REDIS_URL: redis://localhost:6379
CLICKHOUSE_URL: http://default:@localhost:8123
POSTGRES_URL: http://test:test@localhost:5432/test
name: build and test
runs-on: ubuntu-latest
steps:
- name: Get The Code
uses: actions/checkout@v4
- name: List files in workspace
run: ls -alh ${{ github.workspace }}
- name: List files in workspace
run: ls -alh /home/runner/work/_temp
# - name: Install Vector for Better Stack
# run: |
# curl -sSL https://logs.betterstack.com/setup-vector/ubuntu/${{ secrets.BETTER_STACK_SOURCE_TOKEN }} \
# -o /tmp/setup-vector.sh && \
# bash /tmp/setup-vector.sh
# - name: Configure Vector with custom configuration
# run: |
# sudo envsubst < "${{ github.workspace }}/.github/workflows/vector.toml" | sudo tee /etc/vector/vector.toml > /dev/null
# sudo systemctl restart vector
# echo "Configuration complete."
# sudo systemctl restart vector
# echo "Vector service restarted."
# env:
# BETTER_STACK_SOURCE_TOKEN: ${{ secrets.BETTER_STACK_SOURCE_TOKEN }}
- name: Debug Info
run: |
echo "SHOULD_RELEASE: ${{ env.SHOULD_RELEASE }}"
echo "SHOULD_DEPLOY: ${{ env.SHOULD_DEPLOY }}"
echo "Commit Message: ${{ github.event.head_commit.message }}"
- name: Get current time
id: current_time
run: echo "time=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT
shell: bash
- name: Write Build Information to a Config File
run: |
echo '{
"commitId": "${{ github.sha }}",
"buildTime": "${{ steps.current_time.outputs.time }}",
"buildNumber": "${{ github.run_number }}",
"branch": "${{ github.ref_name }}"
}' > ./buildInfo.json
shell: bash
- name: Set up DNS for subdomain testing
run: |
echo "127.0.0.1 test.lan.com" | sudo tee -a /etc/hosts
- name: Test DNS resolution
run: |
echo "Testing DNS resolution for lan.com and its subdomains..."
dig +short test.lan.com @127.0.0.1 || echo "Failed to resolve test.lan.com"
- name: Configure Git
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
- name: Install GH CLI
run: |
sudo apt update
sudo apt install -y gh
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9.6.0
- name: Set Node Version
uses: actions/setup-node@v4
with:
node-version: 22.5.1
cache: pnpm
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install FlyCtl CLI
uses: superfly/flyctl-actions/setup-flyctl@master
- name: Install Deps
run: pnpm -v && pnpm i && pnpm rebuild --recursive
- name: Run Type Check
run: npm run types:ci
# - name: Restore ESLint cache
# uses: actions/cache/restore@v4
# id: eslint-cache-restore
# with:
# path: .eslintcache
# key: ${{ runner.os }}-eslint-${{ github.ref }}
# restore-keys: |
# ${{ runner.os }}-eslint-
# - name: Run ESLint
# run: npm run lint:dev
# continue-on-error: false
# - name: Save ESLint cache
# uses: actions/cache/save@v4
# if: always()
# with:
# path: .eslintcache
# key: ${{ runner.os }}-eslint-${{ github.ref }}-${{ github.sha }}
- name: Debug Git Config
run: |
git config --list
git remote -v
- name: Install Playwright Browsers
run: npx playwright install
- name: Run Docker Compose (DB)
run: docker compose -f ./docker/docker-compose.yml pull && docker compose -f ./docker/docker-compose.yml up --build -d
- name: Create Tables
run: npm -w @fiction/www exec -- fiction run generate
- name: DEBUG tests
run: npm exec -- vitest run debug -u --passWithNoTests
- name: ENVIRONMENT tests
run: npm exec -- vitest run envi -u --passWithNoTests
- name: BUILD tests
env:
NODE_OPTIONS: --max_old_space_size=4096
run: npm exec -- vitest run build -u --no-file-parallelism
- name: SPOT tests
run: npm exec -- vitest run spot -u --passWithNoTests
- name: E2E/UI tests
run: npm exec -- vitest run uiux -u --no-file-parallelism
- name: UNIT tests
run: npm exec -- vitest run unit -u
- name: Install Build Packages
if: env.SHOULD_DEPLOY == 'true'
run: pnpm add tsup cross-env --global
- name: Build Bundles
if: env.SHOULD_DEPLOY == 'true'
run: npm exec -- fiction run bundle
- name: Render Apps
if: env.SHOULD_DEPLOY == 'true'
run: npm exec -- fiction run render
- name: DIST unit tests
if: env.SHOULD_DEPLOY == 'true'
run: npm exec -- vitest run dist -u
- name: Deploy Apps
if: env.SHOULD_DEPLOY == 'true'
run: |
cross-env DOMAIN=fiction APP=beacon npm run deploy
cross-env DOMAIN=fiction APP=www npm run deploy
cross-env DOMAIN=fiction APP=sites npm run deploy
- name: Release Code
if: env.SHOULD_RELEASE == 'true'
run: |
npm run i:lockfile && npm run release
- name: Post Notification
if: failure()
id: slack
uses: slackapi/slack-github-action@v1.24.0
with:
# This data can be any valid JSON from a previous step in the GitHub Action
payload: |
{
"icon_emoji": "${{ job.status == 'success' && ':white_check_mark:' || ':x:' }}",
"username": "supereon",
"channel": "#notify",
"text": "Workflow *${{ github.workflow }}* on *${{ github.ref }}* (commit: ${{ github.sha }}) completed with status: *${{ job.status }}*. <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Run>"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}