-
Notifications
You must be signed in to change notification settings - Fork 111
182 lines (158 loc) · 5.87 KB
/
ci.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
name: CI
on: [push, pull_request]
env:
UI_VERSION: ${{ github.sha }}
jobs:
build:
name: Build & test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 100
# Install Node
- uses: actions/setup-node@v4
with:
node-version: 20.8.0
cache: 'npm'
# Install & build & test:
- run: npm ci
- run: npm run test:unit
# Build & run normal integration tests:
- name: Build & test
run: npm run test:integration
if: github.ref != 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # To pull server without rate limit issues in CI
# Build with secrets & run integrations tests, on main only:
- name: Build & test for production release
run: npm run test:integration
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }}
SENTRY_DSN: ${{ env.SENTRY_DSN }}
SENTRY_ORG: http-toolkit
SENTRY_PROJECT: httptoolkit-ui
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
REPORT_URI: ${{ env.REPORT_URI }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # To pull server without rate limit issues in CI
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/*
if-no-files-found: error
# We build on Windows too, purely to check the build process is cross-compatible for contributors
test-windows-build:
name: Build & test on Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 100
# Install Node
- uses: actions/setup-node@v4
with:
node-version: 20.8.0
cache: 'npm'
# Install & build & test:
- run: npm ci
- run: npm run test:unit
# Build & run normal integration tests:
- name: Build & test
run: npm run test:integration
if: github.ref != 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # To pull server without rate limit issues in CI
publish-netlify:
name: Deploy ${{ (github.ref == 'refs/heads/main' && 'to Netlify production') || 'Netlify preview' }}
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: dist
path: dist
- name: Deploy to Netlify
uses: nwtgck/actions-netlify@v3
with:
publish-dir: './dist'
production-branch: main # Main goes to prod, others do deploy previews
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: GHA Deploy - ${{ github.event.head_commit.message }}
enable-commit-status: true
enable-pull-request-comment: false
enable-commit-comment: false
netlify-config-path: ./netlify.toml
alias: ${{ github.sha }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 1
publish-docker:
name: Build & publish container to Docker Hub
if: github.event_name == 'push' && !startsWith(github.ref, 'refs/heads/dependabot/')
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: dist
path: dist
- uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: httptoolkit/ui
tags: |
type=raw,value=prod,enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
type=sha
- name: Build and publish to Docker Hub
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name == 'push' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
publish-scaleway:
name: Deploy to Scaleway
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
container: httptoolkit/act-build-base
needs: publish-docker
steps:
- name: Redeploy container
uses: thibaultchazal/scaleway-serverless-container-deploy-action@0d290edda0c3359e51442bd8bf730eafef4e290f
with:
container_id: ${{ vars.SCW_API_CONTAINER_ID }}
region: ${{ vars.SCW_API_CONTAINER_REGION }}
secret_key: ${{ secrets.SCW_SECRET_KEY }}
registry_image_url: "registry.hub.docker.com/httptoolkit/ui:prod"
- name: Redeploy failover container
uses: thibaultchazal/scaleway-serverless-container-deploy-action@0d290edda0c3359e51442bd8bf730eafef4e290f
with:
container_id: ${{ vars.SCW_FAILOVER_API_CONTAINER_ID }}
region: ${{ vars.SCW_FAILOVER_API_CONTAINER_REGION }}
secret_key: ${{ secrets.SCW_SECRET_KEY }}
registry_image_url: "registry.hub.docker.com/httptoolkit/ui:prod"
- name: Flush CDN cache
run: |
# Wait a little - the reploy commands don't wait for the container to start up
sleep 30
# Clear CDN cache to re-request content:
curl -f --request POST \
--url https://api.bunny.net/pullzone/$PULL_ZONE_ID/purgeCache \
--header "AccessKey: $BUNNY_SITE_API_KEY"
env:
PULL_ZONE_ID: 1110200
BUNNY_SITE_API_KEY: ${{ secrets.BUNNY_SITE_API_KEY }}