Skip to content

Commit c416f1f

Browse files
committed
ci: deploy and pull request preview workflow
1 parent 475ca53 commit c416f1f

File tree

2 files changed

+136
-10
lines changed

2 files changed

+136
-10
lines changed

.github/workflows/deploy.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy to GitHub Pages
1+
name: Deploy to Cloudflare Pages
22
on:
33
workflow_dispatch:
44
push:
@@ -39,21 +39,20 @@ jobs:
3939
cd preview_generator
4040
cargo run --release -- blog ../articles ../out/blog/articles
4141
cargo run --release -- this_week ../esta_semana_en_rust/ ../out/blog/articles
42+
4243
- name: Upload artifact
43-
uses: actions/upload-pages-artifact@v1
44+
uses: actions/upload-artifact@v4
4445
with:
45-
name: out
4646
path: ./out/blog
4747

4848
deploy:
49-
environment:
50-
name: github-pages
51-
url: ${{ steps.deployment.outputs.page_url }}
5249
runs-on: ubuntu-latest
5350
needs: build
5451
steps:
55-
- name: Deploy to GitHub Pages
56-
id: deployment
57-
uses: actions/deploy-pages@v2
52+
- uses: actions/download-artifact@v4
53+
- name: Deploy
54+
uses: cloudflare/wrangler-action@v3
5855
with:
59-
artifact_name: out
56+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
57+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
58+
command: pages deploy ./artifact --project-name=blog

.github/workflows/pr-preview.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#################### 🚧 WARNING: READ THIS BEFORE USING THIS FILE 🚧 ####################
2+
#
3+
#
4+
#
5+
# IF YOU DON'T KNOW WHAT YOU'RE DOING, YOU CAN EASILY LEAK SECRETS BY USING A
6+
# `pull_request_target` WORKFLOW INSTEAD OF `pull_request`! SERIOUSLY, DO NOT
7+
# BLINDLY COPY AND PASTE THIS FILE WITHOUT UNDERSTANDING THE FULL IMPLICATIONS
8+
# OF WHAT YOU'RE DOING! WE HAVE TESTED THIS FOR OUR OWN USE CASES, WHICH ARE
9+
# NOT NECESSARILY THE SAME AS YOURS! WHILE WE AREN'T EXPOSING ANY OF OUR SECRETS,
10+
# ONE COULD EASILY DO SO BY MODIFYING OR ADDING A STEP TO THIS WORKFLOW!
11+
#
12+
#
13+
#
14+
#################### 🚧 WARNING: READ THIS BEFORE USING THIS FILE 🚧 ####################
15+
16+
name: Docs - Preview Deployment
17+
on:
18+
pull_request_target:
19+
types:
20+
- opened
21+
- edited
22+
- closed
23+
24+
# cancel in-progress runs on new commits to same PR (github.event.number)
25+
concurrency:
26+
group: ${{ github.workflow }}-${{ github.event.number || github.sha }}
27+
cancel-in-progress: true
28+
29+
jobs:
30+
deploy-preview:
31+
if: ${{ github.event.action != 'closed' }}
32+
permissions:
33+
contents: read
34+
pull-requests: write
35+
deployments: write
36+
runs-on: ubuntu-latest
37+
name: Deploy Preview to Cloudflare Pages
38+
env:
39+
BRANCH_NAME: preview-${{ github.head_ref }}
40+
ACTION_RUN: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}
41+
steps:
42+
- uses: actions/checkout@v3
43+
with:
44+
submodules: "recursive"
45+
ref: ${{ github.event.pull_request.head.ref }}
46+
repository: ${{ github.event.pull_request.head.repo.full_name }}
47+
- name: Declare some variables
48+
shell: bash
49+
run: |
50+
echo "SHA_SHORT=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
51+
52+
- name: Create comment
53+
id: comment
54+
uses: peter-evans/create-or-update-comment@v4
55+
with:
56+
issue-number: ${{ github.event.pull_request.number }}
57+
comment-author: 'github-actions[bot]'
58+
body: |
59+
## ⚡ Cloudflare Pages Deployment
60+
| Name | Status | Preview |
61+
| :--- | :----- | :------ |
62+
| ${{env.BRANCH_NAME}} | 🔨 Building ([Logs](${env.ACTION_RUN})) | waiting... |
63+
64+
# Build Rust Page
65+
- uses: dtolnay/rust-toolchain@stable
66+
- uses: Swatinem/rust-cache@v2
67+
- name: Build
68+
run: npm i && npx tailwindcss -i ./input.css -o ./out/blog/output.css && RUST_BACKTRACE=1 cargo run --release
69+
- name: Generate Previews
70+
run: |
71+
cd preview_generator
72+
cargo run --release -- blog ../articles ../out/blog/articles
73+
cargo run --release -- this_week ../esta_semana_en_rust/ ../out/blog/articles
74+
75+
- name: Deploy
76+
id: deploy
77+
uses: cloudflare/wrangler-action@v3
78+
with:
79+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
80+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
81+
command: pages deploy ./dist --project-name=blog --branch="${ env.BRANCH_NAME }"
82+
83+
- name: Create comment
84+
uses: peter-evans/create-or-update-comment@v4
85+
with:
86+
issue-number: ${{ github.event.pull_request.number }}
87+
comment-id: ${{ steps.comment.outputs.comment-id }}
88+
edit-mode: replace
89+
body: |
90+
## ⚡ Cloudflare Pages Deployment
91+
| Name | Status | Preview |
92+
| :--- | :----- | :------ |
93+
| ${{env.BRANCH_NAME}} | ✅ Ready ([Logs](${env.ACTION_RUN})) | [${{env.SHA_SHORT}}](${{ steps.deploy.outputs.deployment-url }}) |
94+
95+
# remove-preview:
96+
# if: ${{ github.event.action == "closed" }}
97+
# permissions:
98+
# contents: read
99+
# pull-requests: write
100+
# deployments: write
101+
# runs-on: ubuntu-latest
102+
# name: Remove Preview of Cloudflare Pages
103+
# steps:
104+
# - uses: actions/checkout@v3
105+
# with:
106+
# submodules: "recursive"
107+
# ref: ${{ github.event.pull_request.head.ref }}
108+
# repository: ${{ github.event.pull_request.head.repo.full_name }}
109+
110+
# - name: Deploy
111+
# id: deploy
112+
# uses: cloudflare/wrangler-action@v3
113+
# with:
114+
# apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
115+
# accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
116+
# command: pages --project-name=homepage --branch="${ env.BRANCH_NAME }"
117+
118+
# - name: Create comment
119+
# uses: peter-evans/create-or-update-comment@v4
120+
# with:
121+
# issue-number: ${{ github.event.pull_request.number }}
122+
# comment-author: 'github-actions[bot]'
123+
# body: |
124+
# ## ⚡ Removing Cloudflare Pages Preview
125+
# | Name | Status |
126+
# | :--- | :----- |
127+
# | ${{env.BRANCH_NAME}} | ✅ Removed |

0 commit comments

Comments
 (0)