Correct the example code base file upload and cache management #40
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Cloudflare Infrastructure | |
on: | |
push: | |
branches: ['main'] | |
pull_request: | |
branches: ['main'] | |
jobs: | |
lint: | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Use Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
- name: Cache node_modules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
**/node_modules | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: npm install | |
- name: Lint | |
run: npm run lint | |
test: | |
runs-on: ubuntu-24.04 | |
# No 'needs:' here, so it can run in parallel with 'lint' | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Use Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
- name: Cache node_modules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
**/node_modules | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: npm install | |
- name: Test | |
run: npm run test | |
build_web: | |
runs-on: ubuntu-24.04 | |
needs: [lint, 'test'] # Only build if lint_and_test passed | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Use Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
- name: Cache node_modules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
**/node_modules | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: npm install | |
# @todo improve below to build all apps, including workers | |
- name: Build Web | |
run: npm run deploy:web | |
# Optionally store build artifacts for subsequent jobs | |
- name: Archive production artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: web-dist | |
path: ./apps/web/dist | |
# Or archive multiple if you have more apps | |
migrate: | |
runs-on: ubuntu-24.04 | |
needs: [build_web] | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Use Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
- name: Cache node_modules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
**/node_modules | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: npm install | |
- name: Run migrations on production | |
run: npm run migrate:d1:production | |
env: | |
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
deploy_web: | |
runs-on: ubuntu-24.04 | |
needs: [migrate] | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Use Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
- name: Cache node_modules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
**/node_modules | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: npm install | |
- name: Run Setup | |
run: npm run setup | |
- name: Download build artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: web-dist | |
path: './apps/web/dist' | |
- name: Display CP and Wrangler versions | |
run: ls -al . && ls -al ./apps/web/dist && cat ./apps/web/wrangler.json | |
- name: Deploy to Cloudflare Pages | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
workingDirectory: ./apps/web | |
command: pages deploy ./dist | |
deploy_worker: | |
runs-on: ubuntu-24.04 | |
needs: [migrate] | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Use Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
- name: Cache node_modules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
**/node_modules | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: npm install | |
- name: Run Setup | |
run: npm run setup | |
- name: Run Setup | |
run: npm run build --workspace=@services/database | |
- name: Deploy to Cloudflare Workers | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
workingDirectory: ./apps/worker | |
command: deploy |