Skip to content

Commit e9a21c3

Browse files
committed
adding docs preview after CI
1 parent 2398e50 commit e9a21c3

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

.github/get_preview_url.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
import re
3+
4+
deploy_output = os.environ['DEPLOY_OUTPUT']
5+
6+
m = re.search(r'https://(\S+)\.workers\.dev', deploy_output)
7+
assert m, f'Could not find worker URL in {deploy_output!r}'
8+
worker_name = m.group(1)
9+
10+
m = re.search(r'Current Version ID: ([^-]+)', deploy_output)
11+
assert m, f'Could not find version ID in {deploy_output!r}'
12+
version_id = m.group(1)
13+
14+
preview_url = f'https://{version_id}-{worker_name}.workers.dev'
15+
16+
print(f'preview_url={preview_url}')

.github/workflows/coverage.yaml renamed to .github/workflows/after-ci.yml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Smokeshow
1+
name: After CI
22

33
on:
44
workflow_run:
@@ -45,3 +45,49 @@ jobs:
4545
SMOKESHOW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4646
SMOKESHOW_GITHUB_PR_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
4747
SMOKESHOW_AUTH_KEY: ${{ secrets.SMOKESHOW_AUTH_KEY }}
48+
49+
deploy-docs-preview:
50+
runs-on: ubuntu-latest
51+
needs: [check]
52+
environment:
53+
name: deploy-preview
54+
url: ${{ steps.get_preview_url.outputs.preview_url }}
55+
56+
steps:
57+
- uses: dawidd6/action-download-artifact@v6
58+
with:
59+
workflow: ci.yml
60+
name: docs-site
61+
commit: ${{ github.event.workflow_run.head_sha }}
62+
allow_forks: true
63+
workflow_conclusion: completed
64+
if_no_artifact_found: warn
65+
66+
- uses: actions/setup-node@v4
67+
- run: npm install
68+
69+
- run: 'echo head_sha $VAR'
70+
env:
71+
VAR: ${{ github.event.workflow_run.head_sha }}
72+
73+
- run: 'echo head_branch $VAR'
74+
env:
75+
VAR: ${{ github.event.workflow_run.head_branch }}
76+
77+
- uses: cloudflare/wrangler-action@v3
78+
name: Deploy docs-preview
79+
id: deploy
80+
with:
81+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
82+
environment: previews
83+
workingDirectory: docs-site
84+
command: >
85+
deploy
86+
--var GIT_COMMIT_SHA:${{ github.event.workflow_run.head_sha }}
87+
--var GIT_BRANCH:${{ github.event.workflow_run.head_branch }}
88+
89+
- name: get preview URL
90+
id: get_preview_url
91+
run: python .github/get_preview_url.py >> $GITHUB_OUTPUT
92+
env:
93+
DEPLOY_OUTPUT: ${{ steps.deploy.outputs.command-output }}

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ jobs:
7575

7676
- run: tree site
7777

78+
- name: Store docs
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: docs-site
82+
path: site
83+
7884
test-live:
7985
runs-on: ubuntu-latest
8086
timeout-minutes: 5

0 commit comments

Comments
 (0)