Repository navigation
109 lines (97 loc) · 3.84 KB
/
Copy pathrelease-embedded.yml
File metadata and controls
109 lines (97 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Release Embedded Build
on:
release:
types: [published]
workflow_dispatch:
inputs:
cdn_release_tag:
description: 'Published release tag to upload to R2 (leave empty to test a build)'
required: false
type: string
permissions:
contents: write
jobs:
build-and-release:
if: github.event_name == 'release' || !inputs.cdn_release_tag
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build embedded
run: npm run build-embedded
- name: Remove source maps
run: find dist-embedded -name "*.map" -type f -delete
- name: Create zip file
run: |
cd dist-embedded
zip -r ../dist-embedded.zip . -x embedded.html
cd ..
- name: Upload release asset
if: github.event_name == 'release'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
count=$(gh api "repos/$GITHUB_REPOSITORY/releases/tags/$RELEASE_TAG" --jq '[.assets[] | select(.name == "dist-embedded.zip")] | length')
if [ "$count" = 0 ]; then
gh release upload "$RELEASE_TAG" dist-embedded.zip
else
echo "Keeping the existing release archive for reproducible CDN publication."
fi
- name: Upload artifact (for workflow_dispatch)
if: github.event_name == 'workflow_dispatch'
uses: actions/upload-artifact@v4
with:
name: dist-embedded
path: dist-embedded.zip
publish-cdn:
needs: build-and-release
if: >-
always() && !cancelled() &&
((github.event_name == 'release' && needs.build-and-release.result == 'success') ||
(github.event_name == 'workflow_dispatch' && inputs.cdn_release_tag && needs.build-and-release.result == 'skipped'))
runs-on: ubuntu-latest
timeout-minutes: 30
concurrency:
group: cdn-sqlide-${{ github.event.release.tag_name || inputs.cdn_release_tag }}
cancel-in-progress: false
permissions:
contents: read
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_R2_CDN }}
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID || secrets.CLOUDFLARE_ACCOUNT_ID }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ github.event.release.tag_name || inputs.cdn_release_tag }}
WRANGLER_SEND_METRICS: 'false'
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || github.event.repository.default_branch }}
- uses: actions/setup-node@v4
with:
node-version: '24'
cache: 'npm'
- run: npm ci
- run: npm run test:cdn
- name: Install Wrangler
run: npm install --global wrangler@4.149.0
- name: Check Cloudflare configuration
run: |
test -n "$CLOUDFLARE_API_TOKEN" || { echo 'Missing CLOUDFLARE_R2_CDN Actions secret'; exit 1; }
test -n "$CLOUDFLARE_ACCOUNT_ID" || { echo 'Missing CLOUDFLARE_ACCOUNT_ID Actions variable or secret'; exit 1; }
- name: Download and verify the published release
run: node scripts/fetch-cdn-release.mjs sqlide "$RELEASE_TAG"
- name: Allow browser access to runtime files
run: wrangler r2 bucket cors set cdn --file scripts/cdn-cors.json --force
- name: Publish immutable runtime files
run: node scripts/publish-cdn.mjs sqlide "$RELEASE_TAG" .cache/cdn-release
- name: Verify files through the public CDN
run: node scripts/verify-cdn.mjs sqlide "$RELEASE_TAG" .cache/cdn-release