-
Notifications
You must be signed in to change notification settings - Fork 193
111 lines (93 loc) · 3.44 KB
/
comment-diffs.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
101
102
103
104
105
106
107
108
109
110
111
name: Comment diffs
on:
workflow_dispatch:
pull_request:
branches:
- main
paths:
- '.github/workflows/comment-diffs.yml'
- 'packages/create-react-native-library/**'
- '!**.md'
jobs:
comment-diffs:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup
uses: ./.github/actions/setup
- name: Build crnl
run: |
yarn workspace create-react-native-library prepare
- name: Create library
run: |
./packages/create-react-native-library/bin/create-react-native-library new-version \
--slug @bob/react-native-test \
--description test \
--author-name test \
--author-email test@test \
--author-url https://test.test \
--repo-url https://test.test \
--type module-mixed \
--languages java-objc \
--no-example \
--no-local
- name: Store the commit hash
id: head_hash
run: echo "HEAD_HASH=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Fetch main
run: git fetch origin main
- name: Checkout main
run: git checkout origin/main
# Removed this step for the sake of testing
# - name: Setup again # Add a check here to setup again if deps changed
# uses: ./.github/actions/setup
- name: Remove old build and build again
run: |
rm -rf ./packages/create-react-native-library/lib
yarn workspace create-react-native-library prepare
- name: Create library again
run: |
./packages/create-react-native-library/bin/create-react-native-library old-version \
--slug @bob/react-native-test \
--description test \
--author-name test \
--author-email test@test \
--author-url https://test.test \
--repo-url https://test.test \
--type module-mixed \
--languages java-objc \
--no-example \
--no-local
- name: Diff the libraries
id: diff
run: |
echo "DIFF_RESULT<<EOF" >> $GITHUB_OUTPUT
# Diff in recursive mod with unified format (unified format uses - and + instead of < and >)
diff -r -u --no-ignore-file-name-case old-version new-version >> $GITHUB_OUTPUT || true
echo "EOF" >> $GITHUB_OUTPUT
- name: Comment on PR
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const body = `The commit with hash: ${{ steps.head_hash.outputs.HEAD_HASH }} has changed the output of \`create-react-native-library\`. You can find the diff of the change below:
\`\`\`diff
${{ steps.diff.outputs.DIFF_RESULT }}
\`\`\`
> This diff is between this branch and the \`main\` branch.
`;
const comments = await github.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
if (comments.data.some(comment => comment.body === body)) {
return;
}
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
})