-
Notifications
You must be signed in to change notification settings - Fork 2
76 lines (63 loc) · 2.24 KB
/
add-test-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
name: Add new tests to PR
on:
pull_request:
jobs:
test-diff:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 14
- name: Install dependencies
run: |
echo //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} > .npmrc
yarn --frozen-lockfile
- name: Extract tests from origin branch
run: |
yarn extract tests.txt
cat tests.txt | sort > origin_tests.txt
rm tests.txt
env:
CI: true
- name: Extract tests from destination branch
run: |
git fetch origin ${{ github.base_ref }}
git checkout ${{ github.base_ref }}
echo //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} > .npmrc
yarn --frozen-lockfile
yarn extract tests.txt
cat tests.txt | sort > destination_tests.txt
rm tests.txt
env:
CI: true
- name: Compare tests
run: |
diff origin_tests.txt destination_tests.txt > tests_diff.txt || true
touch new_tests.txt
NEW_TESTS_LINES=$(cat tests_diff.txt | grep "<" | wc -l)
if [ $NEW_TESTS_LINES -gt 0 ]; then
echo "**New Tests**" > new_tests.txt
echo "\`\`\`" >> new_tests.txt
cat tests_diff.txt | grep "<" >> new_tests.txt
echo "\`\`\`" >> new_tests.txt
fi
touch removed_tests.txt
REMOVED_TESTS_LINES=$(cat tests_diff.txt | grep ">" | wc -l)
if [ $REMOVED_TESTS_LINES -gt 0 ]; then
echo "**Removed Tests**" > removed_tests.txt
echo "\`\`\`" >> removed_tests.txt
cat tests_diff.txt | grep ">" >> removed_tests.txt
echo "\`\`\`" >> removed_tests.txt
fi
echo "### Tests difference:" > comment.txt
cat new_tests.txt >> comment.txt
cat removed_tests.txt >> comment.txt
cat comment.txt
- name: PR comment with file
uses: thollander/actions-comment-pull-request@v2
with:
filePath: comment.txt
comment_tag: "Tests Difference"