|
| 1 | +name: Docker build and smoke test for apps |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + branches: ["preview"] |
| 7 | + paths: |
| 8 | + - "apps/web/**" |
| 9 | + - "apps/space/**" |
| 10 | + - "apps/admin/**" |
| 11 | + - "apps/live/**" |
| 12 | + - "packages/**" |
| 13 | + - "turbo.json" |
| 14 | + - "pnpm-lock.yaml" |
| 15 | + - "pnpm-workspace.yaml" |
| 16 | + - ".github/workflows/docker-smoke.yml" |
| 17 | + push: |
| 18 | + branches: ["preview"] |
| 19 | + paths: |
| 20 | + - "apps/web/**" |
| 21 | + - "apps/space/**" |
| 22 | + - "apps/admin/**" |
| 23 | + - "apps/live/**" |
| 24 | + - "packages/**" |
| 25 | + - "turbo.json" |
| 26 | + - "pnpm-lock.yaml" |
| 27 | + - "pnpm-workspace.yaml" |
| 28 | + - ".github/workflows/docker-smoke.yml" |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: read |
| 32 | + |
| 33 | +concurrency: |
| 34 | + group: docker-smoke-${{ github.workflow }}-${{ github.ref }} |
| 35 | + cancel-in-progress: true |
| 36 | + |
| 37 | +jobs: |
| 38 | + determine-matrix: |
| 39 | + name: Determine matrix |
| 40 | + runs-on: ubuntu-latest |
| 41 | + outputs: |
| 42 | + matrix: ${{ steps.build-matrix.outputs.matrix }} |
| 43 | + has_targets: ${{ steps.build-matrix.outputs.has_targets }} |
| 44 | + steps: |
| 45 | + - name: Checkout repository |
| 46 | + uses: actions/checkout@v4 |
| 47 | + with: |
| 48 | + fetch-depth: 0 |
| 49 | + |
| 50 | + - name: Detect changed paths |
| 51 | + id: changes |
| 52 | + uses: dorny/paths-filter@v3 |
| 53 | + with: |
| 54 | + filters: | |
| 55 | + web: |
| 56 | + - 'apps/web/**' |
| 57 | + space: |
| 58 | + - 'apps/space/**' |
| 59 | + admin: |
| 60 | + - 'apps/admin/**' |
| 61 | + live: |
| 62 | + - 'apps/live/**' |
| 63 | + common: |
| 64 | + - 'turbo.json' |
| 65 | + - 'pnpm-lock.yaml' |
| 66 | + - 'pnpm-workspace.yaml' |
| 67 | + - '.github/workflows/docker-smoke.yml' |
| 68 | + - 'packages/**' |
| 69 | +
|
| 70 | + - name: Build matrix |
| 71 | + id: build-matrix |
| 72 | + uses: actions/github-script@v7 |
| 73 | + with: |
| 74 | + script: | |
| 75 | + const include = []; |
| 76 | + const eventName = context.eventName; |
| 77 | + const anyCommon = '${{ steps.changes.outputs.common }}' === 'true'; |
| 78 | + const changed = { |
| 79 | + web: '${{ steps.changes.outputs.web }}' === 'true', |
| 80 | + space: '${{ steps.changes.outputs.space }}' === 'true', |
| 81 | + admin: '${{ steps.changes.outputs.admin }}' === 'true', |
| 82 | + live: '${{ steps.changes.outputs.live }}' === 'true', |
| 83 | + }; |
| 84 | + const add = (name, dockerfile, image, container, port, path, env_flags = "") => include.push({ name, dockerfile, image, container, host_port: port, path, env_flags }); |
| 85 | + const buildAll = anyCommon || eventName === 'push' || eventName === 'workflow_dispatch'; |
| 86 | + if (buildAll || changed.web) add('web', 'apps/web/Dockerfile.web', 'plane-web:ci-smoke', 'plane-web-ci', 3001, '/'); |
| 87 | + if (buildAll || changed.space) add('space', 'apps/space/Dockerfile.space', 'plane-space:ci-smoke', 'plane-space-ci', 3002, '/spaces'); |
| 88 | + if (buildAll || changed.admin) add('admin', 'apps/admin/Dockerfile.admin', 'plane-admin:ci-smoke', 'plane-admin-ci', 3003, '/god-mode'); |
| 89 | + if (buildAll || changed.live) add('live', 'apps/live/Dockerfile.live', 'plane-live:ci-smoke', 'plane-live-ci', 3004, '/live/health', '-e NODE_ENV=production -e LIVE_BASE_PATH=/live'); |
| 90 | + const hasTargets = include.length > 0; |
| 91 | + if (!hasTargets) { |
| 92 | + core.warning('No changes detected for any app. Matrix is empty. Skipping smoke tests.'); |
| 93 | + } |
| 94 | + core.setOutput('matrix', JSON.stringify({ include })); |
| 95 | + core.setOutput('has_targets', String(hasTargets)); |
| 96 | + smoke: |
| 97 | + name: Build and smoke test ${{ matrix.name }} |
| 98 | + runs-on: ubuntu-latest |
| 99 | + needs: determine-matrix |
| 100 | + if: ${{ needs.determine-matrix.outputs.has_targets == 'true' }} |
| 101 | + timeout-minutes: 25 |
| 102 | + |
| 103 | + strategy: |
| 104 | + fail-fast: false |
| 105 | + matrix: ${{ fromJSON(needs.determine-matrix.outputs.matrix) }} |
| 106 | + |
| 107 | + steps: |
| 108 | + - name: Checkout repository |
| 109 | + uses: actions/checkout@v4 |
| 110 | + with: |
| 111 | + fetch-depth: 0 |
| 112 | + |
| 113 | + - name: Show Docker version |
| 114 | + run: | |
| 115 | + docker version |
| 116 | + docker info |
| 117 | +
|
| 118 | + - name: Run scripts/smoke.sh for ${{ matrix.name }} |
| 119 | + shell: bash |
| 120 | + run: | |
| 121 | + set -euo pipefail |
| 122 | + svc="${{ matrix.name }}" |
| 123 | + case "$svc" in |
| 124 | + web) |
| 125 | + export WEB_PORT=${{ matrix.host_port }} |
| 126 | + export WEB_PATH='${{ matrix.path }}' |
| 127 | + ;; |
| 128 | + admin) |
| 129 | + export ADMIN_PORT=${{ matrix.host_port }} |
| 130 | + export ADMIN_PATH='${{ matrix.path }}' |
| 131 | + export ADMIN_BASE_PATH='/god-mode' |
| 132 | + ;; |
| 133 | + space) |
| 134 | + export SPACE_PORT=${{ matrix.host_port }} |
| 135 | + export SPACE_PATH='${{ matrix.path }}' |
| 136 | + export SPACE_BASE_PATH='/spaces' |
| 137 | + ;; |
| 138 | + live) |
| 139 | + export LIVE_PORT=${{ matrix.host_port }} |
| 140 | + export LIVE_PATH='${{ matrix.path }}' |
| 141 | + export LIVE_BASE_PATH='/live' |
| 142 | + ;; |
| 143 | + esac |
| 144 | + export MAX_WAIT=120 |
| 145 | + export SLEEP_INTERVAL=2 |
| 146 | + export NODE_ENV=production |
| 147 | + set +e |
| 148 | + output="$(bash scripts/smoke.sh up --services "$svc")" |
| 149 | + status=$? |
| 150 | + set -e |
| 151 | + echo "$output" |
| 152 | + if [ $status -ne 0 ]; then |
| 153 | + echo "smoke.sh exited non-zero ($status)" |
| 154 | + exit $status |
| 155 | + fi |
| 156 | + if echo "$output" | grep -qi "failure(s)"; then |
| 157 | + echo "::group::Container logs ($svc)" |
| 158 | + docker ps -a || true |
| 159 | + docker logs "plane-${svc}-smoke" || true |
| 160 | + echo "::endgroup::" |
| 161 | + exit 1 |
| 162 | + fi |
| 163 | +
|
| 164 | + - name: Cleanup smoke containers (${{ matrix.name }}) |
| 165 | + if: always() |
| 166 | + run: | |
| 167 | + bash scripts/smoke.sh down |
0 commit comments