Skip to content

Commit 65241aa

Browse files
chore: Enable preview urls
1 parent 197854e commit 65241aa

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

.github/workflows/build-deploy.yml

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,46 @@ jobs:
1616
runs-on: ubuntu-latest
1717
permissions:
1818
contents: read
19-
env:
20-
VITE_APP_HOSTNAME: alpha.vivliostyle.pub
19+
outputs:
20+
preview: ${{ steps.build-env.outputs.preview }}
21+
preview-alias: ${{ steps.build-env.outputs.preview-alias }}
22+
hostname: ${{ steps.build-env.outputs.hostname }}
2123
steps:
2224
- uses: vivliostyle/vivliostyle.pub/.github/actions/setup@ci/deploy
25+
- name: Determine build environment
26+
id: build-env
27+
run: |
28+
if [[ "${{ github.ref_name }}" == "main" ]]; then
29+
echo "preview=false" >> $GITHUB_OUTPUT
30+
echo "hostname=alpha.vivliostyle.pub" >> $GITHUB_OUTPUT
31+
else
32+
echo "preview=true" >> $GITHUB_OUTPUT
33+
echo "preview-alias=pr-preview-${{ github.event.number }}" >> $GITHUB_OUTPUT
34+
echo "hostname=pr-preview-${{ github.event.number }}-vivliostyle-pub-app.vivliostyle.workers.dev" >> $GITHUB_OUTPUT
35+
fi
2336
- run: pnpm build
37+
env:
38+
VITE_APP_HOSTNAME: ${{ steps.build-env.outputs.hostname }}
2439

2540
deploy:
26-
# if: ${{ github.ref == 'refs/heads/main' }}
2741
needs: build
2842
runs-on: ubuntu-latest
2943
permissions:
3044
contents: read
31-
env:
32-
VITE_APP_HOSTNAME: alpha.vivliostyle.pub
3345
steps:
3446
- uses: vivliostyle/vivliostyle.pub/.github/actions/setup@ci/deploy
3547
- run: pnpm build
36-
- uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3.14.1
37-
with:
38-
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
39-
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
40-
wranglerVersion: '4.50.0'
48+
env:
49+
VITE_APP_HOSTNAME: ${{ needs.build.outputs.hostname }}
50+
- name: Deploy production
51+
if: ${{ !fromJSON(needs.build.outputs.preview) }}
52+
run: npx wrangler deploy
53+
env:
54+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
55+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
56+
- name: Deploy preview
57+
if: ${{ fromJSON(needs.build.outputs.preview) }}
58+
run: npx wrangler versions upload --preview-alias ${{ needs.build.outputs.preview-alias }}
59+
env:
60+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
61+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

turbo.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"$schema": "https://turbo.build/schema.json",
33
"ui": "tui",
4-
"globalEnv": ["VITE_APP_*"],
54
"tasks": {
65
"build": {
76
"dependsOn": ["^build", "build:rollup-wasm", "build:viewer-resource"],
@@ -28,6 +27,9 @@
2827
"test": {
2928
"inputs": ["$TURBO_DEFAULT$", ".env*"],
3029
"outputs": ["coverage/**"]
30+
},
31+
"@v/viola#build": {
32+
"env": ["VITE_APP_*"]
3133
}
3234
}
3335
}

0 commit comments

Comments
 (0)