From 8da65a0fdf4fc9e61f38961a453975c238e32b53 Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Fri, 4 Oct 2024 20:18:09 +0100 Subject: [PATCH] improve speed of PR builds + remove duplicated comments (#1090) Co-authored-by: Shane Osbourne --- .github/workflows/build-pr.yml | 47 ++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 455ee42d8..decebab70 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -9,20 +9,25 @@ permissions: write-all jobs: build: if: github.event.action != 'closed' - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Set up Node.js - uses: actions/setup-node@v3 + - name: Use Node.js 20 + uses: actions/setup-node@v1 + with: + node-version: 20.x + - uses: actions/cache@v4 with: - node-version: '20' - cache: 'npm' + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- - name: Install dependencies - run: npm install + run: npm ci --verbose - name: Run build run: npm run build @@ -42,8 +47,18 @@ jobs: echo "BRANCH_NAME=pr-releases/pr-${PR_NUMBER}" >> $GITHUB_ENV echo "COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV - - name: Post comment on PR + - name: Find Previous Comment + uses: peter-evans/find-comment@v2 + id: find_comment + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: 'Temporary Branch Update' + direction: last + + - name: Create Comment Body uses: actions/github-script@v7 + id: create_body with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | @@ -61,15 +76,19 @@ jobs: - **Branch Name**: [${branchName}](${branchUrl}) - **Commit Hash**: [${commitHash}](${commitUrl}) - **Install Command**: \`npm i github:duckduckgo/content-scope-scripts#${commitHash}\` - + Please use the above install command to update to the latest version. - `; + `; + core.setOutput('comment_body', commentBody); + core.setOutput('pr_number', prNumber); - await github.rest.issues.createComment({ - ...context.repo, - issue_number: prNumber, - body: commentBody - }); + - name: Create, or Update the Comment + uses: peter-evans/create-or-update-comment@v2 + with: + issue-number: ${{ github.event.pull_request.number }} + comment-id: ${{ steps.find_comment.outputs.comment-id }} + body: ${{ steps.create_body.outputs.comment_body }} + edit-mode: replace clean_up: if: github.event.action == 'closed'