Repository navigation
123 lines (110 loc) · 4.19 KB
/
Copy pathdocs.yml
File metadata and controls
123 lines (110 loc) · 4.19 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Docs
on:
pull_request:
branches: [main]
paths:
- .github/workflows/docs.yml
- docs/**
push:
branches: [main]
paths:
- .github/workflows/docs.yml
- docs/**
workflow_dispatch:
concurrency:
group: docs-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
deployments: write
issues: write
pull-requests: write
jobs:
build-and-deploy:
name: Build and deploy docs
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
worker:
- name: docs
directory: docs
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
defaults:
run:
working-directory: docs
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: "24"
cache: npm
cache-dependency-path: docs/package-lock.json
- name: Set up Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
- name: Install dependencies
run: npm ci
- name: Build docs
run: npm run build
- name: Deploy
if: ${{ github.event_name != 'pull_request' && env.CLOUDFLARE_ACCOUNT_ID != '' && env.CLOUDFLARE_API_TOKEN != '' }}
uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: ${{ matrix.worker.directory }}
command: deploy --config wrangler.ci.jsonc
- name: Preview
id: preview
if: ${{ github.event_name == 'pull_request' && env.CLOUDFLARE_ACCOUNT_ID != '' && env.CLOUDFLARE_API_TOKEN != '' }}
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
PREVIEW_ALIAS: pr-${{ github.event.pull_request.number }}
run: |
set -o pipefail
npx wrangler versions upload --preview-alias "$PREVIEW_ALIAS" 2>&1 | tee "$RUNNER_TEMP/wrangler-preview.log"
deployment_url="$(grep -Eo 'https://[^[:space:]]+workers.dev[^[:space:]]*' "$RUNNER_TEMP/wrangler-preview.log" | tail -n 1)"
if [ -z "$deployment_url" ]; then
echo "No Cloudflare preview URL found in Wrangler output." >&2
exit 1
fi
echo "deployment-url=$deployment_url" >> "$GITHUB_OUTPUT"
- name: Publish preview summary
if: ${{ github.event_name == 'pull_request' && steps.preview.outputs.deployment-url != '' }}
env:
DEPLOYMENT_URL: ${{ steps.preview.outputs.deployment-url }}
run: |
{
echo "### Cloudflare Workers docs preview"
echo
echo "$DEPLOYMENT_URL"
} >> "$GITHUB_STEP_SUMMARY"
- name: Publish preview comment
if: ${{ github.event_name == 'pull_request' && steps.preview.outputs.deployment-url != '' }}
env:
DEPLOYMENT_URL: ${{ steps.preview.outputs.deployment-url }}
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
marker="<!-- centaur-docs-preview-url -->"
body="$(cat <<EOF
$marker
### Cloudflare Workers docs preview
$DEPLOYMENT_URL
EOF
)"
comment_id="$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --paginate \
--jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | contains(\"$marker\"))) | .id" \
2>/dev/null | tail -n 1 || true)"
if [ -n "$comment_id" ]; then
gh api --method PATCH "repos/${GITHUB_REPOSITORY}/issues/comments/${comment_id}" -f body="$body"
else
gh api --method POST "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" -f body="$body"
fi