diff --git a/.github/actions/ios-set-up/action.yml b/.github/actions/ios-set-up/action.yml new file mode 100644 index 000000000..2ff73b9d5 --- /dev/null +++ b/.github/actions/ios-set-up/action.yml @@ -0,0 +1,18 @@ +name: iOS set up +description: Sets up Kotlin Native and Cocoapods +runs: + using: "composite" + steps: + - shell: bash + run: ./gradlew :shared:generateDummyFramework + + - name: Set up cocoapods + uses: maxim-lobanov/setup-cocoapods@v1 + with: + version: latest + + - shell: bash + name: Install Dependencies + run: | + cd iosApp + pod install --verbose \ No newline at end of file diff --git a/.github/actions/job-set-up/action.yml b/.github/actions/job-set-up/action.yml new file mode 100644 index 000000000..6ac3b8db7 --- /dev/null +++ b/.github/actions/job-set-up/action.yml @@ -0,0 +1,12 @@ +name: Job set up +description: Sets up the Java and Gradle +runs: + using: "composite" + steps: + - uses: actions/setup-java@v3 + with: + distribution: "temurin" + java-version: "17" + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 \ No newline at end of file diff --git a/.github/workflows/android-pull-request-ci.yml b/.github/workflows/android-pull-request-ci.yml deleted file mode 100644 index dccf54559..000000000 --- a/.github/workflows/android-pull-request-ci.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: Android Pull Request CI - -on: - pull_request: - branches: [ main ] - -jobs: - verify: - runs-on: ubuntu-latest - - permissions: - checks: write - - # needed unless run with comment_mode: off - pull-requests: write - - # only needed for private repository - contents: read - - # only needed for private repository - issues: read - - # required by download step to access artifacts API - actions: read - - steps: - - name: Checkout the code - uses: actions/checkout@v3 - - - name: set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'corretto' - java-version: '17' - - - name: set up Android SDK - uses: android-actions/setup-android@v2 - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - - name: Run detekt - run: ./gradlew detekt - - - name: Upload Event File - uses: actions/upload-artifact@v4 - with: - name: Event File - path: ${{ github.event_path }} - - - name: Run unit tests - run: ./gradlew testDebugUnitTest --stacktrace - - - name: Upload Test Results - if: always() - uses: actions/upload-artifact@v4 - with: - name: Test Results - path: "**/test-results/**/*.xml" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..980dc1922 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,42 @@ +name: Build + +on: + workflow_call: + inputs: + shouldRunKmp: + required: true + type: string + shouldRunAndroid: + required: true + type: string + shouldRunIos: + required: true + type: string + +jobs: + Android: + if: ${{ inputs.shouldRunKmp == 'true' || inputs.shouldRunAndroid == 'true' }} + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Job set up + uses: ./.github/actions/job-set-up + + - run: ./gradlew :app:assembleDebug --stacktrace + + iOS: + if: ${{ inputs.shouldRunKmp == 'true' || inputs.shouldRunIos == 'true' }} + runs-on: macos-latest + + steps: + - uses: actions/checkout@v4 + + - name: Job set up + uses: ./.github/actions/job-set-up + + - name: iOS set up + uses: ./.github/actions/ios-set-up + + - run: xcodebuild build -workspace iosApp/iosApp.xcworkspace -configuration Debug -scheme iosApp -sdk iphoneos -destination name='iPhone 14' -verbose diff --git a/.github/workflows/compare-screenshot-comment.yml b/.github/workflows/compare-screenshot-comment.yml deleted file mode 100644 index 7d48f4339..000000000 --- a/.github/workflows/compare-screenshot-comment.yml +++ /dev/null @@ -1,150 +0,0 @@ -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
/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 diff --git a/.github/workflows/compare-screenshot.yml b/.github/workflows/compare-screenshot.yml deleted file mode 100644 index da1b778f0..000000000 --- a/.github/workflows/compare-screenshot.yml +++ /dev/null @@ -1,80 +0,0 @@ -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/ diff --git a/.github/workflows/pull-request-ci.yml b/.github/workflows/pull-request-ci.yml new file mode 100644 index 000000000..368e78bbc --- /dev/null +++ b/.github/workflows/pull-request-ci.yml @@ -0,0 +1,32 @@ +name: Pull Request CI + +on: + pull_request: + branches: + - main-kmp + workflow_dispatch: + inputs: + shouldRunAndroid: + description: 'Run Android build' + required: true + default: 'false' + type: choice + options: + - 'true' + - 'false' + shouldRunIos: + description: 'Run iOS build' + required: true + default: 'false' + type: choice + options: + - 'true' + - 'false' + +jobs: + build: + uses: ./.github/workflows/build.yml + with: + shouldRunKmp: ${{ contains(github.event.pull_request.labels.*.name, 'Common') }} + shouldRunAndroid: ${{ contains(github.event.pull_request.labels.*.name, 'Android') }} + shouldRunIos: ${{ contains(github.event.pull_request.labels.*.name, 'iOS') }} diff --git a/.github/workflows/store-screenshot.yml b/.github/workflows/store-screenshot.yml deleted file mode 100644 index 62b5d5a78..000000000 --- a/.github/workflows/store-screenshot.yml +++ /dev/null @@ -1,64 +0,0 @@ -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