-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature/roborazzi]: Screenshot Test 작업 추가 #323
Merged
Merged
Changes from 29 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
f92051f
필요 종속성 추가
kez-lab 5915353
필요 종속성 추가
kez-lab 7a56fb6
test rule 및 RobotTestRule 추가
kez-lab dfbf076
App Test 셋팅
kez-lab 4b6dee5
CI yml파일 셋팅
kez-lab f94568d
사용하지 않는 함수 제거
kez-lab 249229c
사용하지 않는 import 제거
kez-lab 9c59eff
CI .yml 수정
kez-lab 0411f70
CI .yml 수정
kez-lab dc381fe
CI .yml 수정
kez-lab 37acc52
CI .yml 수정
kez-lab a275ee2
CI .yml 수정
kez-lab dbe4257
CI .yml 수정
kez-lab 9a889d5
CI .yml 수정
kez-lab ad0853c
CI .yml 수정
kez-lab 667839e
CI .yml 수정
kez-lab 13479f0
CI .yml 수정
kez-lab c2b676c
CI .yml 수정
kez-lab 3233adc
CI .yml 수정
kez-lab 5e19f70
CI .yml 수정
kez-lab 7174967
CI .yml 수정
kez-lab cb26759
CI .yml 수정
kez-lab 9b94eb8
UI 변경 TEST
kez-lab 1907469
TEST CI
kez-lab 01615e1
TEST
kez-lab 35db2c5
compare 속성 추가
kez-lab 702ddb6
Merge pull request #2 from KwakEuiJin/feature/roborazzi-test
kez-lab fcab875
compare 속성 추가
kez-lab a3cf595
최종 수정
kez-lab 3ec4fff
엔터 제거 수정
kez-lab b163440
Report Option 수정
kez-lab 7a112a9
엔터 제거 수정
kez-lab f364d08
파일 마지막 줄 엔터 추가
kez-lab 0c9d1af
gradle.properties roborazzi options 수정
kez-lab 4b4a527
runTestWithLogging coroutineScope 제거 및 onFailure 활용
kez-lab 26b884b
MainActivity Widget 기능 원복
kez-lab c1e9527
Merge remote-tracking branch 'upstream/main' into feature/roborazzi
kez-lab 234d17a
HiltTestActivity.kt 삭제
kez-lab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
name: Screenshot compare comment | ||
|
||
on: | ||
workflow_run: | ||
workflows: | ||
- CompareScreenshot | ||
types: | ||
- completed | ||
|
||
permissions: { } | ||
|
||
jobs: | ||
Comment-CompareScreenshot: | ||
if: > | ||
github.event.workflow_run.event == 'pull_request' && | ||
github.event.workflow_run.conclusion == 'success' | ||
|
||
timeout-minutes: 2 | ||
|
||
permissions: | ||
actions: read # for downloading artifacts | ||
contents: write # for pushing screenshot-diff to companion branch | ||
pull-requests: write # for creating a comment on pull requests | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615 | ||
with: | ||
name: pr | ||
run_id: ${{ github.event.workflow_run.id }} | ||
- id: get-pull-request-number | ||
name: Get pull request number | ||
shell: bash | ||
run: | | ||
echo "pull_request_number=$(cat NR)" >> "$GITHUB_OUTPUT" | ||
- name: main checkout | ||
id: checkout-main | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.event.pull_request.base.ref || github.event.repository.default_branch }} | ||
- id: switch-companion-branch | ||
env: | ||
BRANCH_NAME: companion_${{ github.event.workflow_run.head_branch }} | ||
run: | | ||
# orphan means it will create no history branch | ||
git branch -D "$BRANCH_NAME" || true | ||
git checkout --orphan "$BRANCH_NAME" | ||
git rm -rf . | ||
- uses: dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615 | ||
with: | ||
run_id: ${{ github.event.workflow_run.id }} | ||
name: screenshot-diff | ||
path: screenshot-diff | ||
- id: check-if-there-are-valid-files | ||
name: Check if there are valid files | ||
shell: bash | ||
run: | | ||
# Find all the files ending with _compare.png | ||
mapfile -t files_to_add < <(find . -type f -name "*_compare.png") | ||
|
||
# Check for invalid file names and add only valid ones | ||
exist_valid_files="false" | ||
for file in "${files_to_add[@]}"; do | ||
if [[ $file =~ ^[a-zA-Z0-9_./-]+$ ]]; then | ||
exist_valid_files="true" | ||
break | ||
fi | ||
done | ||
echo "exist_valid_files=$exist_valid_files" >> "$GITHUB_OUTPUT" | ||
- id: push-screenshot-diff | ||
shell: bash | ||
if: steps.check-if-there-are-valid-files.outputs.exist_valid_files == 'true' | ||
env: | ||
BRANCH_NAME: companion_${{ github.event.workflow_run.head_branch }} | ||
run: | | ||
# Find all the files ending with _compare.png | ||
files_to_add=$(find . -type f -name "*_compare.png") | ||
|
||
# Check for invalid file names and add only valid ones | ||
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 | ||
- id: generate-diff-reports | ||
name: Generate diff reports | ||
if: steps.check-if-there-are-valid-files.outputs.exist_valid_files == 'true' | ||
env: | ||
BRANCH_NAME: companion_${{ github.event.workflow_run.head_branch }} | ||
shell: bash | ||
run: | | ||
# Find all the files ending with _compare.png in roborazzi folder | ||
files=$(find . -type f -name "*_compare.png" | grep "roborazzi/" | grep -E "^[a-zA-Z0-9_./-]+$") | ||
delimiter="$(openssl rand -hex 8)" | ||
{ | ||
echo "reports<<${delimiter}" | ||
|
||
# Create markdown table header | ||
echo "Snapshot diff report vs base branch: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.event.pull_request.base.ref || github.event.repository.default_branch }}" | ||
echo "| File name | Image |" | ||
echo "|-------|-------|" | ||
} >> "$GITHUB_OUTPUT" | ||
|
||
# Iterate over the files and create table rows | ||
for file in $files; do | ||
# Get the file name and insert newlines every 20 characters | ||
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 | ||
if: steps.generate-diff-reports.outputs.reports != '' | ||
with: | ||
issue-number: ${{ steps.get-pull-request-number.outputs.pull_request_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 | ||
if: steps.generate-diff-reports.outputs.reports != '' | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
issue-number: ${{ steps.get-pull-request-number.outputs.pull_request_number }} | ||
body: ${{ steps.generate-diff-reports.outputs.reports }} | ||
edit-mode: replace | ||
|
||
- name: Cleanup outdated companion branches | ||
run: | | ||
# Find outdated companion branches with last commit date | ||
git branch -r --format="%(refname:lstrip=3)" | grep companion_ | while read -r branch; do | ||
last_commit_date_timestamp=$(git log -1 --format=%ct "origin/$branch") | ||
now_timestamp=$(date +%s) | ||
# Delete branch if it's older than 1 month | ||
# if [ $((now_timestamp - last_commit_date_timestamp)) -gt 2592000 ]; then | ||
# For testing purpose, delete branch if it's older than 1 second | ||
echo "branch: $branch now_timestamp: $now_timestamp last_commit_date_timestamp: $last_commit_date_timestamp" | ||
if [ $((now_timestamp - last_commit_date_timestamp)) -gt 1 ]; then | ||
# Comment out for demonstration purpose | ||
echo "Deleting $branch" | ||
|
||
# git push origin --delete "$branch" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: CompareScreenshot | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
permissions: {} | ||
|
||
jobs: | ||
compare-screenshot-test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 20 | ||
|
||
permissions: | ||
contents: read # for clone | ||
actions: write # for upload-artifact | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
|
||
- name: Setup Gradle | ||
uses: gradle/gradle-build-action@4c39dd82cd5e1ec7c6fa0173bb41b4b6bb3b86ff # v3.3.2 | ||
with: | ||
gradle-version: wrapper | ||
|
||
|
||
- uses: dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615 | ||
continue-on-error: true | ||
with: | ||
name: screenshot | ||
workflow: store-screenshot.yml | ||
branch: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || github.event.repository.default_branch }} | ||
|
||
- name: compare screenshot test | ||
id: compare-screenshot-test | ||
run: | | ||
./gradlew compareRoborazziDebug --stacktrace | ||
|
||
- uses: actions/upload-artifact@v4 | ||
if: ${{ always() }} | ||
with: | ||
name: screenshot-diff | ||
path: | | ||
**/build/outputs/roborazzi | ||
retention-days: 30 | ||
|
||
- uses: actions/upload-artifact@v4 | ||
if: ${{ always() }} | ||
with: | ||
name: screenshot-diff-reports | ||
path: | | ||
**/build/reports | ||
retention-days: 30 | ||
|
||
- uses: actions/upload-artifact@v4 | ||
if: ${{ always() }} | ||
with: | ||
name: screenshot-diff-test-results | ||
path: | | ||
**/build/test-results | ||
retention-days: 30 | ||
|
||
- name: Save PR number | ||
if: ${{ github.event_name == 'pull_request' }} | ||
run: | | ||
mkdir -p ./pr | ||
echo ${{ github.event.number }} > ./pr/NR | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: pr | ||
path: pr/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: StoreScreenshot | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
permissions: {} | ||
|
||
jobs: | ||
store-screenshot-test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 20 | ||
|
||
permissions: | ||
contents: read # for clone | ||
actions: write # for upload-artifact | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
|
||
# Better than caching and/or extensions of actions/setup-java | ||
- name: Setup Gradle | ||
uses: gradle/gradle-build-action@4c39dd82cd5e1ec7c6fa0173bb41b4b6bb3b86ff # v3.3.2 | ||
with: | ||
gradle-version: wrapper | ||
|
||
- name: record screenshot | ||
id: record-test | ||
run: | | ||
# Use --rerun-tasks to disable cache for test task | ||
./gradlew recordRoborazziDebug --stacktrace --rerun-tasks | ||
- uses: actions/upload-artifact@v4 | ||
if: ${{ always() }} | ||
with: | ||
name: screenshot | ||
path: | | ||
**/build/outputs/roborazzi | ||
retention-days: 30 | ||
|
||
- uses: actions/upload-artifact@v4 | ||
if: ${{ always() }} | ||
with: | ||
name: screenshot-reports | ||
path: | | ||
**/build/reports | ||
retention-days: 30 | ||
|
||
- uses: actions/upload-artifact@v4 | ||
if: ${{ always() }} | ||
with: | ||
name: screenshot-test-results | ||
path: | | ||
**/build/test-results | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ plugins { | |
id("droidknights.android.application") | ||
id("com.google.android.gms.oss-licenses-plugin") | ||
alias(libs.plugins.baselineprofile) | ||
alias(libs.plugins.roborazzi.plugin) | ||
} | ||
|
||
android { | ||
|
@@ -43,4 +44,6 @@ dependencies { | |
|
||
baselineProfile(projects.baselineprofile) | ||
implementation(libs.androidx.profileinstaller) | ||
} | ||
|
||
testImplementation(projects.core.testing) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 엔터 제거 다시 조정해주세요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 수정했습니다. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.droidknights.app | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.droidknights.app.core.testing.category.ScreenshotTests | ||
import com.droidknights.app.core.testing.robot.KnightsAppRobot | ||
import com.droidknights.app.core.testing.rule.RobotTestRule | ||
import com.droidknights.app.feature.main.MainActivity | ||
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers | ||
import dagger.hilt.android.testing.BindValue | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import dagger.hilt.android.testing.HiltTestApplication | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.experimental.categories.Category | ||
import org.junit.runner.RunWith | ||
import org.robolectric.annotation.Config | ||
import org.robolectric.annotation.GraphicsMode | ||
import javax.inject.Inject | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@GraphicsMode(GraphicsMode.Mode.NATIVE) | ||
@Config(application = HiltTestApplication::class) | ||
@HiltAndroidTest | ||
@Category(ScreenshotTests::class) | ||
class KnightsAppTest { | ||
|
||
@get:Rule | ||
@BindValue | ||
val robotTestRule: RobotTestRule = RobotTestRule<MainActivity>(this) | ||
|
||
@Inject | ||
lateinit var knightsAppRobot: KnightsAppRobot | ||
|
||
@Test | ||
fun checkStartupShot() { | ||
knightsAppRobot { | ||
capture() | ||
} | ||
} | ||
|
||
@Test | ||
@Config(qualifiers = RobolectricDeviceQualifiers.MediumTablet) | ||
fun checkMediumTabletLaunchShot() { | ||
knightsAppRobot { | ||
capture() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엔터 제거 다시 조정해주세요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 수정했습니다.