|
| 1 | +name: Frontend Cloudflare Deploy |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - dev |
| 10 | + tags: |
| 11 | + - frontend-pre-* |
| 12 | + - frontend-live-* |
| 13 | + workflow_dispatch: |
| 14 | + inputs: |
| 15 | + product: |
| 16 | + description: Product to deploy |
| 17 | + required: true |
| 18 | + type: choice |
| 19 | + default: all |
| 20 | + options: |
| 21 | + - all |
| 22 | + - nucleum |
| 23 | + - memotron |
| 24 | + - pointron |
| 25 | + environment: |
| 26 | + description: Frontend environment to deploy |
| 27 | + required: true |
| 28 | + type: choice |
| 29 | + default: dev |
| 30 | + options: |
| 31 | + - dev |
| 32 | + - pre |
| 33 | + - live |
| 34 | + |
| 35 | +jobs: |
| 36 | + detect: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + outputs: |
| 39 | + environment: ${{ steps.detect.outputs.environment }} |
| 40 | + products: ${{ steps.detect.outputs.products }} |
| 41 | + steps: |
| 42 | + - id: detect |
| 43 | + env: |
| 44 | + EVENT_NAME: ${{ github.event_name }} |
| 45 | + INPUT_ENVIRONMENT: ${{ github.event.inputs.environment }} |
| 46 | + INPUT_PRODUCT: ${{ github.event.inputs.product }} |
| 47 | + REF_TYPE: ${{ github.ref_type }} |
| 48 | + REF_NAME: ${{ github.ref_name }} |
| 49 | + run: | |
| 50 | + set -euo pipefail |
| 51 | +
|
| 52 | + default_products='["nucleum","memotron","pointron"]' |
| 53 | +
|
| 54 | + if [ "$EVENT_NAME" = "workflow_dispatch" ]; then |
| 55 | + environment="${INPUT_ENVIRONMENT:-dev}" |
| 56 | + product="${INPUT_PRODUCT:-all}" |
| 57 | + case "$environment" in |
| 58 | + pre) |
| 59 | + [[ "$REF_TYPE" == "tag" && "$REF_NAME" == frontend-pre-* ]] || { |
| 60 | + echo "Pre deploys must run from a frontend-pre-* tag" >&2 |
| 61 | + exit 1 |
| 62 | + } |
| 63 | + ;; |
| 64 | + live) |
| 65 | + [[ "$REF_TYPE" == "tag" && "$REF_NAME" == frontend-live-* ]] || { |
| 66 | + echo "Live deploys must run from a frontend-live-* tag" >&2 |
| 67 | + exit 1 |
| 68 | + } |
| 69 | + ;; |
| 70 | + esac |
| 71 | + elif [[ "$REF_TYPE" == "tag" && "$REF_NAME" == frontend-pre-* ]]; then |
| 72 | + environment="pre" |
| 73 | + product="all" |
| 74 | + elif [[ "$REF_TYPE" == "tag" && "$REF_NAME" == frontend-live-* ]]; then |
| 75 | + environment="live" |
| 76 | + product="all" |
| 77 | + else |
| 78 | + environment="dev" |
| 79 | + product="all" |
| 80 | + fi |
| 81 | +
|
| 82 | + case "$environment" in |
| 83 | + dev|pre|live) ;; |
| 84 | + *) echo "Invalid environment: $environment" >&2; exit 1 ;; |
| 85 | + esac |
| 86 | +
|
| 87 | + case "$product" in |
| 88 | + all) products="$default_products" ;; |
| 89 | + nucleum|memotron|pointron) products="[\"$product\"]" ;; |
| 90 | + *) echo "Invalid product: $product" >&2; exit 1 ;; |
| 91 | + esac |
| 92 | +
|
| 93 | + echo "environment=$environment" >> "$GITHUB_OUTPUT" |
| 94 | + echo "products=$products" >> "$GITHUB_OUTPUT" |
| 95 | +
|
| 96 | + deploy: |
| 97 | + runs-on: ubuntu-latest |
| 98 | + needs: detect |
| 99 | + environment: ${{ needs.detect.outputs.environment }} |
| 100 | + concurrency: |
| 101 | + group: frontend-cloudflare-deploy-${{ needs.detect.outputs.environment }}-${{ matrix.product }} |
| 102 | + cancel-in-progress: false |
| 103 | + strategy: |
| 104 | + fail-fast: false |
| 105 | + matrix: |
| 106 | + product: ${{ fromJson(needs.detect.outputs.products) }} |
| 107 | + steps: |
| 108 | + - name: Checkout Nucleus |
| 109 | + uses: actions/checkout@v4 |
| 110 | + |
| 111 | + - name: Setup Node |
| 112 | + uses: actions/setup-node@v4 |
| 113 | + with: |
| 114 | + node-version: 22 |
| 115 | + cache: npm |
| 116 | + |
| 117 | + - name: Install dependencies |
| 118 | + run: npm ci --legacy-peer-deps |
| 119 | + |
| 120 | + - name: Validate frontend Cloudflare config |
| 121 | + run: npm --workspace @21n/frontend-deploy run check |
| 122 | + |
| 123 | + - name: Deploy frontend Worker assets |
| 124 | + env: |
| 125 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 126 | + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 127 | + run: npm --workspace @21n/frontend-deploy run deploy:${{ needs.detect.outputs.environment }} -- --products=${{ matrix.product }} |
0 commit comments