-
Notifications
You must be signed in to change notification settings - Fork 334
84 lines (71 loc) · 2.83 KB
/
diff-change-to-package.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Diff changes to npm package
on:
workflow_call:
workflow_dispatch:
permissions:
pull-requests: write
jobs:
generate-diff:
name: Generate diff
runs-on: ubuntu-22.04
# Skip workflows other than PRs such as merges to `main` but
# also when token write permissions are unavailable on forks
if: ${{ github.event.pull_request && !github.event.pull_request.head.repo.fork }}
steps:
- uses: actions/checkout@v4.2.2
with:
fetch-depth: 0 # Need to also checkout the base branch to compare
- name: Install dependencies
uses: ./.github/workflows/actions/install-node
- name: Set up diff drivers
run: |
npm install -g js-beautify
git config diff.minjs.textconv "js-beautify --editorconfig --type js"
git config diff.mincss.textconv "js-beautify --editorconfig --type css"
- name: Generate diff
run: |
git config user.name github-actions
git config user.email github-actions@github.com
bin/package-diff.sh $GITHUB_BASE_REF $GITHUB_WORKSPACE
- name: Save npm package diffs
uses: actions/upload-artifact@v4.5.0
with:
name: Package diff
path: .cache/diff/package/*.diff
if-no-files-found: ignore
- name: Add comment to PR
uses: actions/github-script@v7.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { commentDiffs } = await import('${{ github.workspace }}/.github/workflows/scripts/comments.mjs')
// PR information
const issueNumber = ${{ github.event.pull_request.number }}
const commit = '${{ github.event.pull_request.head.sha }}'
const diffs = [
{
path: '${{ github.workspace }}/.cache/diff/package/js.diff',
titleText: 'JavaScript changes to npm package',
markerText: 'package/js.diff',
skipEmpty: true
},
{
path: '${{ github.workspace }}/.cache/diff/package/css.diff',
titleText: 'Stylesheets changes to npm package',
markerText: 'package/css.diff',
skipEmpty: true
},
{
path: '${{ github.workspace }}/.cache/diff/package/html.diff',
titleText: 'Rendered HTML changes to npm package',
markerText: 'package/html.diff',
skipEmpty: true
},
{
path: '${{ github.workspace }}/.cache/diff/package/other.diff',
titleText: 'Other changes to npm package',
markerText: 'package/other.diff',
skipEmpty: true
}
]
await commentDiffs({ github, context, commit }, issueNumber, diffs)