Skip to content

Commit

Permalink
Merge pull request #353 from qdsfdhvh/version_1.7.0
Browse files Browse the repository at this point in the history
Version to 1.7.0
  • Loading branch information
qdsfdhvh committed Nov 5, 2023
2 parents 7b1b030 + d0f5f6b commit 5c996d3
Show file tree
Hide file tree
Showing 123 changed files with 1,981 additions and 826 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
# @see https://youtrack.jetbrains.com/issue/KTIJ-21944
ij_kotlin_blank_lines_around_block_when_branches = 0
ij_kotlin_line_break_after_multiline_when_entry = false

[*.yml]
indent_size = 2
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
**/baseline-prof.txt linguist-generated=true
**/snapshots/**/*.png filter=lfs diff=lfs merge=lfs -text
**/yarn.lock -diff
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,37 @@ name: CompareScreenshot

on:
push:
branches:
- master
pull_request:
paths:
- 'image-loader/**'
- 'image-loader/src/**'

env:
GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx6g -Dorg.gradle.daemon=false -Dkotlin.incremental=false"
permissions: { }

jobs:
test:
runs-on: macos-latest
compare-screenshot-test:
runs-on: ubuntu-latest
timeout-minutes: 20

permissions:
contents: read # for clone
actions: write # for upload-artifact

steps:
- uses: actions/checkout@v4
with:
lfs: true
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- uses: actions/[email protected]
- name: Set up JDK 17
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0
with:
distribution: 'zulu'
java-version: 19
distribution: temurin
java-version: 17

- name: Gradle cache
uses: gradle/gradle-build-action@v2
- name: Setup Gradle
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a # v2.9.0
with:
gradle-version: wrapper

# Download screenshots from main branch
- uses: dawidd6/action-download-artifact@v2
Expand All @@ -35,7 +44,7 @@ jobs:

- name: compare screenshot test
id: compare-screenshot-test
run: ./gradlew compareRoborazziDebug --stacktrace --info
run: ./gradlew compareRoborazzi --stacktrace --info

- uses: actions/upload-artifact@v3
if: ${{ always() }}
Expand Down
150 changes: 150 additions & 0 deletions .github/workflows/CompareScreenshotComment.yml
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-compare-screenshot-test:
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 # v2.27.0
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: master checkout
id: checkout-master
uses: actions/checkout@v3
with:
ref: master
- 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 # v2.27.0
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"
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@v2
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@v3
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
2 changes: 1 addition & 1 deletion .github/workflows/DocsDeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: ./gradlew dokkaHtmlMultiModule --stacktrace

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/DocsTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: ./gradlew dokkaHtmlMultiModule --stacktrace

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/StoreScreenshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ name: StoreScreenshot
on:
push:
branches:
- main
- master
pull_request:
paths:
- 'image-loader/src/**'

run-name: "StoreScreenshot by ${{ github.actor }}"

permissions: { }

Expand All @@ -19,7 +23,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Set up JDK 17
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0
Expand All @@ -35,7 +39,7 @@ jobs:

- name: record screenshot
id: record-test
run: ./gradlew recordRoborazziDebug --stacktrace
run: ./gradlew recordRoborazzi --stacktrace

- uses: actions/upload-artifact@v3
if: ${{ always() }}
Expand All @@ -59,4 +63,4 @@ jobs:
name: screenshot-test-results
path: |
**/build/test-results
retention-days: 30
retention-days: 30
38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
+ api("io.github.qdsfdhvh:image-loader:1.6.8")
+ api("io.github.qdsfdhvh:image-loader:1.7.0")
// optional - Moko Resources Decoder
+ api("io.github.qdsfdhvh:image-loader-extension-moko-resources:1.6.8")
+ api("io.github.qdsfdhvh:image-loader-extension-moko-resources:1.7.0")
// optional - Blur Interceptor (only support bitmap)
+ api("io.github.qdsfdhvh:image-loader-extension-blur:1.6.8")
+ api("io.github.qdsfdhvh:image-loader-extension-blur:1.7.0")
}
}
val jvmMain by getting {
dependencies {
// optional - ImageIO Decoder
+ api("io.github.qdsfdhvh:image-loader-extension-imageio:1.6.8")
+ api("io.github.qdsfdhvh:image-loader-extension-imageio:1.7.0")
}
}
}
Expand Down Expand Up @@ -58,18 +58,40 @@ fun Content() {
CompositionLocalProvider(
LocalImageLoader provides remember { generateImageLoader() },
) {
val painter = rememberImagePainter("https://..")
// Option 1 on 1.7.0+
AutoSizeImage(
"https://...",
contentDescription = "image",
)
// Option 2 on 1.7.0+
AutoSizeBox("https://...") { action ->
when (action) {
is ImageAction.Success -> {
Image(
rememberImageSuccessPainter(action),
contentDescription = "image",
)
}
is ImageAction.Loading -> {}
is ImageAction.Failure -> {}
}
}
// Option 3
Image(
painter = painter,
painter = rememberImagePainter("https://.."),
contentDescription = "image",
)
}
}
```

Use priority: `AutoSizeImage` -> `AutoSizeBox` -> `rememberImagePainter`.

`AutoSizeBox` & `AutoSizeImage` are based on **Modifier.Node**, `AutoSizeImage``AutoSizeBox` + `Painter`.

#### in Android

```kotlin title="MainActivity.kt"
```kotlin
fun generateImageLoader(): ImageLoader {
return ImageLoader {
options {
Expand All @@ -96,7 +118,7 @@ fun generateImageLoader(): ImageLoader {

#### in Jvm

```kotlin title="Main.kt"
```kotlin
fun generateImageLoader(): ImageLoader {
return ImageLoader {
components {
Expand Down
1 change: 1 addition & 0 deletions app/android/benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
android {
namespace = "com.seiko.imageloader.demo.benchmark"
defaultConfig {
minSdk = 23
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

// TODO temporary until AGP 8.2, which no longer requires this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import com.seiko.imageloader.DefaultAndroid
import com.seiko.imageloader.ImageLoader
import com.seiko.imageloader.LocalImageLoader
import com.seiko.imageloader.createDefaultAndroid
import com.seiko.imageloader.demo.util.commonConfig

class MainActivity : ComponentActivity() {
Expand All @@ -24,7 +24,7 @@ class MainActivity : ComponentActivity() {

private fun generateImageLoader(): ImageLoader {
return ImageLoader {
takeFrom(ImageLoader.DefaultAndroid(applicationContext))
takeFrom(ImageLoader.createDefaultAndroid(applicationContext))
commonConfig()
}
// return ImageLoader {
Expand Down
Loading

0 comments on commit 5c996d3

Please sign in to comment.