Skip to content

Separate JS and CSS diff, and upload diffs as artifacts #99

Separate JS and CSS diff, and upload diffs as artifacts

Separate JS and CSS diff, and upload diffs as artifacts #99

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: |
# Using `origin/$GITHUB_BASE_REF` to avoid actually checking out the branch
# as all we need is to let Git diff the two references
bin/dist-diff.sh origin/$GITHUB_BASE_REF $GITHUB_WORKSPACE
- name: Save distribution diffs
uses: actions/upload-artifact@v3
with:
name: Dist diff
path: dist*.diff
if-no-files-found: ignore
- name: Add comment to PR
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs').promises
const diff = await fs.readFile(
process.env.GITHUB_WORKSPACE + '/dist.diff', 'utf8'
)
const commentText = '## Changes to dist\n' +
'```diff\n' +
diff +
'\n```'
github.rest.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentText
})