Skip to content

Add generic comment on PR script #88

Add generic comment on PR script

Add generic comment on PR script #88

name: Diff changes to dist
on:
pull_request:
paths: ['dist/**']
permissions:
pull-requests: write
jobs:
generate-diff:
name: Generate Diff
runs-on: ubuntu-latest
# Abort if run from a fork, as token won't have write access to post comment
if: github.event.pull_request.head.repo.full_name == github.repository
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Need to also checkout the base branch to compare
- name: Setup Node.js
uses: actions/setup-node@v3
with:
cache: npm
node-version-file: .nvmrc
- name: Set up diff drivers
run: |
npm install -g js-beautify
git config diff.minjs.textconv js-beautify
git config diff.mincss.textconv js-beautify
- name: Generate diff
id: diff
run: |
git diff -M05 origin/$GITHUB_BASE_REF -- dist \
> $GITHUB_WORKSPACE/dist.diff
- name: Add comment to PR
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs').promises
const { commentOnPr } = await import(
`${process.env.GITHUB_WORKSPACE}/shared/stats/comment.mjs`
)
const diff = await fs.readFile(
process.env.GITHUB_WORKSPACE + '/dist.diff', 'utf8'
)
const commentText = '## Changes to dist\n' +
'```diff\n' +
diff +
'\n```'
await commentOnPr({github,context}, 'Diff release', commentText)