ci: add Bunny deployment workflow
2d3dba4 parent: 3fe3ee6 added
.github/workflows/deploy-bunny.yml +94 -0 | new file mode 100644 | ||
| @@ -0,0 +1,94 @@ | ||
| 1 | +name: Deploy to Bunny | |
| 2 | + | |
| 3 | +on: | |
| 4 | + push: | |
| 5 | + branches: [develop] | |
| 6 | + workflow_dispatch: | |
| 7 | + | |
| 8 | +permissions: | |
| 9 | + contents: read | |
| 10 | + | |
| 11 | +concurrency: | |
| 12 | + group: deploy-bunny-production | |
| 13 | + cancel-in-progress: true | |
| 14 | + | |
| 15 | +jobs: | |
| 16 | + test: | |
| 17 | + name: Run quality checks | |
| 18 | + runs-on: ubuntu-latest | |
| 19 | + | |
| 20 | + steps: | |
| 21 | + - name: Check out repository | |
| 22 | + uses: actions/checkout@v4 | |
| 23 | + | |
| 24 | + - name: Set up Node.js | |
| 25 | + uses: actions/setup-node@v4 | |
| 26 | + with: | |
| 27 | + node-version: "20" | |
| 28 | + cache: npm | |
| 29 | + | |
| 30 | + - name: Install dependencies | |
| 31 | + run: npm ci | |
| 32 | + | |
| 33 | + - name: Lint | |
| 34 | + run: npm run lint | |
| 35 | + | |
| 36 | + - name: Type check | |
| 37 | + run: npm run typecheck | |
| 38 | + | |
| 39 | + - name: Test | |
| 40 | + run: npm test | |
| 41 | + | |
| 42 | + deploy: | |
| 43 | + name: Build and deploy static site | |
| 44 | + needs: test | |
| 45 | + runs-on: ubuntu-latest | |
| 46 | + environment: production | |
| 47 | + | |
| 48 | + steps: | |
| 49 | + - name: Check out repository | |
| 50 | + uses: actions/checkout@v4 | |
| 51 | + | |
| 52 | + - name: Set up Node.js | |
| 53 | + uses: actions/setup-node@v4 | |
| 54 | + with: | |
| 55 | + node-version: "20" | |
| 56 | + cache: npm | |
| 57 | + | |
| 58 | + - name: Install dependencies | |
| 59 | + run: npm ci | |
| 60 | + | |
| 61 | + - name: Build static site | |
| 62 | + run: npm run build | |
| 63 | + | |
| 64 | + - name: Upload static site to Bunny Storage | |
| 65 | + env: | |
| 66 | + BUNNY_STORAGE_ENDPOINT: ${{ vars.BUNNY_STORAGE_ENDPOINT }} | |
| 67 | + BUNNY_STORAGE_PASSWORD: ${{ secrets.BUNNY_STORAGE_PASSWORD }} | |
| 68 | + run: | | |
| 69 | + set -euo pipefail | |
| 70 | + | |
| 71 | + while IFS= read -r -d '' file; do | |
| 72 | + relative_path="${file#out/}" | |
| 73 | + mime_type="$(file --brief --mime-type "$file")" | |
| 74 | + | |
| 75 | + echo "Uploading $relative_path" | |
| 76 | + curl --fail --silent --show-error \ | |
| 77 | + --request PUT \ | |
| 78 | + --header "AccessKey: $BUNNY_STORAGE_PASSWORD" \ | |
| 79 | + --header "Content-Type: $mime_type" \ | |
| 80 | + --upload-file "$file" \ | |
| 81 | + "$BUNNY_STORAGE_ENDPOINT/$relative_path" | |
| 82 | + done < <(find out -type f -print0) | |
| 83 | + | |
| 84 | + - name: Purge Bunny CDN cache | |
| 85 | + env: | |
| 86 | + BUNNY_API_KEY: ${{ secrets.BUNNY_API_KEY }} | |
| 87 | + BUNNY_PULL_ZONE_ID: ${{ vars.BUNNY_PULL_ZONE_ID }} | |
| 88 | + run: | | |
| 89 | + set -euo pipefail | |
| 90 | + | |
| 91 | + curl --fail --silent --show-error \ | |
| 92 | + --request POST \ | |
| 93 | + --header "AccessKey: $BUNNY_API_KEY" \ | |
| 94 | + "https://api.bunny.net/pullzone/$BUNNY_PULL_ZONE_ID/purgeCache" | |
| new file mode 100644 | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | +name: Deploy to Bunny | ||
| 2 | + | ||
| 3 | +on: | ||
| 4 | + push: | ||
| 5 | + branches: [develop] | ||
| 6 | + workflow_dispatch: | ||
| 7 | + | ||
| 8 | +permissions: | ||
| 9 | + contents: read | ||
| 10 | + | ||
| 11 | +concurrency: | ||
| 12 | + group: deploy-bunny-production | ||
| 13 | + cancel-in-progress: true | ||
| 14 | + | ||
| 15 | +jobs: | ||
| 16 | + test: | ||
| 17 | + name: Run quality checks | ||
| 18 | + runs-on: ubuntu-latest | ||
| 19 | + | ||
| 20 | + steps: | ||
| 21 | + - name: Check out repository | ||
| 22 | + uses: actions/checkout@v4 | ||
| 23 | + | ||
| 24 | + - name: Set up Node.js | ||
| 25 | + uses: actions/setup-node@v4 | ||
| 26 | + with: | ||
| 27 | + node-version: "20" | ||
| 28 | + cache: npm | ||
| 29 | + | ||
| 30 | + - name: Install dependencies | ||
| 31 | + run: npm ci | ||
| 32 | + | ||
| 33 | + - name: Lint | ||
| 34 | + run: npm run lint | ||
| 35 | + | ||
| 36 | + - name: Type check | ||
| 37 | + run: npm run typecheck | ||
| 38 | + | ||
| 39 | + - name: Test | ||
| 40 | + run: npm test | ||
| 41 | + | ||
| 42 | + deploy: | ||
| 43 | + name: Build and deploy static site | ||
| 44 | + needs: test | ||
| 45 | + runs-on: ubuntu-latest | ||
| 46 | + environment: production | ||
| 47 | + | ||
| 48 | + steps: | ||
| 49 | + - name: Check out repository | ||
| 50 | + uses: actions/checkout@v4 | ||
| 51 | + | ||
| 52 | + - name: Set up Node.js | ||
| 53 | + uses: actions/setup-node@v4 | ||
| 54 | + with: | ||
| 55 | + node-version: "20" | ||
| 56 | + cache: npm | ||
| 57 | + | ||
| 58 | + - name: Install dependencies | ||
| 59 | + run: npm ci | ||
| 60 | + | ||
| 61 | + - name: Build static site | ||
| 62 | + run: npm run build | ||
| 63 | + | ||
| 64 | + - name: Upload static site to Bunny Storage | ||
| 65 | + env: | ||
| 66 | + BUNNY_STORAGE_ENDPOINT: ${{ vars.BUNNY_STORAGE_ENDPOINT }} | ||
| 67 | + BUNNY_STORAGE_PASSWORD: ${{ secrets.BUNNY_STORAGE_PASSWORD }} | ||
| 68 | + run: | | ||
| 69 | + set -euo pipefail | ||
| 70 | + | ||
| 71 | + while IFS= read -r -d '' file; do | ||
| 72 | + relative_path="${file#out/}" | ||
| 73 | + mime_type="$(file --brief --mime-type "$file")" | ||
| 74 | + | ||
| 75 | + echo "Uploading $relative_path" | ||
| 76 | + curl --fail --silent --show-error \ | ||
| 77 | + --request PUT \ | ||
| 78 | + --header "AccessKey: $BUNNY_STORAGE_PASSWORD" \ | ||
| 79 | + --header "Content-Type: $mime_type" \ | ||
| 80 | + --upload-file "$file" \ | ||
| 81 | + "$BUNNY_STORAGE_ENDPOINT/$relative_path" | ||
| 82 | + done < <(find out -type f -print0) | ||
| 83 | + | ||
| 84 | + - name: Purge Bunny CDN cache | ||
| 85 | + env: | ||
| 86 | + BUNNY_API_KEY: ${{ secrets.BUNNY_API_KEY }} | ||
| 87 | + BUNNY_PULL_ZONE_ID: ${{ vars.BUNNY_PULL_ZONE_ID }} | ||
| 88 | + run: | | ||
| 89 | + set -euo pipefail | ||
| 90 | + | ||
| 91 | + curl --fail --silent --show-error \ | ||
| 92 | + --request POST \ | ||
| 93 | + --header "AccessKey: $BUNNY_API_KEY" \ | ||
| 94 | + "https://api.bunny.net/pullzone/$BUNNY_PULL_ZONE_ID/purgeCache" | ||