|
| 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 | + cache-dependency-path: "frontend/pnpm-lock.yaml" |
| 135 | + |
| 136 | + - name: Install frontend deps |
| 137 | + if: ${{ steps.vars.outputs.build_frontend == 'true' }} |
| 138 | + working-directory: frontend |
| 139 | + run: pnpm install --frozen-lockfile |
| 140 | + |
| 141 | + - name: Lint frontend |
| 142 | + if: ${{ steps.vars.outputs.build_frontend == 'true' }} |
| 143 | + working-directory: frontend |
| 144 | + run: (pnpm lint:oxlint && pnpm lint:eslint) |
| 145 | + |
| 146 | + - name: Sync forth and back with crowdin |
| 147 | + if: ${{ steps.vars.outputs.build_frontend == 'true' }} |
| 148 | + uses: crowdin/github-action@v2 |
| 149 | + with: |
| 150 | + upload_sources: true |
| 151 | + download_translations: true |
| 152 | + push_translations: false |
| 153 | + create_pull_request: false |
| 154 | + skip_untranslated_strings: true |
| 155 | + config: "crowdin.yml" |
| 156 | + crowdin_branch_name: master |
| 157 | + env: |
| 158 | + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} |
| 159 | + |
| 160 | + - name: Build frontend (prod) |
| 161 | + if: ${{ steps.vars.outputs.build_frontend == 'true' && steps.vars.outputs.master_branch == 'true' }} |
| 162 | + working-directory: frontend |
| 163 | + run: pnpm build |
| 164 | + - name: Build frontend (staging) |
| 165 | + if: ${{ steps.vars.outputs.build_frontend == 'true' && steps.vars.outputs.staging_branch == 'true' }} |
| 166 | + working-directory: frontend |
| 167 | + run: pnpm buildStaging |
| 168 | + # </editor-fold> |
| 169 | + |
| 170 | + # <editor-fold desc="Deploy"> |
| 171 | + - name: Set up Docker Buildx |
| 172 | + if: ${{ steps.vars.outputs.deploy == 'true' }} |
| 173 | + uses: docker/setup-buildx-action@v3 |
| 174 | + |
| 175 | + - name: Login to registry |
| 176 | + if: ${{ steps.vars.outputs.deploy == 'true' }} |
| 177 | + uses: docker/login-action@v3 |
| 178 | + with: |
| 179 | + registry: ${{ env.REGISTRY }} |
| 180 | + username: ${{ github.actor }} |
| 181 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 182 | + |
| 183 | + - name: Extract metadata (tags, labels) for Docker (frontend) |
| 184 | + if: ${{ steps.vars.outputs.deploy == 'true' }} |
| 185 | + id: frontend-meta |
| 186 | + uses: docker/metadata-action@v5 |
| 187 | + with: |
| 188 | + images: ${{ env.REGISTRY }}/${{ github.repository }}/frontend |
| 189 | + tags: | |
| 190 | + type=sha,enable=true,format=short,prefix=${{ env.BRANCH_NAME }}-,suffix=-${{ steps.vars.outputs.timestamp }} |
| 191 | + type=raw,value=latest,enable={{is_default_branch}} |
| 192 | +
|
| 193 | + - name: Build and push frontend Dockerfile |
| 194 | + if: ${{ steps.vars.outputs.deploy == 'true' }} |
| 195 | + uses: docker/build-push-action@v6 |
| 196 | + with: |
| 197 | + context: . |
| 198 | + file: chart/dockerfiles/frontend/Dockerfile |
| 199 | + tags: ${{ steps.frontend-meta.outputs.tags }} |
| 200 | + labels: ${{ steps.frontend-meta.outputs.labels }} |
| 201 | + push: true |
| 202 | + cache-from: type=gha |
| 203 | + cache-to: type=gha,mode=max |
| 204 | + |
| 205 | + - name: Extract metadata (tags, labels) for Docker (backend) |
| 206 | + if: ${{ steps.vars.outputs.deploy == 'true' }} |
| 207 | + id: backend-meta |
| 208 | + uses: docker/metadata-action@v5 |
| 209 | + with: |
| 210 | + images: ${{ env.REGISTRY }}/${{ github.repository }}/backend |
| 211 | + tags: | |
| 212 | + type=sha,enable=true,format=short,prefix=${{ env.BRANCH_NAME }}-,suffix=-${{ steps.vars.outputs.timestamp }} |
| 213 | + type=raw,value=latest,enable={{is_default_branch}} |
| 214 | +
|
| 215 | + - name: Build and push backend Dockerfile |
| 216 | + if: ${{ steps.vars.outputs.deploy == 'true' }} |
| 217 | + uses: docker/build-push-action@v6 |
| 218 | + with: |
| 219 | + context: . |
| 220 | + file: chart/dockerfiles/backend/Dockerfile |
| 221 | + tags: ${{ steps.backend-meta.outputs.tags }} |
| 222 | + labels: ${{ steps.backend-meta.outputs.labels }} |
| 223 | + push: true |
| 224 | + cache-from: type=gha |
| 225 | + cache-to: type=gha,mode=max |
| 226 | + # </editor-fold> |
0 commit comments