Skip to content

Commit f0cdb74

Browse files
committed
deploy
1 parent 5a573ec commit f0cdb74

File tree

2 files changed

+164
-49
lines changed

2 files changed

+164
-49
lines changed

.github/workflows/ci.yml

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
pull_request:
99
branches: [main, cloud, devel]
1010

11+
env:
12+
GITHUB_REGISTRY: ghcr.io
13+
DEV_CONTAINER_DOCKER_IMAGE: bencher-dev-container
14+
1115
# Cancel in-progress runs for the same branch
1216
concurrency:
1317
group: ${{ github.workflow }}-${{ github.ref }}
@@ -96,11 +100,26 @@ jobs:
96100
build-docker: ${{ needs.changes.outputs.docker == 'true' || github.ref == 'refs/heads/devel' || github.ref == 'refs/heads/cloud' || startsWith(github.ref, 'refs/tags/') }}
97101
build-cli: ${{ needs.changes.outputs.cli == 'true' || startsWith(github.ref, 'refs/tags/') }}
98102

103+
deploy:
104+
name: Deploy
105+
needs: [lint, cli, test, build]
106+
if: ${{ github.ref == 'refs/heads/devel' || github.ref == 'refs/heads/cloud' || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy')) }}
107+
uses: ./.github/workflows/deploy.yml
108+
with:
109+
deploy-dev: ${{ github.ref == 'refs/heads/devel' || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy')) }}
110+
deploy-test: ${{ github.ref == 'refs/heads/devel' || github.ref == 'refs/heads/cloud' }}
111+
deploy-prod: ${{ github.ref == 'refs/heads/cloud' }}
112+
secrets:
113+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
114+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
115+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
116+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
117+
99118
# Summary job for required status checks
100119
ci-success:
101120
name: CI Success
102121
runs-on: ubuntu-22.04
103-
needs: [lint, cli, test, build]
122+
needs: [lint, cli, test, build, deploy]
104123
if: always()
105124
steps:
106125
- name: Check all jobs passed
@@ -109,6 +128,10 @@ jobs:
109128
echo "Lint failed"
110129
exit 1
111130
fi
131+
if [[ "${{ needs.cli.result }}" != "success" ]]; then
132+
echo "CLI failed"
133+
exit 1
134+
fi
112135
if [[ "${{ needs.test.result }}" != "success" && "${{ needs.test.result }}" != "skipped" ]]; then
113136
echo "Test failed"
114137
exit 1
@@ -117,12 +140,31 @@ jobs:
117140
echo "Build failed"
118141
exit 1
119142
fi
143+
if [[ "${{ needs.deploy.result }}" != "success" && "${{ needs.deploy.result }}" != "skipped" ]]; then
144+
echo "Deploy failed"
145+
exit 1
146+
fi
120147
echo "All required jobs passed!"
121148
122-
# Trigger Deploy Devel for PRs with the deploy label
123-
deploy_devel:
124-
name: Deploy Devel
125-
needs: [ci-success]
126-
if: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy') }}
127-
uses: ./.github/workflows/deploy-devel.yml
128-
secrets: inherit
149+
build_dev_container:
150+
name: Build dev container
151+
if: ${{ github.ref == 'refs/heads/devel' }}
152+
runs-on: ubuntu-22.04
153+
steps:
154+
- uses: actions/checkout@v6
155+
- name: Set up QEMU
156+
uses: docker/setup-qemu-action@v3
157+
- name: Setup Docker buildx
158+
uses: docker/setup-buildx-action@v3
159+
- name: Log in to the Container registry
160+
uses: docker/login-action@v3
161+
with:
162+
registry: ${{ env.GITHUB_REGISTRY }}
163+
username: ${{ github.actor }}
164+
password: ${{ secrets.GITHUB_TOKEN }}
165+
- name: Pre-build dev container image
166+
uses: devcontainers/ci@v0.3
167+
with:
168+
imageName: ${{ env.GITHUB_REGISTRY }}/${{ github.repository_owner }}/${{ env.DEV_CONTAINER_DOCKER_IMAGE }}
169+
cacheFrom: ${{ env.GITHUB_REGISTRY }}/${{ github.repository_owner }}/${{ env.DEV_CONTAINER_DOCKER_IMAGE }}
170+
push: always
Lines changed: 114 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
name: Deploy Devel
22

33
on:
4-
workflow_run:
5-
workflows: ["CI"]
6-
branches: [devel]
7-
types: [completed]
84
workflow_call:
5+
inputs:
6+
deploy-dev:
7+
type: boolean
8+
default: false
9+
deploy-test:
10+
type: boolean
11+
default: false
12+
deploy-prod:
13+
type: boolean
14+
default: false
15+
secrets:
16+
FLY_API_TOKEN:
17+
required: false
18+
SENTRY_AUTH_TOKEN:
19+
required: false
20+
NETLIFY_AUTH_TOKEN:
21+
required: false
22+
NETLIFY_SITE_ID:
23+
required: false
24+
GITHUB_TOKEN:
25+
required: false
926

1027
concurrency:
11-
group: deploy-devel
28+
group: deploy
1229
cancel-in-progress: true
1330

1431
env:
@@ -17,14 +34,12 @@ env:
1734
FLY_REGISTRY: registry.fly.io
1835
WASM_BENCHER_VALID: bencher-valid-pkg
1936
NETLIFY_CLI_VERSION: "18.0.4"
20-
GITHUB_REGISTRY: ghcr.io
21-
DEV_CONTAINER_DOCKER_IMAGE: bencher-dev-container
2237

2338
jobs:
2439
deploy_api_fly_dev:
2540
name: Deploy API to Fly.io Dev
2641
runs-on: ubuntu-22.04
27-
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_call' }}
42+
if: ${{ inputs.deploy-dev }}
2843
env:
2944
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
3045
steps:
@@ -52,10 +67,52 @@ jobs:
5267
RUST_BACKTRACE: full
5368
run: cargo test-api smoke dev
5469

70+
deploy_console_netlify_dev:
71+
name: Deploy Console UI to Netlify Dev
72+
if: ${{ inputs.deploy-dev }}
73+
runs-on: ubuntu-22.04
74+
needs: deploy_api_fly_dev
75+
steps:
76+
- uses: actions/checkout@v6
77+
- name: Download `bencher_valid` Artifact
78+
uses: actions/download-artifact@v4
79+
with:
80+
name: ${{ env.WASM_BENCHER_VALID }}
81+
run-id: ${{ github.event.workflow_run.id }}
82+
github-token: ${{ github.event.workflow_run.id && secrets.GITHUB_TOKEN || '' }}
83+
path: ./lib/bencher_valid/pkg
84+
- name: Build Console UI
85+
working-directory: ./services/console
86+
env:
87+
SENTRY_UPLOAD: true
88+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
89+
run: npm run netlify
90+
- name: Install Netlify CLI
91+
run: npm install --save-dev netlify-cli@${{ env.NETLIFY_CLI_VERSION }}
92+
- name: Deploy Console UI to Netlify Dev
93+
env:
94+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
95+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
96+
DEPLOY_MESSAGE: "Deploy from devel"
97+
run: |
98+
npx netlify-cli \
99+
deploy \
100+
--alias devel \
101+
--message "$DEPLOY_MESSAGE" \
102+
--json \
103+
| tee netlify.json
104+
- uses: rui314/setup-mold@v1
105+
with:
106+
mold-version: ${{ env.MOLD_VERSION }}
107+
- name: Run Netlify Dev Test
108+
env:
109+
RUST_BACKTRACE: full
110+
run: cargo test-netlify dev devel
111+
55112
deploy_api_fly_test:
56113
name: Deploy API to Fly.io Test
114+
if: ${{ inputs.deploy-test }}
57115
runs-on: ubuntu-22.04
58-
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_call' }}
59116
env:
60117
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
61118
steps:
@@ -82,18 +139,57 @@ jobs:
82139
RUST_BACKTRACE: full
83140
run: cargo test-api smoke test
84141

85-
deploy_console_netlify_dev:
86-
name: Deploy Console UI to Netlify Dev
142+
deploy_api_fly_prod:
143+
name: Deploy API to Fly.io Prod
144+
if: ${{ inputs.deploy-prod }}
87145
runs-on: ubuntu-22.04
88-
needs: deploy_api_fly_dev
146+
needs: deploy_api_fly_test
147+
env:
148+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
149+
steps:
150+
- uses: actions/checkout@v6
151+
with:
152+
fetch-depth: 0
153+
- name: Download API Docker Artifact
154+
uses: actions/download-artifact@v4
155+
with:
156+
name: ${{ env.API_DOCKER_IMAGE }}.tar.gz
157+
run-id: ${{ github.event.workflow_run.id }}
158+
github-token: ${{ secrets.GITHUB_TOKEN }}
159+
- name: Load & Tag Litestream Image
160+
run: |
161+
docker load < ${{ env.API_DOCKER_IMAGE }}.tar.gz
162+
docker tag ${{ env.API_DOCKER_IMAGE }} ${{ env.FLY_REGISTRY }}/bencher-api
163+
- uses: superfly/flyctl-actions/setup-flyctl@master
164+
- name: Deploy API to Fly.io Prod
165+
working-directory: ./services/api
166+
run: flyctl deploy --local-only --config fly/fly.toml --wait-timeout 300
167+
- name: Rebase main on cloud
168+
run: |
169+
git config --global user.name "Bencher"
170+
git config --global user.email "git@bencher.dev"
171+
git fetch origin cloud
172+
git checkout cloud
173+
git pull
174+
git fetch origin main
175+
git checkout main
176+
git pull
177+
git rebase origin/cloud
178+
git push
179+
180+
deploy_console_netlify_prod:
181+
name: Deploy Console UI to Netlify Prod
182+
if: ${{ inputs.deploy-prod }}
183+
runs-on: ubuntu-22.04
184+
needs: deploy_api_fly_prod
89185
steps:
90186
- uses: actions/checkout@v6
91187
- name: Download `bencher_valid` Artifact
92188
uses: actions/download-artifact@v4
93189
with:
94190
name: ${{ env.WASM_BENCHER_VALID }}
95191
run-id: ${{ github.event.workflow_run.id }}
96-
github-token: ${{ github.event.workflow_run.id && secrets.GITHUB_TOKEN || '' }}
192+
github-token: ${{ secrets.GITHUB_TOKEN }}
97193
path: ./lib/bencher_valid/pkg
98194
- name: Build Console UI
99195
working-directory: ./services/console
@@ -103,45 +199,22 @@ jobs:
103199
run: npm run netlify
104200
- name: Install Netlify CLI
105201
run: npm install --save-dev netlify-cli@${{ env.NETLIFY_CLI_VERSION }}
106-
- name: Deploy Console UI to Netlify Dev
202+
- name: Deploy Console UI to Netlify
107203
env:
108204
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
109205
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
110-
DEPLOY_MESSAGE: "Deploy from devel"
206+
DEPLOY_MESSAGE: "Deploy from cloud"
111207
run: |
112208
npx netlify-cli \
113209
deploy \
114-
--alias devel \
210+
--prod \
115211
--message "$DEPLOY_MESSAGE" \
116212
--json \
117213
| tee netlify.json
118214
- uses: rui314/setup-mold@v1
119215
with:
120216
mold-version: ${{ env.MOLD_VERSION }}
121-
- name: Run Netlify Dev Test
217+
- name: Run Netlify Test
122218
env:
123219
RUST_BACKTRACE: full
124-
run: cargo test-netlify dev devel
125-
126-
build_dev_container:
127-
name: Build dev container
128-
runs-on: ubuntu-22.04
129-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
130-
steps:
131-
- uses: actions/checkout@v6
132-
- name: Set up QEMU
133-
uses: docker/setup-qemu-action@v3
134-
- name: Setup Docker buildx
135-
uses: docker/setup-buildx-action@v3
136-
- name: Log in to the Container registry
137-
uses: docker/login-action@v3
138-
with:
139-
registry: ${{ env.GITHUB_REGISTRY }}
140-
username: ${{ github.actor }}
141-
password: ${{ secrets.GITHUB_TOKEN }}
142-
- name: Pre-build dev container image
143-
uses: devcontainers/ci@v0.3
144-
with:
145-
imageName: ${{ env.GITHUB_REGISTRY }}/${{ github.repository_owner }}/${{ env.DEV_CONTAINER_DOCKER_IMAGE }}
146-
cacheFrom: ${{ env.GITHUB_REGISTRY }}/${{ github.repository_owner }}/${{ env.DEV_CONTAINER_DOCKER_IMAGE }}
147-
push: always
220+
run: cargo test-netlify prod --user-agent "${{ secrets.LYCHEE_USER_AGENT }}" cloud

0 commit comments

Comments
 (0)