From f03e65c126ce55ed176dc7315a01a72b5c67a7ad Mon Sep 17 00:00:00 2001 From: Piotr Rogowski Date: Fri, 25 Aug 2023 13:20:54 +0200 Subject: [PATCH] Add Comment on PR to preview --- .github/workflows/deploy-preview.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 9b79eba..6822d72 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -42,6 +42,7 @@ jobs: - run: unzip build.zip -d build - name: Deploy preview to Cloudflare Pages + id: deploy uses: cloudflare/pages-action@v1 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} @@ -50,3 +51,21 @@ jobs: directory: build gitHubToken: ${{ secrets.GITHUB_TOKEN }} # GitHub Deployments wranglerVersion: '3' + + - name: 'Comment on PR' + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const fs = require('fs'); + try { + const issue_number = Number(fs.readFileSync('./build/PR_NR')); + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue_number, + body: "Preview URL: ${{ steps.deploy.outputs.alias }}" + }); + } catch (err) { + console.log(err); + }