|
| 1 | +name: Cloudflare Infra |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - 'infra/web/**' |
| 7 | + - '.github/workflows/cloudflare-worker-prod.yml' |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - dev |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: cloudflare-infra |
| 15 | + cancel-in-progress: false |
| 16 | + |
| 17 | +jobs: |
| 18 | + plan: |
| 19 | + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + env: |
| 24 | + CLOUDFLARE_API_TOKEN: ${{ secrets.TF_CLOUDFLARE_API_TOKEN }} |
| 25 | + TF_VAR_account_id: ${{ secrets.TF_VAR_ACCOUNT_ID }} |
| 26 | + TF_VAR_zone_id: ${{ secrets.TF_VAR_ZONE_ID }} |
| 27 | + TF_HTTP_ADDRESS: ${{ secrets.TF_HTTP_ADDRESS }} |
| 28 | + TF_HTTP_LOCK_ADDRESS: ${{ secrets.TF_HTTP_LOCK_ADDRESS }} |
| 29 | + TF_HTTP_UNLOCK_ADDRESS: ${{ secrets.TF_HTTP_UNLOCK_ADDRESS }} |
| 30 | + TF_HTTP_USERNAME: ${{ secrets.TF_HTTP_USERNAME }} |
| 31 | + TF_HTTP_PASSWORD: ${{ secrets.TF_HTTP_PASSWORD }} |
| 32 | + TF_HTTP_LOCK_METHOD: 'POST' |
| 33 | + TF_HTTP_UNLOCK_METHOD: 'DELETE' |
| 34 | + TF_HTTP_RETRY_WAIT_MIN: '5' |
| 35 | + defaults: |
| 36 | + run: |
| 37 | + working-directory: infra/web |
| 38 | + steps: |
| 39 | + - name: Checkout repository |
| 40 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 41 | + with: |
| 42 | + persist-credentials: false |
| 43 | + |
| 44 | + - name: Prepare deployment metadata |
| 45 | + shell: bash |
| 46 | + run: | |
| 47 | + workers_message="$(git log -1 --pretty=%s)" |
| 48 | + workers_message="$(printf '%s' "$workers_message" | head -c 100)" |
| 49 | + printf 'TF_VAR_workers_message=%s\n' "$workers_message" >> "$GITHUB_ENV" |
| 50 | +
|
| 51 | + - name: Setup node |
| 52 | + uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 |
| 53 | + with: |
| 54 | + node-version-file: '.node-version' |
| 55 | + cache: 'npm' |
| 56 | + |
| 57 | + - name: Install dependencies |
| 58 | + working-directory: . |
| 59 | + run: npm ci |
| 60 | + |
| 61 | + - name: Build app |
| 62 | + working-directory: . |
| 63 | + run: npm run build |
| 64 | + |
| 65 | + - name: Setup OpenTofu |
| 66 | + uses: opentofu/setup-opentofu@9d84900f3238fab8cd84ce47d658d25dd008be2f # v1.0.8 |
| 67 | + with: |
| 68 | + tofu_version: 1.11.5 |
| 69 | + |
| 70 | + - name: Check formatting |
| 71 | + run: tofu fmt -check |
| 72 | + |
| 73 | + - name: Initialize OpenTofu |
| 74 | + run: tofu init -input=false -reconfigure |
| 75 | + |
| 76 | + - name: Validate configuration |
| 77 | + run: tofu validate -no-color |
| 78 | + |
| 79 | + - name: Plan infrastructure |
| 80 | + run: tofu plan -input=false -lock=false -no-color |
| 81 | + |
| 82 | + apply: |
| 83 | + if: (github.event_name == 'push' && github.ref_name == 'dev') || github.event_name == 'workflow_dispatch' |
| 84 | + runs-on: ubuntu-latest |
| 85 | + permissions: |
| 86 | + contents: read |
| 87 | + env: |
| 88 | + CLOUDFLARE_API_TOKEN: ${{ secrets.TF_CLOUDFLARE_API_TOKEN }} |
| 89 | + TF_VAR_account_id: ${{ secrets.TF_VAR_ACCOUNT_ID }} |
| 90 | + TF_VAR_zone_id: ${{ secrets.TF_VAR_ZONE_ID }} |
| 91 | + TF_HTTP_ADDRESS: ${{ secrets.TF_HTTP_ADDRESS }} |
| 92 | + TF_HTTP_LOCK_ADDRESS: ${{ secrets.TF_HTTP_LOCK_ADDRESS }} |
| 93 | + TF_HTTP_UNLOCK_ADDRESS: ${{ secrets.TF_HTTP_UNLOCK_ADDRESS }} |
| 94 | + TF_HTTP_USERNAME: ${{ secrets.TF_HTTP_USERNAME }} |
| 95 | + TF_HTTP_PASSWORD: ${{ secrets.TF_HTTP_PASSWORD }} |
| 96 | + TF_HTTP_LOCK_METHOD: 'POST' |
| 97 | + TF_HTTP_UNLOCK_METHOD: 'DELETE' |
| 98 | + TF_HTTP_RETRY_WAIT_MIN: '5' |
| 99 | + defaults: |
| 100 | + run: |
| 101 | + working-directory: infra/web |
| 102 | + steps: |
| 103 | + - name: Checkout repository |
| 104 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 105 | + with: |
| 106 | + persist-credentials: false |
| 107 | + |
| 108 | + - name: Prepare deployment metadata |
| 109 | + shell: bash |
| 110 | + run: | |
| 111 | + workers_message="$(git log -1 --pretty=%s)" |
| 112 | + workers_message="$(printf '%s' "$workers_message" | head -c 100)" |
| 113 | + printf 'TF_VAR_workers_message=%s\n' "$workers_message" >> "$GITHUB_ENV" |
| 114 | +
|
| 115 | + - name: Setup node |
| 116 | + uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 |
| 117 | + with: |
| 118 | + node-version-file: '.node-version' |
| 119 | + cache: 'npm' |
| 120 | + |
| 121 | + - name: Install dependencies |
| 122 | + working-directory: . |
| 123 | + run: npm ci |
| 124 | + |
| 125 | + - name: Build app |
| 126 | + working-directory: . |
| 127 | + run: npm run build |
| 128 | + |
| 129 | + - name: Setup OpenTofu |
| 130 | + uses: opentofu/setup-opentofu@9d84900f3238fab8cd84ce47d658d25dd008be2f # v1.0.8 |
| 131 | + with: |
| 132 | + tofu_version: 1.11.5 |
| 133 | + |
| 134 | + - name: Check formatting |
| 135 | + run: tofu fmt -check |
| 136 | + |
| 137 | + - name: Initialize OpenTofu |
| 138 | + run: tofu init -input=false -reconfigure |
| 139 | + |
| 140 | + - name: Validate configuration |
| 141 | + run: tofu validate -no-color |
| 142 | + |
| 143 | + - name: Plan infrastructure |
| 144 | + run: tofu plan -input=false -no-color |
| 145 | + |
| 146 | + - name: Apply infrastructure |
| 147 | + run: tofu apply -input=false -auto-approve |
0 commit comments