Skip to content

Commit fc0b077

Browse files
committed
chore: reorganize CI/CD workflows
1 parent b554cab commit fc0b077

File tree

4 files changed

+225
-271
lines changed

4 files changed

+225
-271
lines changed

.github/workflows/backend_build.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

.github/workflows/cicd.yml

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
name: CI/CD
2+
3+
on:
4+
# allow manual dispatch
5+
workflow_dispatch:
6+
inputs:
7+
build_backend:
8+
description: "Build backend"
9+
required: false
10+
default: true
11+
type: boolean
12+
build_frontend:
13+
description: "Build frontend"
14+
required: false
15+
default: true
16+
type: boolean
17+
deploy:
18+
description: "Deploy"
19+
required: false
20+
default: true
21+
type: boolean
22+
23+
# run on pushes to master and staging branches
24+
push:
25+
branches:
26+
- master
27+
- staging
28+
paths-ignore:
29+
- 'e2e/**'
30+
31+
concurrency:
32+
group: ${{ github.workflow }}-${{ github.ref }}
33+
cancel-in-progress: true
34+
35+
env:
36+
REGISTRY: ghcr.io
37+
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
38+
CI: true
39+
NODE_ENV: "production"
40+
41+
jobs:
42+
cicd:
43+
name: CI/CD
44+
runs-on: ubuntu-latest
45+
steps:
46+
# <editor-fold desc="Prepare">
47+
- name: Checkout
48+
uses: actions/checkout@v4
49+
with:
50+
# Assume PRs are less than 50 commits
51+
fetch-depth: 50
52+
53+
- name: Get changed files
54+
id: changed-files
55+
uses: tj-actions/changed-files@v46
56+
with:
57+
files_yaml: |
58+
backend:
59+
- backend/**
60+
frontend:
61+
- frontend/**
62+
chart:
63+
- chart/**
64+
65+
- name: Create Vars
66+
id: vars
67+
run: |
68+
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
69+
70+
backend_changed="${{ steps.changed-files.outputs.backend_any_changed }}"
71+
frontend_changed="${{ steps.changed-files.outputs.frontend_any_changed }}"
72+
chart_changed="${{ steps.changed-files.outputs.chart_any_changed }}"
73+
74+
staging_branch=false
75+
master_branch=false
76+
[[ "${GITHUB_REF}" == "refs/heads/staging" ]] && staging_branch=true
77+
[[ "${GITHUB_REF}" == "refs/heads/master" ]] && master_branch=true
78+
79+
build_backend=false
80+
build_frontend=false
81+
[[ "${{ inputs.deploy }}" == "true" || "${{ inputs.build_backend }}" == "true" || "$backend_changed" == "true" || "$chart_changed" == "true" ]] && build_backend=true
82+
[[ "${{ inputs.deploy }}" == "true" || "${{ inputs.build_frontend }}" == "true" || "$frontend_changed" == "true" || "$chart_changed" == "true" ]] && build_frontend=true
83+
84+
deploy=false
85+
if { [[ "$staging_branch" == "true" || "$master_branch" == "true" ]] && { [[ "$build_backend" == "true" || "$build_frontend" == "true" ]]; }; }; then
86+
deploy=true
87+
fi
88+
89+
{
90+
echo "build_backend=$build_backend"
91+
echo "build_frontend=$build_frontend"
92+
echo "deploy=$deploy"
93+
echo "staging_branch=$staging_branch"
94+
echo "master_branch=$master_branch"
95+
} >> $GITHUB_OUTPUT
96+
97+
echo "::group::Variables"
98+
echo "build_backend=$build_backend"
99+
echo "build_frontend=$build_frontend"
100+
echo "deploy=$deploy"
101+
echo "staging_branch=$staging_branch"
102+
echo "master_branch=$master_branch"
103+
echo "::endgroup::"
104+
# </editor-fold>
105+
106+
# <editor-fold desc="Build Backend">
107+
- name: Set up JDK
108+
if: ${{ steps.vars.outputs.build_backend == 'true' }}
109+
uses: actions/setup-java@v4
110+
with:
111+
java-version: 21
112+
distribution: temurin
113+
cache: "maven"
114+
115+
- name: Build backend
116+
if: ${{ steps.vars.outputs.build_backend == 'true' }}
117+
working-directory: backend
118+
run: mvn --batch-mode --errors --fail-at-end --show-version --no-transfer-progress install
119+
# </editor-fold>
120+
121+
# <editor-fold desc="Build Frontend">
122+
- name: Set up pnpm
123+
if: ${{ steps.vars.outputs.build_frontend == 'true' }}
124+
uses: pnpm/action-setup@v4
125+
with:
126+
version: 10
127+
128+
- name: Set up Node
129+
if: ${{ steps.vars.outputs.build_frontend == 'true' }}
130+
uses: actions/setup-node@v4
131+
with:
132+
node-version: "22"
133+
cache: "pnpm"
134+
135+
- name: Install frontend deps
136+
if: ${{ steps.vars.outputs.build_frontend == 'true' }}
137+
working-directory: frontend
138+
run: pnpm install --frozen-lockfile
139+
140+
- name: Lint frontend
141+
if: ${{ steps.vars.outputs.build_frontend == 'true' }}
142+
working-directory: frontend
143+
run: (pnpm lint:oxlint && pnpm lint:eslint)
144+
145+
- name: Sync forth and back with crowdin
146+
if: ${{ steps.vars.outputs.build_frontend == 'true' }}
147+
uses: crowdin/github-action@v2
148+
with:
149+
upload_sources: true
150+
download_translations: true
151+
push_translations: false
152+
create_pull_request: false
153+
skip_untranslated_strings: true
154+
config: "crowdin.yml"
155+
crowdin_branch_name: master
156+
env:
157+
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
158+
159+
- name: Build frontend (prod)
160+
if: ${{ steps.vars.outputs.build_frontend == 'true' && steps.vars.outputs.master_branch == 'true' }}
161+
working-directory: frontend
162+
run: pnpm build
163+
- name: Build frontend (staging)
164+
if: ${{ steps.vars.outputs.build_frontend == 'true' && steps.vars.outputs.staging_branch == 'true' }}
165+
working-directory: frontend
166+
run: pnpm buildStaging
167+
# </editor-fold>
168+
169+
# <editor-fold desc="Deploy">
170+
- name: Set up Docker Buildx
171+
if: ${{ steps.vars.outputs.deploy == 'true' }}
172+
uses: docker/setup-buildx-action@v3
173+
174+
- name: Login to registry
175+
if: ${{ steps.vars.outputs.deploy == 'true' }}
176+
uses: docker/login-action@v3
177+
with:
178+
registry: ${{ env.REGISTRY }}
179+
username: ${{ github.actor }}
180+
password: ${{ secrets.GITHUB_TOKEN }}
181+
182+
- name: Extract metadata (tags, labels) for Docker (frontend)
183+
if: ${{ steps.vars.outputs.deploy == 'true' }}
184+
id: frontend-meta
185+
uses: docker/metadata-action@v5
186+
with:
187+
images: ${{ env.REGISTRY }}/${{ github.repository }}/frontend
188+
tags: |
189+
type=sha,enable=true,format=short,prefix=${{ env.BRANCH_NAME }}-,suffix=-${{ steps.vars.outputs.timestamp }}
190+
type=raw,value=latest,enable={{is_default_branch}}
191+
192+
- name: Build and push frontend Dockerfile
193+
if: ${{ steps.vars.outputs.deploy == 'true' }}
194+
uses: docker/build-push-action@v6
195+
with:
196+
context: .
197+
file: chart/dockerfiles/frontend/Dockerfile
198+
tags: ${{ steps.frontend-meta.outputs.tags }}
199+
labels: ${{ steps.frontend-meta.outputs.labels }}
200+
push: true
201+
cache-from: type=gha
202+
cache-to: type=gha,mode=max
203+
204+
- name: Extract metadata (tags, labels) for Docker (backend)
205+
if: ${{ steps.vars.outputs.deploy == 'true' }}
206+
id: backend-meta
207+
uses: docker/metadata-action@v5
208+
with:
209+
images: ${{ env.REGISTRY }}/${{ github.repository }}/backend
210+
tags: |
211+
type=sha,enable=true,format=short,prefix=${{ env.BRANCH_NAME }}-,suffix=-${{ steps.vars.outputs.timestamp }}
212+
type=raw,value=latest,enable={{is_default_branch}}
213+
214+
- name: Build and push backend Dockerfile
215+
if: ${{ steps.vars.outputs.deploy == 'true' }}
216+
uses: docker/build-push-action@v6
217+
with:
218+
context: .
219+
file: chart/dockerfiles/backend/Dockerfile
220+
tags: ${{ steps.backend-meta.outputs.tags }}
221+
labels: ${{ steps.backend-meta.outputs.labels }}
222+
push: true
223+
cache-from: type=gha
224+
cache-to: type=gha,mode=max
225+
# </editor-fold>

0 commit comments

Comments
 (0)