diff --git a/.github/workflows/reusable-build-and-review-pr.yml b/.github/workflows/reusable-build-and-review-pr.yml index 9ee0580..b38de34 100644 --- a/.github/workflows/reusable-build-and-review-pr.yml +++ b/.github/workflows/reusable-build-and-review-pr.yml @@ -246,3 +246,46 @@ jobs: .addRaw(instructionsWithLinks) .write(); core.setFailed(instructions); + + # ---------------------------------------------------- + # Add comment if Contributing Guidelines are satisfied + # ---------------------------------------------------- + - name: Add comment if contributing guidelines are satisfied + if: env.HAS_CODE_CHANGES == 'true' && env.NEEDS_BUILD_COMMIT == 'false' && env.NEEDS_README_COMMIT == 'false' + uses: actions/github-script@v7 + with: + script: | + + // Setup vars for the script to use + const hasBuildStep = ${{ env.HAS_BUILD_STEP }}; + + const contribId = '${{ inputs.readme-contribution-id }}'; + const contributionLink = `https://github.com/${{ github.repository }}${contribId}`; + const contributingTitle = contribId.replace('#', '').split('-').map(w => { return w.slice(0, 1).toUpperCase() + w.slice(1) }).join(' '); + + const exampleId = '${{ inputs.readme-examples-id }}'; + const readmeLink = `${{ github.event.pull_request.head.repo.html_url }}/blob/${{ github.event.pull_request.head.ref }}/${{ env.README }}`; + const readmeExampleLink = `${readmeLink}${exampleId}`; + const readmeExampleTitle = exampleId.replace('#', '').split('-').map(w => { return w.slice(0, 1).toUpperCase() + w.slice(1) }).join(' '); + + // Construct the prComment + let prComment = `The action's [${contributingTitle} Guidelines](${contributionLink}) have been met: + - The action's version in the [${readmeExampleTitle}](${readmeExampleLink}) section of [${{ env.README }}](${readmeLink}) has been updated to \`@${{ env.NEXT_VERSION }}\`` + + if (hasBuildStep){ + prComment += ` + - The action has been recompiled (if needed) by running the build command from the root of the repository`; + } + + // Comment on PR for branches. A fork's GH_TOKEN only has 'read' permission on all scopes so a comment cannot be made. + if (!${{ env.IS_FORK }}) { + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: prComment + }) + } + + // Add workflow summary + core.summary.addRaw(prComment).write();