-
Notifications
You must be signed in to change notification settings - Fork 1
205 lines (170 loc) · 5.94 KB
/
test.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: Test
on:
pull_request:
branches:
- main
- develop
- feature/*
paths-ignore:
- README.md
permissions:
contents: write
actions: read
pull-requests: write
jobs:
dependencies:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup
uses: ./.github/actions/setup
with:
api-key: ${{ secrets.API_KEY }}
test-prod:
needs: dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
# ref: https://github.com/danger/danger/issues/913
fetch-depth: 100
- name: Setup
uses: ./.github/actions/setup
with:
api-key: ${{ secrets.API_KEY }}
- name: ktlint-check
run: ./gradlew --continue ktlintCheck
- name: Test ProdDebug
run: ./gradlew testProdDebugUnitTest
- name: Report jacoco
run: ./gradlew jacocoTestReport
- name: jacoco-report to zip
run: zip -r jacocoTestReport.zip ./build/reports/jacoco/jacocoTestReport/html
- name: Archive jacoco report
uses: actions/upload-artifact@v4
with:
name: jacocoTestReport
path: ./build/reports/jacoco/jacocoTestReport/html
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.2
bundler-cache: true
- name: Danger
uses: MeilCli/danger-action@v5
with:
plugins_file: Gemfile
install_path: vendor/bundle
danger_file: Dangerfile
danger_id: danger-pr
env:
DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }}
- name: Slack notify
uses: ./.github/actions/incoming-webhook
with:
slack-webhook-url: ${{ secrets.SLACK_INCOMING_WEBHOOK_URL }}
compile-mock:
needs: dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup
uses: ./.github/actions/setup
with:
api-key: ${{ secrets.API_KEY }}
- name: Compile MockDebug
run: ./gradlew compileMockDebugSource
compare-screnshots:
needs: dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup
uses: ./.github/actions/setup
with:
api-key: ${{ secrets.API_KEY }}
- name: compare screenshots
run: ./gradlew compareRoborazziProdDebug --stacktrace
- name: Make PR number directory for saving screenshots
if: ${{ github.event_name == 'pull_request' }}
run: mkdir -p ./pr/${{ github.event.number }}
- name: Move screenshots to PR number directory
if: ${{ github.event_name == 'pull_request' }}
run: |
# delete except *_compare.png
find ./app/build/outputs/roborazzi -type f | grep -v -e '.*_compare.png' | xargs rm -rf
mv ./app/build/outputs/roborazzi ./pr/${{ github.event.number }}/
ls ./pr/${{ github.event.number }}
- name: Save screenshots
uses: actions/upload-artifact@v4
with:
name: pr directory
path: pr/${{ github.event.number }}/
- name: Save pr number
run: echo "PR_NUMBER=${{ github.event.number }}" >> $GITHUB_ENV
- name: main checkout
uses: actions/checkout@v4
with:
ref: main
- name: switch companion branch
env:
BRANCH_NAME: companion_${{ github.event.workflow_run.head_branch }}
run: |
git branch -D $BRANCH_NAME || true
git checkout --orphan $BRANCH_NAME
git rm -rf .
## CompareScreenshotワークフローで生成された差分を取得
- uses: actions/download-artifact@v4
env:
PR_NUMBER: ${{ env.PR_NUMBER }}
with:
name: pr directory
## 差分の画像をcompanionブランチにpush
- id: push-screenshot-diff
env:
BRANCH_NAME: companion_${{ github.event.workflow_run.head_branch }}
run: |
files_to_add=$(find . -type f -name "*_compare.png")
for file in $files_to_add; do
if [[ $file =~ ^[a-zA-Z0-9_./-]+$ ]]; then
git add $file
fi
done
git config --global user.name ScreenshotBot
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
git commit -m "Add screenshot diff"
git push origin HEAD:$BRANCH_NAME -f
- name: Create comments
id: create-comments
run: |
files=$(find . -type f -name "*_compare.png" | grep "roborazzi/" | grep -E "^[a-zA-Z0-9_./-]+$")
delimiter="$(openssl rand -hex 8)"
{
echo "reports<<${delimiter}"
echo "Snapshot diff report"
echo "| File name | Image |"
echo "|-------|-------|"
} >> "$GITHUB_OUTPUT"
for file in $files; do
fileName=$(basename "$file" | sed -r 's/(.{20})/\1<br>/g')
echo "| [$fileName](https://github.com/${{ github.repository }}/blob/$BRANCH_NAME/$file) | ![](https://github.com/${{ github.repository }}/blob/$BRANCH_NAME/$file?raw=true) |" >> "$GITHUB_OUTPUT"
done
echo "${delimiter}" >> "$GITHUB_OUTPUT"
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.number }}
comment-author: 'github-actions[bot]'
body-includes: Snapshot diff report
- name: Add or update comment on PR
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.number }}
body: ${{ steps.create-comments.outputs.reports }}
edit-mode: replace