|
| 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 | + paths: |
| 24 | + - "**/**/**.rs" |
| 25 | + - "**/**/**.toml" |
| 26 | + - "**/**/**.css" |
| 27 | + - "**.config.js" |
| 28 | + - package.json |
| 29 | + - Cargo.toml |
| 30 | + |
| 31 | +# cancel in-progress runs on new commits to same PR (github.event.number) |
| 32 | +concurrency: |
| 33 | + group: ${{ github.workflow }}-${{ github.event.number || github.sha }} |
| 34 | + cancel-in-progress: true |
| 35 | + |
| 36 | +jobs: |
| 37 | + deploy-preview: |
| 38 | + if: ${{ github.event.action != "closed" }} |
| 39 | + permissions: |
| 40 | + contents: read |
| 41 | + pull-requests: write |
| 42 | + deployments: write |
| 43 | + runs-on: ubuntu-latest |
| 44 | + name: Deploy Preview to Cloudflare Pages |
| 45 | + env: |
| 46 | + BRANCH_NAME: preview-${{ github.head_ref }} |
| 47 | + ACTION_RUN: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}} |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v3 |
| 50 | + with: |
| 51 | + submodules: "recursive" |
| 52 | + ref: ${{ github.event.pull_request.head.ref }} |
| 53 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 54 | + - name: Declare some variables |
| 55 | + shell: bash |
| 56 | + run: | |
| 57 | + echo "SHA_SHORT=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV" |
| 58 | +
|
| 59 | + - name: Create comment |
| 60 | + id: comment |
| 61 | + uses: peter-evans/create-or-update-comment@v4 |
| 62 | + with: |
| 63 | + issue-number: ${{ github.event.pull_request.number }} |
| 64 | + comment-author: 'github-actions[bot]' |
| 65 | + body: | |
| 66 | + ## ⚡ Cloudflare Pages Deployment |
| 67 | + | Name | Status | Preview | |
| 68 | + | :--- | :----- | :------ | |
| 69 | + | ${{BRANCH_NAME}} | 🔨 Building ([Logs](${env.ACTION_RUN})) | waiting... | |
| 70 | +
|
| 71 | + # Build Rust Page |
| 72 | + - uses: actions-rs/toolchain@v1 |
| 73 | + with: |
| 74 | + profile: minimal |
| 75 | + toolchain: nightly-2024-02-12 |
| 76 | + target: wasm32-unknown-unknown |
| 77 | + override: true |
| 78 | + |
| 79 | + - uses: Swatinem/rust-cache@v2 |
| 80 | + - uses: davidB/rust-cargo-make@v1 |
| 81 | + |
| 82 | + - name: Pre Build |
| 83 | + run: | |
| 84 | + npm i |
| 85 | + - name: Build |
| 86 | + run: cargo make build |
| 87 | + |
| 88 | + - name: Deploy |
| 89 | + id: deploy |
| 90 | + uses: cloudflare/wrangler-action@v3 |
| 91 | + with: |
| 92 | + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 93 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 94 | + command: pages deploy ./dist --project-name=homepage --branch="${ env.BRANCH_NAME }" |
| 95 | + |
| 96 | + - name: Create comment |
| 97 | + id: comment |
| 98 | + uses: peter-evans/create-or-update-comment@v4 |
| 99 | + with: |
| 100 | + issue-number: ${{ github.event.pull_request.number }} |
| 101 | + comment-id: ${{ steps.comment.outputs.comment-id }} |
| 102 | + edit-mode: replace |
| 103 | + body: | |
| 104 | + ## ⚡ Cloudflare Pages Deployment |
| 105 | + | Name | Status | Preview | |
| 106 | + | :--- | :----- | :------ | |
| 107 | + | ${{BRANCH_NAME}} | ✅ Ready ([Logs](${env.ACTION_RUN})) | [${{env.SHA_SHORT}}](${{ steps.deploy.outputs.deployment-url }}) | |
| 108 | +
|
| 109 | + # remove-preview: |
| 110 | + # if: ${{ github.event.action == "closed" }} |
| 111 | + # permissions: |
| 112 | + # contents: read |
| 113 | + # pull-requests: write |
| 114 | + # deployments: write |
| 115 | + # runs-on: ubuntu-latest |
| 116 | + # name: Remove Preview of Cloudflare Pages |
| 117 | + # steps: |
| 118 | + # - uses: actions/checkout@v3 |
| 119 | + # with: |
| 120 | + # submodules: "recursive" |
| 121 | + # ref: ${{ github.event.pull_request.head.ref }} |
| 122 | + # repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 123 | + |
| 124 | + # - name: Deploy |
| 125 | + # id: deploy |
| 126 | + # uses: cloudflare/wrangler-action@v3 |
| 127 | + # with: |
| 128 | + # apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 129 | + # accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 130 | + # command: pages --project-name=homepage --branch="${ env.BRANCH_NAME }" |
| 131 | + |
| 132 | + # - name: Create comment |
| 133 | + # id: comment |
| 134 | + # uses: peter-evans/create-or-update-comment@v4 |
| 135 | + # with: |
| 136 | + # issue-number: ${{ github.event.pull_request.number }} |
| 137 | + # comment-author: 'github-actions[bot]' |
| 138 | + # body: | |
| 139 | + # ## ⚡ Removing Cloudflare Pages Preview |
| 140 | + # | Name | Status | |
| 141 | + # | :--- | :----- | |
| 142 | + # | ${{BRANCH_NAME}} | ✅ Removed | |
0 commit comments