From 2f941789cc7094d56f480dc441b908857eb6fdc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 11:10:55 +0200 Subject: [PATCH 01/38] Add CF publish --- .github/workflows/deploy.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a467d52..639cbe5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -37,4 +37,17 @@ jobs: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v3 \ No newline at end of file + uses: actions/deploy-pages@v3 + + - name: Publish + uses: cloudflare/pages-action@v1 + env: + API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + GITHUB_TOKEN: ${{ secrets.TOKEN }} + with: + apiToken: ${{ env.API_TOKEN }} + accountId: ${{ env.ACCOUNT_ID }} + projectName: probe-rs + directory: 'target' + gitHubToken: ${{ env.GITHUB_TOKEN }} \ No newline at end of file From 9490fa3e5b4aa0ad592d273e6698ea8d8e9efd29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 11:29:41 +0200 Subject: [PATCH 02/38] Deploy all branches --- .github/workflows/deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 639cbe5..e1a2b7f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,7 +2,6 @@ name: Publish on GitHub Pages on: push: - branches: [ master ] permissions: contents: read From 289f14d1d48030298aeec80795d90c21b744cf76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 11:34:03 +0200 Subject: [PATCH 03/38] Fix repo name --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e1a2b7f..08b6f49 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -47,6 +47,6 @@ jobs: with: apiToken: ${{ env.API_TOKEN }} accountId: ${{ env.ACCOUNT_ID }} - projectName: probe-rs + projectName: ${{ github.event.repository.name }} directory: 'target' gitHubToken: ${{ env.GITHUB_TOKEN }} \ No newline at end of file From 786249739de74a0bd364a6a292941cf501d6f2e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 12:23:42 +0200 Subject: [PATCH 04/38] Make preview workflow separate and test posting on the PR --- .github/workflows/deploy-preview.yml | 53 ++++++++++++++++++++++++++++ .github/workflows/deploy.yml | 14 +------- 2 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/deploy-preview.yml diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml new file mode 100644 index 0000000..7fc9362 --- /dev/null +++ b/.github/workflows/deploy-preview.yml @@ -0,0 +1,53 @@ +name: Publish on GitHub Pages + +on: + pull_request: + +permissions: + contents: read + pages: write + id-token: write + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Clone repository + uses: actions/checkout@v4 + + - name: Setup Deno environment + uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + + - name: Build site + run: deno task build + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} + + - name: Deploy to CF Pages + id: deploy-preview + uses: cloudflare/pages-action@v1 + env: + API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + GITHUB_TOKEN: ${{ secrets.TOKEN }} + with: + apiToken: ${{ env.API_TOKEN }} + accountId: ${{ env.ACCOUNT_ID }} + projectName: ${{ github.event.repository.name }} + directory: 'target' + gitHubToken: ${{ env.GITHUB_TOKEN }} + + - name: Report preview environment in PR + uses: actions/github-script@v6 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '${{ steps.deploy-preview.outputs.alias }}' + }) + \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 08b6f49..46f6029 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,6 +2,7 @@ name: Publish on GitHub Pages on: push: + branches: [ 'master' ] permissions: contents: read @@ -37,16 +38,3 @@ jobs: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v3 - - - name: Publish - uses: cloudflare/pages-action@v1 - env: - API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - GITHUB_TOKEN: ${{ secrets.TOKEN }} - with: - apiToken: ${{ env.API_TOKEN }} - accountId: ${{ env.ACCOUNT_ID }} - projectName: ${{ github.event.repository.name }} - directory: 'target' - gitHubToken: ${{ env.GITHUB_TOKEN }} \ No newline at end of file From 6c68eb0f258063f79feaab619e97b8741e332687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 12:32:36 +0200 Subject: [PATCH 05/38] Fix permissions --- .github/workflows/deploy-preview.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 7fc9362..649e641 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -1,4 +1,4 @@ -name: Publish on GitHub Pages +name: Publish preview on CF Pages on: pull_request: @@ -7,6 +7,7 @@ permissions: contents: read pages: write id-token: write + issues: write jobs: build: From 77ac17d4fa2c28dc1a144e370430082b1057e058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 12:35:22 +0200 Subject: [PATCH 06/38] Fix permissions --- .github/workflows/deploy-preview.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 649e641..67a4dfb 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -8,6 +8,7 @@ permissions: pages: write id-token: write issues: write + pull-requests: write jobs: build: From 400c71d0eb48e6936aeb73870557e6732e5ba697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 12:53:56 +0200 Subject: [PATCH 07/38] Post proper message and use correct branch --- .github/workflows/deploy-preview.yml | 29 ++++++++++++++++++++++++---- .github/workflows/deploy.yml | 2 +- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 67a4dfb..71b94fd 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -11,7 +11,7 @@ permissions: pull-requests: write jobs: - build: + deploy-preview: runs-on: ubuntu-latest steps: @@ -35,21 +35,42 @@ jobs: API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} GITHUB_TOKEN: ${{ secrets.TOKEN }} + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} with: apiToken: ${{ env.API_TOKEN }} accountId: ${{ env.ACCOUNT_ID }} projectName: ${{ github.event.repository.name }} directory: 'target' gitHubToken: ${{ env.GITHUB_TOKEN }} + branch: ${{ env.BRANCH_NAME }} - name: Report preview environment in PR uses: actions/github-script@v6 with: + github-token: ${{ secrets.GH_PAT }} script: | - github.rest.issues.createComment({ + let comments = octokit.rest.issues.listComments({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: '${{ steps.deploy-preview.outputs.alias }}' - }) + }); + + let previousComment = comments.find((i) => i.login = "probe-rs-bot"); + + if(!previousComment) { + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '#[Preview](${{ steps.deploy-preview.outputs.alias }}') + }) + } else { + github.rest.issues.updateComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: previousComment.id, + body: '#[Preview](${{ steps.deploy-preview.outputs.alias }}') + }) + } \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 46f6029..4c0f178 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,7 +10,7 @@ permissions: id-token: write jobs: - build: + deploy: runs-on: ubuntu-latest steps: From 05261ac98553c33e98cae80a374bd4f5afdaf39c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 12:56:02 +0200 Subject: [PATCH 08/38] Fix script --- .github/workflows/deploy-preview.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 71b94fd..098bbb1 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -55,14 +55,14 @@ jobs: repo: context.repo.repo, }); - let previousComment = comments.find((i) => i.login = "probe-rs-bot"); + let previousComment = comments.find((i) => i.login === "probe-rs-bot"); if(!previousComment) { github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: '#[Preview](${{ steps.deploy-preview.outputs.alias }}') + body: '#[Preview](${{ steps.deploy-preview.outputs.alias }})' }) } else { github.rest.issues.updateComment({ @@ -70,7 +70,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, comment_id: previousComment.id, - body: '#[Preview](${{ steps.deploy-preview.outputs.alias }}') + body: '#[Preview](${{ steps.deploy-preview.outputs.alias }})' }) } \ No newline at end of file From 646e6bb60768cc04b6fdd79ea0b7e7f7f831d5a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 12:57:42 +0200 Subject: [PATCH 09/38] Fix script --- .github/workflows/deploy-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 098bbb1..56d28f9 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -49,7 +49,7 @@ jobs: with: github-token: ${{ secrets.GH_PAT }} script: | - let comments = octokit.rest.issues.listComments({ + let comments = github.rest.issues.listComments({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, From d7392af7a77e492b3eb414595dfc8106fea12282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 13:07:45 +0200 Subject: [PATCH 10/38] Fix script --- .github/workflows/deploy-preview.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 56d28f9..e3d961c 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -49,7 +49,7 @@ jobs: with: github-token: ${{ secrets.GH_PAT }} script: | - let comments = github.rest.issues.listComments({ + let comments = await github.rest.issues.listComments({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, @@ -58,14 +58,14 @@ jobs: let previousComment = comments.find((i) => i.login === "probe-rs-bot"); if(!previousComment) { - github.rest.issues.createComment({ + await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: '#[Preview](${{ steps.deploy-preview.outputs.alias }})' }) } else { - github.rest.issues.updateComment({ + await github.rest.issues.updateComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, From e8eebd36aa7d74af16441fdfe18c0c335a8c7f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 13:09:17 +0200 Subject: [PATCH 11/38] Fix script --- .github/workflows/deploy-preview.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index e3d961c..d403cf2 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -54,6 +54,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, }); + console.log(comments); let previousComment = comments.find((i) => i.login === "probe-rs-bot"); From f4bbe9f24b83f4134c29a2f331d68cdfd8dd8fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 13:20:53 +0200 Subject: [PATCH 12/38] Fix script --- .github/workflows/deploy-preview.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index d403cf2..82e206d 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -54,9 +54,9 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, }); - console.log(comments); + console.log(comments.data[0].user); - let previousComment = comments.find((i) => i.login === "probe-rs-bot"); + let previousComment = comments.data.find((i) => i.user.login === "probe-rs-bot"); if(!previousComment) { await github.rest.issues.createComment({ From 2426b9ac7176df71a06274b9cc48eb3b83dfc389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 13:25:17 +0200 Subject: [PATCH 13/38] Fix heading in preview comment --- .github/workflows/deploy-preview.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 82e206d..7607f94 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -54,7 +54,6 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, }); - console.log(comments.data[0].user); let previousComment = comments.data.find((i) => i.user.login === "probe-rs-bot"); @@ -63,7 +62,7 @@ jobs: issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: '#[Preview](${{ steps.deploy-preview.outputs.alias }})' + body: '# [Preview](${{ steps.deploy-preview.outputs.alias }})' }) } else { await github.rest.issues.updateComment({ @@ -71,7 +70,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, comment_id: previousComment.id, - body: '#[Preview](${{ steps.deploy-preview.outputs.alias }})' + body: '# [Preview](${{ steps.deploy-preview.outputs.alias }})' }) } \ No newline at end of file From 0efee7926100c960313f317be2d86cdbe08ccbeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 13:26:44 +0200 Subject: [PATCH 14/38] Only do one build on PR pushes --- .github/workflows/build.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 82cc7a6..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Build pages - -on: - pull_request: - -permissions: - contents: read - pages: write - id-token: write - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Clone repository - uses: actions/checkout@v4 - - - name: Setup Deno environment - uses: denoland/setup-deno@v1 - with: - deno-version: v1.x - - - name: Build site - run: deno task build - env: - GITHUB_TOKEN: ${{ secrets.TOKEN }} From 3d19693be00f0e40ce938fef96d9f7415e903ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 13:29:18 +0200 Subject: [PATCH 15/38] Debug --- .github/workflows/deploy-preview.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 7607f94..67d9d11 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -57,6 +57,8 @@ jobs: let previousComment = comments.data.find((i) => i.user.login === "probe-rs-bot"); + console.log(${{ steps.deploy-preview.outputs }}) + if(!previousComment) { await github.rest.issues.createComment({ issue_number: context.issue.number, From 4e0c5430f51db57d8426a3ecdb6d0bb01a03e7c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 13:31:53 +0200 Subject: [PATCH 16/38] Debug --- .github/workflows/deploy-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 67d9d11..5702c43 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -57,7 +57,7 @@ jobs: let previousComment = comments.data.find((i) => i.user.login === "probe-rs-bot"); - console.log(${{ steps.deploy-preview.outputs }}) + console.log(JSON.stringify(${{ steps.deploy-preview.outputs }})) if(!previousComment) { await github.rest.issues.createComment({ From 6931a4259dee7ded254d2945df05744adf23b01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 13:38:06 +0200 Subject: [PATCH 17/38] Debug --- .github/workflows/deploy-preview.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 5702c43..147d1a0 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -57,7 +57,10 @@ jobs: let previousComment = comments.data.find((i) => i.user.login === "probe-rs-bot"); - console.log(JSON.stringify(${{ steps.deploy-preview.outputs }})) + console.log(${{ steps.deploy-preview.outputs.id }}); + console.log(${{ steps.deploy-preview.outputs.alias }}); + console.log(${{ steps.deploy-preview.outputs.url }}); + console.log(${{ steps.deploy-preview.outputs.environment }}); if(!previousComment) { await github.rest.issues.createComment({ From ce09472bccbb93e34a03d8b5253420bc4eda269e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 13:41:09 +0200 Subject: [PATCH 18/38] Debug --- .github/workflows/deploy-preview.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 147d1a0..c35c58d 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -57,10 +57,10 @@ jobs: let previousComment = comments.data.find((i) => i.user.login === "probe-rs-bot"); - console.log(${{ steps.deploy-preview.outputs.id }}); - console.log(${{ steps.deploy-preview.outputs.alias }}); - console.log(${{ steps.deploy-preview.outputs.url }}); - console.log(${{ steps.deploy-preview.outputs.environment }}); + console.log('${{ steps.deploy-preview.outputs.id }}'); + console.log('${{ steps.deploy-preview.outputs.alias }}'); + console.log('${{ steps.deploy-preview.outputs.url }}'); + console.log('${{ steps.deploy-preview.outputs.environment }}'); if(!previousComment) { await github.rest.issues.createComment({ From 46f0ac3e7ec19c1b95b71312eb5b3d886dde9fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 13:45:05 +0200 Subject: [PATCH 19/38] Remove debug statements --- .github/workflows/deploy-preview.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index c35c58d..7607f94 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -57,11 +57,6 @@ jobs: let previousComment = comments.data.find((i) => i.user.login === "probe-rs-bot"); - console.log('${{ steps.deploy-preview.outputs.id }}'); - console.log('${{ steps.deploy-preview.outputs.alias }}'); - console.log('${{ steps.deploy-preview.outputs.url }}'); - console.log('${{ steps.deploy-preview.outputs.environment }}'); - if(!previousComment) { await github.rest.issues.createComment({ issue_number: context.issue.number, From 7e9263902f13993343718a92360f5bdee7f91fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 16:50:54 +0200 Subject: [PATCH 20/38] Use PAT for CF pages --- .github/workflows/deploy-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 7607f94..5192cf5 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -34,7 +34,7 @@ jobs: env: API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - GITHUB_TOKEN: ${{ secrets.TOKEN }} + GITHUB_TOKEN: ${{ secrets.GH_PAT }} BRANCH_NAME: ${{ github.head_ref || github.ref_name }} with: apiToken: ${{ env.API_TOKEN }} From 1ec25122741ed736dd96fe12eb9104df4053e30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 17:03:33 +0200 Subject: [PATCH 21/38] Make deployments show up --- .github/workflows/deploy.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4c0f178..b922d1b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,6 +13,10 @@ jobs: deploy: runs-on: ubuntu-latest + environment: + name: webpage (Production) + url: https://probe.rs + steps: - name: Clone repository uses: actions/checkout@v4 @@ -38,3 +42,4 @@ jobs: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v3 + From a93c27565f52aa3188b56621f06622706aa0e0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 17:46:18 +0200 Subject: [PATCH 22/38] Check that the PR is from a collaborator or owner or refuse to run the PR --- .github/workflows/deploy-preview.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 5192cf5..d018fca 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -1,7 +1,7 @@ name: Publish preview on CF Pages on: - pull_request: + pull_request_target: permissions: contents: read @@ -18,6 +18,22 @@ jobs: - name: Clone repository uses: actions/checkout@v4 + - name: Modified files + run: | + git fetch origin main:main + git diff --name-only --diff-filter=d main~ main + + - name: Check access + if: ${{ github.event.pull_request.author_association != 'COLLABORATOR' && github.event.pull_request.author_association != 'OWNER' }} + run: | + echo "Event not triggered by a collaborator." + exit 1 + + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Setup Deno environment uses: denoland/setup-deno@v1 with: From f800b190c973a96c15c8984e41f535712bd979e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 18:50:08 +0200 Subject: [PATCH 23/38] Check that workflows were not modified --- .github/workflows/deploy-preview.yml | 33 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index d018fca..31f5e48 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -17,23 +17,28 @@ jobs: steps: - name: Clone repository uses: actions/checkout@v4 - - - name: Modified files - run: | - git fetch origin main:main - git diff --name-only --diff-filter=d main~ main - - - name: Check access - if: ${{ github.event.pull_request.author_association != 'COLLABORATOR' && github.event.pull_request.author_association != 'OWNER' }} - run: | - echo "Event not triggered by a collaborator." - exit 1 - - - name: Checkout code - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} + - name: Check workflow modification permissions + run: | + git diff --name-only HEAD^ HEAD > files.txt + while IFS= read -r file + do + echo "Testing $file" + if [[ $file == .github/* ]]; then + echo "Workflows were modified"; + if [ "${{ github.event.pull_request.author_association }}" != "COLLABORATOR" ] + echo "Modifier is not a collaborator"; + if [ "${{ github.event.pull_request.author_association }}" != "OWNER" ] + echo "Modifier is not an owner"; + echo "Workflows changed by non-collaborator" + exit 1 + fi + fi + fi + done < files.txt + - name: Setup Deno environment uses: denoland/setup-deno@v1 with: From 62f23fbe442bd738f7232f8fbb3d7ee628fb2299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 19:44:21 +0200 Subject: [PATCH 24/38] Fetch newest 2 commits --- .github/workflows/deploy-preview.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 31f5e48..c2cd97c 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -19,6 +19,7 @@ jobs: uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 2 - name: Check workflow modification permissions run: | From 312b90f9b420dc9912bb831cde4164b2bc083cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 19:49:21 +0200 Subject: [PATCH 25/38] Fix bash --- .github/workflows/deploy-preview.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index c2cd97c..190c910 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -29,9 +29,9 @@ jobs: echo "Testing $file" if [[ $file == .github/* ]]; then echo "Workflows were modified"; - if [ "${{ github.event.pull_request.author_association }}" != "COLLABORATOR" ] + if [ "${{ github.event.pull_request.author_association }}" != "COLLABORATOR" ]; then echo "Modifier is not a collaborator"; - if [ "${{ github.event.pull_request.author_association }}" != "OWNER" ] + if [ "${{ github.event.pull_request.author_association }}" != "OWNER" ]; then echo "Modifier is not an owner"; echo "Workflows changed by non-collaborator" exit 1 From c4a612664cc861ee36e5705102f8cd334e787e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 19:54:56 +0200 Subject: [PATCH 26/38] Print author association --- .github/workflows/deploy-preview.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 190c910..1215721 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -29,6 +29,7 @@ jobs: echo "Testing $file" if [[ $file == .github/* ]]; then echo "Workflows were modified"; + echo "${{ github.event.pull_request.author_association }}"; if [ "${{ github.event.pull_request.author_association }}" != "COLLABORATOR" ]; then echo "Modifier is not a collaborator"; if [ "${{ github.event.pull_request.author_association }}" != "OWNER" ]; then From 9413a757705b502147bb379efc5fc17840f3fbf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 19:59:05 +0200 Subject: [PATCH 27/38] Simplify workflow change rules --- .github/workflows/deploy-preview.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 1215721..dbccbcf 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -29,14 +29,9 @@ jobs: echo "Testing $file" if [[ $file == .github/* ]]; then echo "Workflows were modified"; - echo "${{ github.event.pull_request.author_association }}"; - if [ "${{ github.event.pull_request.author_association }}" != "COLLABORATOR" ]; then - echo "Modifier is not a collaborator"; - if [ "${{ github.event.pull_request.author_association }}" != "OWNER" ]; then - echo "Modifier is not an owner"; - echo "Workflows changed by non-collaborator" - exit 1 - fi + if [ "${{ github.event.pull_request.author_association }}" != "MEMBER" ]; then + echo "Workflows changed by someone outside of the probe-rs org" + exit 1 fi fi done < files.txt From 9c7a1be8c1cb0d5002c27a1ce5f8c488f1652e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 20:02:27 +0200 Subject: [PATCH 28/38] Remove author restriction as it is enforced by GH --- .github/workflows/deploy-preview.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index dbccbcf..4c8c57d 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -19,22 +19,6 @@ jobs: uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} - fetch-depth: 2 - - - name: Check workflow modification permissions - run: | - git diff --name-only HEAD^ HEAD > files.txt - while IFS= read -r file - do - echo "Testing $file" - if [[ $file == .github/* ]]; then - echo "Workflows were modified"; - if [ "${{ github.event.pull_request.author_association }}" != "MEMBER" ]; then - echo "Workflows changed by someone outside of the probe-rs org" - exit 1 - fi - fi - done < files.txt - name: Setup Deno environment uses: denoland/setup-deno@v1 From 928037c6c499f6ebb7d81711cdfe4edd98f67699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 20:17:56 +0200 Subject: [PATCH 29/38] Try fix branch name --- .github/workflows/deploy-preview.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 4c8c57d..9ff1e2e 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -44,7 +44,6 @@ jobs: projectName: ${{ github.event.repository.name }} directory: 'target' gitHubToken: ${{ env.GITHUB_TOKEN }} - branch: ${{ env.BRANCH_NAME }} - name: Report preview environment in PR uses: actions/github-script@v6 From 5f13b0a5935d9520b63de2fb9e8209fd8da81618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 20:27:55 +0200 Subject: [PATCH 30/38] Try fix branch name --- .github/workflows/deploy-preview.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 9ff1e2e..74530de 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -44,6 +44,7 @@ jobs: projectName: ${{ github.event.repository.name }} directory: 'target' gitHubToken: ${{ env.GITHUB_TOKEN }} + branch: "master" - name: Report preview environment in PR uses: actions/github-script@v6 From 09b39a0e47fb1d8bcd2642927e8c07776c02cf3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 20:29:45 +0200 Subject: [PATCH 31/38] Try fix branch name --- .github/workflows/deploy-preview.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 74530de..e2ceaf0 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -32,19 +32,17 @@ jobs: - name: Deploy to CF Pages id: deploy-preview - uses: cloudflare/pages-action@v1 + uses: cloudflare/pages-action@master env: API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} GITHUB_TOKEN: ${{ secrets.GH_PAT }} - BRANCH_NAME: ${{ github.head_ref || github.ref_name }} with: apiToken: ${{ env.API_TOKEN }} accountId: ${{ env.ACCOUNT_ID }} projectName: ${{ github.event.repository.name }} directory: 'target' gitHubToken: ${{ env.GITHUB_TOKEN }} - branch: "master" - name: Report preview environment in PR uses: actions/github-script@v6 From 4147849130575ac24b57f6a13bf96d38b4922148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 21:09:53 +0200 Subject: [PATCH 32/38] Try fix branch name --- .github/workflows/deploy-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index e2ceaf0..f5f4542 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -32,7 +32,7 @@ jobs: - name: Deploy to CF Pages id: deploy-preview - uses: cloudflare/pages-action@master + uses: cloudflare/pages-action@main env: API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} From f70344cde7a95288f277a79818ae8b846df15de2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 21:25:24 +0200 Subject: [PATCH 33/38] Use wrangler directly --- .github/workflows/deploy-preview.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index f5f4542..61497a2 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -32,17 +32,16 @@ jobs: - name: Deploy to CF Pages id: deploy-preview - uses: cloudflare/pages-action@main + uses: cloudflare/wrangler-action@v3 env: API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} GITHUB_TOKEN: ${{ secrets.GH_PAT }} + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} with: apiToken: ${{ env.API_TOKEN }} accountId: ${{ env.ACCOUNT_ID }} - projectName: ${{ github.event.repository.name }} - directory: 'target' - gitHubToken: ${{ env.GITHUB_TOKEN }} + command: pages deploy 'target' --project-name=${{ github.event.repository.name }} --branch=${{ BRANCH_NAME }} - name: Report preview environment in PR uses: actions/github-script@v6 From 3f743931ec92d4b20aa744d9d77c7f6e3e364dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 21:28:06 +0200 Subject: [PATCH 34/38] Don't use the GH PAT for CF --- .github/workflows/deploy-preview.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 61497a2..4025c37 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -36,7 +36,6 @@ jobs: env: API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - GITHUB_TOKEN: ${{ secrets.GH_PAT }} BRANCH_NAME: ${{ github.head_ref || github.ref_name }} with: apiToken: ${{ env.API_TOKEN }} From dac76dbc13813426aad51c738819f8539df24002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 21:29:08 +0200 Subject: [PATCH 35/38] Fix CI --- .github/workflows/deploy-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 4025c37..c5ae079 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -40,7 +40,7 @@ jobs: with: apiToken: ${{ env.API_TOKEN }} accountId: ${{ env.ACCOUNT_ID }} - command: pages deploy 'target' --project-name=${{ github.event.repository.name }} --branch=${{ BRANCH_NAME }} + command: pages deploy 'target' --project-name=${{ github.event.repository.name }} --branch=${{ env.BRANCH_NAME }} - name: Report preview environment in PR uses: actions/github-script@v6 From a59d5ca20f5fb0dbaa213ea6de6170c93d41fb15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Sun, 23 Jun 2024 21:30:46 +0200 Subject: [PATCH 36/38] Fix target dir --- .github/workflows/deploy-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index c5ae079..8125a4f 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -40,7 +40,7 @@ jobs: with: apiToken: ${{ env.API_TOKEN }} accountId: ${{ env.ACCOUNT_ID }} - command: pages deploy 'target' --project-name=${{ github.event.repository.name }} --branch=${{ env.BRANCH_NAME }} + command: pages deploy target --project-name=${{ github.event.repository.name }} --branch=${{ env.BRANCH_NAME }} - name: Report preview environment in PR uses: actions/github-script@v6 From 137e849641ad8f57de83bfe06172a7d668c7e5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Mon, 24 Jun 2024 22:22:35 +0200 Subject: [PATCH 37/38] Print correct url --- .github/workflows/deploy-preview.yml | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 8125a4f..c391e53 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -44,6 +44,8 @@ jobs: - name: Report preview environment in PR uses: actions/github-script@v6 + env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} with: github-token: ${{ secrets.GH_PAT }} script: | @@ -55,20 +57,10 @@ jobs: let previousComment = comments.data.find((i) => i.user.login === "probe-rs-bot"); - if(!previousComment) { - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: '# [Preview](${{ steps.deploy-preview.outputs.alias }})' - }) - } else { - await github.rest.issues.updateComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: previousComment.id, - body: '# [Preview](${{ steps.deploy-preview.outputs.alias }})' - }) - } + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '# [Preview](https://${{ env.BRANCH_NAME }}.webpage-5t5.pages.dev/)' + }) \ No newline at end of file From 1ca8993434ea71452c4aa01b590b0866ac38c275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Mon, 24 Jun 2024 23:05:09 +0200 Subject: [PATCH 38/38] Add note about the special checkout --- .github/workflows/deploy-preview.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index c391e53..d1fbcd9 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -1,3 +1,7 @@ +# This workflow always runs from the state on `master`. +# If you want to test changes to the workflow, you need to open a second PR against the branch of the PR with the workflow changes. +# This is a security feature so one cannot meddle with secrets. + name: Publish preview on CF Pages on: