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
+ - synchronize
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
+ - name : Install mdbook
66
+ run : |
67
+ mkdir bin
68
+ curl -sSL https://github.com/RustLangES/mdBook/releases/download/v0.4.36-localization-v0.6/mdbook-v0.4.36-localization-v0.6-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
69
+ curl -sSL https://github.com/catppuccin/mdBook/releases/download/v0.1.1/mdbook-catppuccin-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
70
+ echo "$(pwd)/bin" >> ${GITHUB_PATH}
71
+ - name : Build with mdBook
72
+ run : mdbook build --language es
73
+
74
+ # Deploy
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 ./book --project-name=embedded --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