|
| 1 | +name: Stage Deployment |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +jobs: |
| 8 | + detect-changes: |
| 9 | + name: Detect Changes |
| 10 | + runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + web: ${{ steps.filter.outputs.web }} |
| 13 | + admin: ${{ steps.filter.outputs.admin }} |
| 14 | + root: ${{ steps.filter.outputs.root }} |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Check changed files |
| 20 | + uses: dorny/paths-filter@v3 |
| 21 | + id: filter |
| 22 | + with: |
| 23 | + filters: | |
| 24 | + web: |
| 25 | + - 'apps/web/**' |
| 26 | + admin: |
| 27 | + - 'apps/admin/**' |
| 28 | + root: |
| 29 | + - 'package.json' |
| 30 | + - 'pnpm-lock.yaml' |
| 31 | + - 'pnpm-workspace.yaml' |
| 32 | + - 'turbo.json' |
| 33 | + - '.github/workflows/**' |
| 34 | +
|
| 35 | + deploy-web-stage: |
| 36 | + name: Deploy Web (Stage) |
| 37 | + runs-on: ubuntu-latest |
| 38 | + needs: detect-changes |
| 39 | + if: needs.detect-changes.outputs.web == 'true' || needs.detect-changes.outputs.root == 'true' |
| 40 | + env: |
| 41 | + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} |
| 42 | + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_WEB_STAGE }} |
| 43 | + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} |
| 44 | + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} |
| 45 | + steps: |
| 46 | + - name: Checkout repository |
| 47 | + uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: Install pnpm |
| 50 | + uses: pnpm/action-setup@v3 |
| 51 | + with: |
| 52 | + version: 9 |
| 53 | + |
| 54 | + - name: Setup Node.js |
| 55 | + uses: actions/setup-node@v4 |
| 56 | + with: |
| 57 | + node-version: "22.x" |
| 58 | + cache: "pnpm" |
| 59 | + |
| 60 | + - name: Install dependencies |
| 61 | + run: pnpm install --frozen-lockfile |
| 62 | + |
| 63 | + - name: Install Vercel CLI |
| 64 | + run: pnpm add --global vercel@latest |
| 65 | + |
| 66 | + - name: Turbo cached build (web) |
| 67 | + run: pnpm turbo run build --filter=@solid-connect/web |
| 68 | + |
| 69 | + - name: Prepare Vercel project metadata (web) |
| 70 | + run: | |
| 71 | + rm -rf .vercel |
| 72 | + mkdir -p .vercel-ci |
| 73 | + working-directory: apps/web |
| 74 | + |
| 75 | + - name: Pull Vercel environment (web stage) |
| 76 | + run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} 2>&1 | tee .vercel-ci/pull.log |
| 77 | + working-directory: apps/web |
| 78 | + |
| 79 | + - name: Build prebuilt artifacts (web stage) |
| 80 | + run: vercel build --yes --target=preview --token=${{ secrets.VERCEL_TOKEN }} 2>&1 | tee .vercel-ci/build.log |
| 81 | + working-directory: apps/web |
| 82 | + |
| 83 | + - name: Verify prebuilt artifacts (web) |
| 84 | + run: | |
| 85 | + test -f .vercel/output/config.json |
| 86 | + test -d .vercel/output/functions |
| 87 | + working-directory: apps/web |
| 88 | + |
| 89 | + - name: Deploy prebuilt artifacts (web stage) |
| 90 | + id: deploy_web |
| 91 | + run: | |
| 92 | + set -euo pipefail |
| 93 | + vercel deploy --prebuilt --target=preview --token=${{ secrets.VERCEL_TOKEN }} 2>&1 | tee .vercel-ci/deploy.log |
| 94 | + URL=$(grep -Eo 'https://[^ ]+\.vercel\.app' .vercel-ci/deploy.log | head -n 1) |
| 95 | + if [ -z "$URL" ]; then |
| 96 | + echo "Failed to parse deployment URL from Vercel output" >&2 |
| 97 | + exit 1 |
| 98 | + fi |
| 99 | + echo "url=$URL" >> "$GITHUB_OUTPUT" |
| 100 | + { |
| 101 | + echo "## Web Stage Deployment" |
| 102 | + echo "- Status: success" |
| 103 | + echo "- URL: $URL" |
| 104 | + } >> "$GITHUB_STEP_SUMMARY" |
| 105 | + working-directory: apps/web |
| 106 | + |
| 107 | + - name: Append failure summary (web stage) |
| 108 | + if: failure() |
| 109 | + run: | |
| 110 | + { |
| 111 | + echo "## Web Stage Deployment Failed" |
| 112 | + echo "- Inspect artifact: web-stage-vercel-logs" |
| 113 | + } >> "$GITHUB_STEP_SUMMARY" |
| 114 | +
|
| 115 | + - name: Upload Vercel logs (web stage) |
| 116 | + if: always() |
| 117 | + uses: actions/upload-artifact@v4 |
| 118 | + with: |
| 119 | + name: web-stage-vercel-logs |
| 120 | + path: apps/web/.vercel-ci/*.log |
| 121 | + if-no-files-found: ignore |
| 122 | + |
| 123 | + deploy-admin-stage: |
| 124 | + name: Deploy Admin (Stage) |
| 125 | + runs-on: ubuntu-latest |
| 126 | + needs: detect-changes |
| 127 | + if: needs.detect-changes.outputs.admin == 'true' || needs.detect-changes.outputs.root == 'true' |
| 128 | + env: |
| 129 | + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} |
| 130 | + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_ADMIN_STAGE }} |
| 131 | + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} |
| 132 | + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} |
| 133 | + steps: |
| 134 | + - name: Checkout repository |
| 135 | + uses: actions/checkout@v4 |
| 136 | + |
| 137 | + - name: Install pnpm |
| 138 | + uses: pnpm/action-setup@v3 |
| 139 | + with: |
| 140 | + version: 9 |
| 141 | + |
| 142 | + - name: Setup Node.js |
| 143 | + uses: actions/setup-node@v4 |
| 144 | + with: |
| 145 | + node-version: "22.x" |
| 146 | + cache: "pnpm" |
| 147 | + |
| 148 | + - name: Install dependencies |
| 149 | + run: pnpm install --frozen-lockfile |
| 150 | + |
| 151 | + - name: Install Vercel CLI |
| 152 | + run: pnpm add --global vercel@latest |
| 153 | + |
| 154 | + - name: Turbo cached build (admin) |
| 155 | + run: pnpm turbo run build --filter=@solid-connect/admin |
| 156 | + |
| 157 | + - name: Prepare Vercel project metadata (admin) |
| 158 | + run: | |
| 159 | + rm -rf .vercel |
| 160 | + mkdir -p .vercel-ci |
| 161 | + working-directory: apps/admin |
| 162 | + |
| 163 | + - name: Pull Vercel environment (admin stage) |
| 164 | + run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} 2>&1 | tee .vercel-ci/pull.log |
| 165 | + working-directory: apps/admin |
| 166 | + |
| 167 | + - name: Build prebuilt artifacts (admin stage) |
| 168 | + run: vercel build --yes --target=preview --token=${{ secrets.VERCEL_TOKEN }} 2>&1 | tee .vercel-ci/build.log |
| 169 | + working-directory: apps/admin |
| 170 | + |
| 171 | + - name: Verify prebuilt artifacts (admin) |
| 172 | + run: | |
| 173 | + test -f .vercel/output/config.json |
| 174 | + test -d .vercel/output/functions |
| 175 | + working-directory: apps/admin |
| 176 | + |
| 177 | + - name: Deploy prebuilt artifacts (admin stage) |
| 178 | + id: deploy_admin |
| 179 | + run: | |
| 180 | + set -euo pipefail |
| 181 | + vercel deploy --prebuilt --target=preview --token=${{ secrets.VERCEL_TOKEN }} 2>&1 | tee .vercel-ci/deploy.log |
| 182 | + URL=$(grep -Eo 'https://[^ ]+\.vercel\.app' .vercel-ci/deploy.log | head -n 1) |
| 183 | + if [ -z "$URL" ]; then |
| 184 | + echo "Failed to parse deployment URL from Vercel output" >&2 |
| 185 | + exit 1 |
| 186 | + fi |
| 187 | + echo "url=$URL" >> "$GITHUB_OUTPUT" |
| 188 | + { |
| 189 | + echo "## Admin Stage Deployment" |
| 190 | + echo "- Status: success" |
| 191 | + echo "- URL: $URL" |
| 192 | + } >> "$GITHUB_STEP_SUMMARY" |
| 193 | + working-directory: apps/admin |
| 194 | + |
| 195 | + - name: Append failure summary (admin stage) |
| 196 | + if: failure() |
| 197 | + run: | |
| 198 | + { |
| 199 | + echo "## Admin Stage Deployment Failed" |
| 200 | + echo "- Inspect artifact: admin-stage-vercel-logs" |
| 201 | + } >> "$GITHUB_STEP_SUMMARY" |
| 202 | +
|
| 203 | + - name: Upload Vercel logs (admin stage) |
| 204 | + if: always() |
| 205 | + uses: actions/upload-artifact@v4 |
| 206 | + with: |
| 207 | + name: admin-stage-vercel-logs |
| 208 | + path: apps/admin/.vercel-ci/*.log |
| 209 | + if-no-files-found: ignore |
0 commit comments