Repository navigation
99 lines (93 loc) · 3.36 KB
/
Copy pathjson-diff.yml
File metadata and controls
99 lines (93 loc) · 3.36 KB
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
name: JSON diff
on: pull_request_target
permissions:
contents: read
pull-requests: write
issues: write
jobs:
json-diff:
runs-on: ubuntu-latest
steps:
- name: Checkout base version
uses: actions/checkout@v7
with:
fetch-depth: 0
path: old
- name: Check whether a map is available
id: map-available
run: |
if [ -s old/Map/map ]; then
echo "available=true" >> "$GITHUB_OUTPUT"
else
echo "available=false" >> "$GITHUB_OUTPUT"
echo "No map is available in the repository template; skipping the JSON diff."
fi
- name: Checkout base again for PR overlay
if: steps.map-available.outputs.available == 'true'
uses: actions/checkout@v7
with:
fetch-depth: 0
path: current
- name: Fetch PR changes into current
if: steps.map-available.outputs.available == 'true'
working-directory: current
run: |
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-head
git checkout pr-head
- uses: actions/setup-node@v7.0.0
if: steps.map-available.outputs.available == 'true'
- name: Install dependencies
if: steps.map-available.outputs.available == 'true'
run: |
sudo apt-get install jq diffutils
- name: Generate json map files for diffing
if: steps.map-available.outputs.available == 'true'
run: |
pushd old/
yarn install --frozen-lockfile
node ./map-utilities/generate-map.mjs
node ./map-utilities/generate-map.mjs --base-dir ../current
popd
- name: get JSON diff
if: steps.map-available.outputs.available == 'true'
run: |
echo '## Textual map diff' > output.txt
echo '<details>' >> output.txt
echo '<summary>Open to see the diff for commit ${{ github.event.pull_request.head.sha }}</summary>' >> output.txt
echo '' >> output.txt
echo '```diff' >> output.txt
./old/map-utilities/create-diff.sh >> output.txt
echo '```' >> output.txt
echo '' >> output.txt
echo '</details>' >> output.txt
- name: Find Comment
if: steps.map-available.outputs.available == 'true'
uses: peter-evans/find-comment@v4
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Textual map diff
- name: Create or update comment
if: steps.map-available.outputs.available == 'true'
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const commentBody = fs.readFileSync('output.txt', 'utf8');
const commentId = "${{ steps.fc.outputs.comment-id }}";
if(commentId){
github.rest.issues.updateComment({
comment_id: commentId,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})
}