-
Notifications
You must be signed in to change notification settings - Fork 62
85 lines (72 loc) · 2.36 KB
/
ci.yml
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
name: ci
on:
pull_request:
branches: [main]
push:
branches: [main]
env:
CF_PROJECT_NAME: tech-docs
CF_BASE_URL: tech-docs-2ac
jobs:
checks:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: '18.18.1'
cache: 'yarn'
- name: Install ⚙️
run: yarn install --frozen-lockfile
- name: Prettier 🎨
run: yarn run prettier
build-and-deploy:
runs-on: ubuntu-latest
needs: checks
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: '18.18.1'
cache: 'yarn'
- name: Install ⚙️
run: yarn install --frozen-lockfile
- name: Build 🛠
run: yarn build
- name: Extract branch name
shell: bash
run: |
PR_NUMBER="${{ github.event.number }}"
if [ -n "$PR_NUMBER" ]
then
echo "branch_name=pr-${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "url=https://pr-${PR_NUMBER}.${{ env.CF_BASE_URL }}.pages.dev" >> $GITHUB_OUTPUT
echo "branch=--branch pr-${PR_NUMBER}" >> $GITHUB_OUTPUT
else
echo "branch_name=" >> $GITHUB_OUTPUT
echo "branch=" >> $GITHUB_OUTPUT
fi
id: extract_branch
- name: Deploy
uses: cloudflare/[email protected]
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
command: pages deploy --project-name "${CF_PROJECT_NAME}" build ${{ steps.extract_branch.outputs.branch }} | tee output.log
postCommands: |
sed < output.log -n 's#.*Take a peek over at \(.*\)$#specific_url=\1#p' >> $GITHUB_OUTPUT
id: deploy
- name: Create commit comment
uses: mshick/add-pr-comment@v2
if: ${{ github.event.number != '' }}
with:
message: |
### Deployed with **Cloudflare Pages** :cloud: :rocket: :ok:
- **URL**: [${{ steps.extract_branch.outputs.url }}](${{ steps.extract_branch.outputs.url }})
- **Specific**: [${{ steps.deploy.outputs.specific_url }}](${{ steps.deploy.outputs.specific_url }})