-
Notifications
You must be signed in to change notification settings - Fork 1
100 lines (91 loc) · 3.05 KB
/
diff.yml
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Diff
on:
pull_request:
branches:
- main
paths:
- 'src/**'
- 'package.json'
- '!package-lock.json'
- '!yarn.lock'
jobs:
changed-files:
name: Changed Files
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
steps:
- name: Checkout Default Branch
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
- name: Get Changed Files
id: changed-files
uses: tj-actions/changed-files@bab30c2299617f6615ec02a68b9a40d10bd21366 # v45
with:
files: |
'src/**'
package.json
files_ignore: |
package-lock.json
yarn.lock
matrix: true
- name: List All Changed Files
run: echo "Changed files = ${{ steps.changed-files.outputs.all_changed_and_modified_files }}"
diff:
name: Show Diff
runs-on: ubuntu-latest
needs:
- changed-files
strategy:
matrix:
paths: ${{ fromJson(needs.changed-files.outputs.matrix) }}
steps:
- name: Checkout Default Branch
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
token: "${{ secrets.GITHUB_TOKEN }}"
# ref: "${{ github.event.repository.default_branch }}"
ref: "main"
path: default
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
token: "${{ secrets.GITHUB_TOKEN }}"
path: pull
# The diff command will always return an exit code of 1 if differences are found.
# the "|| :" forces it to return a 0 allowing the step to continue without failure
- name: Generate Diff
id: diff
continue-on-error: true
run: |
diff default/${{matrix.paths}} pull/${{matrix.paths}} > diff.patch || :
echo "diff<<EOF" >> $GITHUB_OUTPUT
cat diff.patch >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "### Diff" >> $GITHUB_STEP_SUMMARY
echo '```diff' >> $GITHUB_STEP_SUMMARY
cat diff.patch >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- if: ${{ steps.diff.outputs.diff != '' }}
name: Add comment
uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
message-id: "${{ github.event.pull_request.number }}/${{ matrix.paths }}"
message-failure: Diff was not successful
message: |
```diff
${{ steps.diff.outputs.diff }}
```
# Summarize matrix https://gh.neting.ccmunity/t/status-check-for-a-matrix-jobs/127354/7
diff-success:
if: ${{ always() }}
needs:
- diff
name: Diff Successful
runs-on: ubuntu-latest
steps:
- if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
name: Check matrix status
run: exit 1