Skip to content

Commit

Permalink
Merge pull request #5 from element-hq/misc/jme/add-screenshot-tests-a…
Browse files Browse the repository at this point in the history
…nd-coverage

Update icons and icon helper. Add screenshot tests, coverage and publishing GH flows
  • Loading branch information
jmartinesp authored Feb 12, 2024
2 parents 751f10b + e87cc9d commit e57649f
Show file tree
Hide file tree
Showing 315 changed files with 3,772 additions and 1,559 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
compound/screenshots/** filter=lfs diff=lfs merge=lfs -text
75 changes: 75 additions & 0 deletions .github/workflows/nightlyReports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Nightly reports

on:
workflow_dispatch:
schedule:
# Every nights at 5
- cron: "0 5 * * *"

# Enrich gradle.properties for CI/CD
env:
GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx3g -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError" -Dkotlin.daemon.jvm.options="-Xmx2560m" -Dkotlin.incremental=false -XX:+UseParallelGC
CI_GRADLE_ARG_PROPERTIES: --stacktrace -PpreDexEnable=false --max-workers 4

jobs:
nightlyReports:
name: Create kover report artifact and upload sonar result.
runs-on: ubuntu-latest
if: ${{ github.repository == 'element-hq/compound-android' }}
steps:
- name: ⏬ Checkout with LFS
uses: nschloe/action-cached-lfs-checkout@v1.2.2

- name: Use JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'

- name: ⚙️ Run unit tests
run: ./gradlew testDebugUnitTest $CI_GRADLE_ARG_PROPERTIES

- name: 📸 Run screenshot tests
run: ./gradlew :compound:verifyRoborazziDebug $CI_GRADLE_ARG_PROPERTIES

- name: 📈 Generate kover report and verify coverage
run: ./gradlew :compound:koverHtmlReport :compound:koverXmlReport :compound:koverVerify $CI_GRADLE_ARG_PROPERTIES -Pci-build=true

- name: ✅ Upload kover report
if: always()
uses: actions/upload-artifact@v4
with:
name: kover-results
path: |
**/build/reports/kover
- name: 🔊 Publish results to Sonar
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
ORG_GRADLE_PROJECT_SONAR_LOGIN: ${{ secrets.SONAR_TOKEN }}
if: ${{ always() && env.SONAR_TOKEN != '' && env.ORG_GRADLE_PROJECT_SONAR_LOGIN != '' }}
run: ./gradlew sonar $CI_GRADLE_ARG_PROPERTIES

# Gradle dependency analysis using https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin
dependency-analysis:
name: Dependency analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
- name: Configure gradle
uses: gradle/gradle-build-action@v2.11.1
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
- name: Dependency analysis
run: ./gradlew dependencyCheckAnalyze $CI_GRADLE_ARG_PROPERTIES
- name: Upload dependency analysis
if: always()
uses: actions/upload-artifact@v4
with:
name: dependency-analysis
path: build/reports/dependency-check-report.html
37 changes: 37 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish

on:
push:
tags:
- '*'
workflow_dispatch:

env:
GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx4096m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError" -Dkotlin.daemon.jvm.options="-Xmx2560m" -Dkotlin.incremental=false
CI_GRADLE_ARG_PROPERTIES: --stacktrace -PpreDexEnable=false --max-workers 4 --no-daemon
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ANDROID_SIGNING_GPG }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.ANDROID_SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.ANDROID_SIGNING_KEY_PASSWORD }}

jobs:
publish:
name: Publish to maven
runs-on: ubuntu-latest
steps:
- name: 🧮 Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: ☕️ Setup Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: ⬆️ Publish to Sonatype
uses: gradle/gradle-build-action@v2
with:
arguments: publishAndReleaseToMavenCentral --no-configuration-cache
50 changes: 50 additions & 0 deletions .github/workflows/recordScreenshots.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Record screenshots

on:
workflow_dispatch:
pull_request:
types: [ labeled ]

# Enrich gradle.properties for CI/CD
env:
GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx3584m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError" -Dkotlin.incremental=false -XX:+UseParallelGC

jobs:
record:
name: Record screenshots on branch ${{ github.event.pull_request.head.ref || github.ref_name }}
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.event.label.name == 'Record-Screenshots'

steps:
- name: Remove Record-Screenshots label
if: github.event.label.name == 'Record-Screenshots'
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: Record-Screenshots
- name: ⏬ Checkout with LFS (PR)
if: github.event.label.name == 'Record-Screenshots'
uses: nschloe/action-cached-lfs-checkout@v1.2.2
with:
persist-credentials: false
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }}
- name: ⏬ Checkout with LFS (Branch)
if: github.event_name == 'workflow_dispatch'
uses: nschloe/action-cached-lfs-checkout@v1.2.2
with:
persist-credentials: false
- name: ☕️ Use JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
# Add gradle cache, this should speed up the process
- name: Configure gradle
uses: gradle/gradle-build-action@v2.11.1
with:
cache-read-only: ${{ github.ref != 'refs/heads/develop' }}
- name: Record screenshots
id: record
run: ./.github/workflows/scripts/recordScreenshots.sh
env:
GITHUB_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN || secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ secrets.GITHUB_REPOSITORY }}
94 changes: 94 additions & 0 deletions .github/workflows/scripts/recordScreenshots.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash

#
# Copyright (c) 2023 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -e

TOKEN=$GITHUB_TOKEN
REPO=$GITHUB_REPOSITORY

SHORT=t:,r:
LONG=token:,repo:
OPTS=$(getopt -a -n recordScreenshots --options $SHORT --longoptions $LONG -- "$@")

eval set -- "$OPTS"
while :
do
case "$1" in
-t | --token )
TOKEN="$2"
shift 2
;;
-r | --repo )
REPO="$2"
shift 2
;;
--)
shift;
break
;;
*)
echo "Unexpected option: $1"
help
;;
esac
done

BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo Branch used: $BRANCH

if [[ -z ${TOKEN} ]]; then
echo "No token specified, either set the env var GITHUB_TOKEN or use the --token option"
exit 1
fi

if [[ -z ${REPO} ]]; then
echo "No repo specified, either set the env var GITHUB_REPOSITORY or use the --repo option"
exit 1
fi

echo "Deleting previous screenshots"
./gradlew removeOldSnapshots --stacktrace -PpreDexEnable=false --max-workers 4 --warn

echo "Record screenshots"
./gradlew :compound:recordRoborazziDebug --stacktrace -PpreDexEnable=false --max-workers 4 --warn

echo "Committing changes"
git config http.sslVerify false

if [[ -z ${INPUT_AUTHOR_NAME} ]]; then
git config user.name "ElementBot"
else
git config --local user.name "${INPUT_AUTHOR_NAME}"
fi

if [[ -z ${INPUT_AUTHOR_EMAIL} ]]; then
git config user.email "benoitm+elementbot@element.io"
else
git config --local user.name "${INPUT_AUTHOR_EMAIL}"
fi
git add -A
git commit -m "Update screenshots"

GITHUB_REPO="https://$GITHUB_ACTOR:$TOKEN@github.com/$REPO.git"
echo "Pushing changes"
if [[ -z ${GITHUB_ACTOR} ]]; then
echo "No GITHUB_ACTOR env var"
GITHUB_REPO="https://$TOKEN@github.com/$REPO.git"
fi
git push $GITHUB_REPO "$BRANCH"
echo "Done!"
33 changes: 33 additions & 0 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Tag Release

on:
pull_request:
types:
- closed
branches:
- 'main'

jobs:
tag_release:
if: ${{ github.event.pull_request.merged == true && startsWith( github.head_ref, 'version-' ) }}
runs-on: ubuntu-latest
steps:
- name: 🧮 Checkout code
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}

- name: Get Version
uses: mad9000/actions-find-and-replace-string@3
id: get-version
with:
source: ${{ github.head_ref }}
find: 'version-'
replace: ''

- name: Add Tag
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.PAT }}
custom_tag: ${{steps.get-version.outputs.value}}
tag_prefix: ''
86 changes: 86 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Test

on:
workflow_dispatch:
pull_request:
merge_group:
push:
branches: [ main ]

# Enrich gradle.properties for CI/CD
env:
GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx3584m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError" -Dkotlin.incremental=false -XX:+UseParallelGC
CI_GRADLE_ARG_PROPERTIES: --stacktrace -PpreDexEnable=false --max-workers 4 --warn

jobs:
tests:
name: Runs unit tests
runs-on: ubuntu-latest

# Allow all jobs on main. Just one per PR.
concurrency:
group: ${{ github.ref == 'refs/heads/main' && format('unit-tests-main-{0}', github.sha) || format('unit-tests-{0}', github.ref) }}
cancel-in-progress: true
steps:
# Increase swapfile size to prevent screenshot tests getting terminated
# https://github.com/actions/runner-images/discussions/7188#discussioncomment-6750749
- name: 💽 Increase swapfile size
run: |
sudo swapoff -a
sudo fallocate -l 8G /mnt/swapfile
sudo chmod 600 /mnt/swapfile
sudo mkswap /mnt/swapfile
sudo swapon /mnt/swapfile
sudo swapon --show
- name: ⏬ Checkout with LFS
uses: nschloe/action-cached-lfs-checkout@v1.2.2
with:
# Ensure we are building the branch and not the branch after being merged on main
# https://github.com/actions/checkout/issues/881
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }}
- name: ☕️ Use JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
- name: Configure gradle
uses: gradle/gradle-build-action@v2.11.1
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' }}

- name: ⚙️ Run unit tests
run: ./gradlew testDebugUnitTest $CI_GRADLE_ARG_PROPERTIES

- name: 📸 Run screenshot tests
run: ./gradlew :compound:verifyRoborazziDebug $CI_GRADLE_ARG_PROPERTIES

- name: 📈Generate kover report and verify coverage
run: ./gradlew :compound:koverHtmlReport :compound:koverXmlReport :compound:koverVerify $CI_GRADLE_ARG_PROPERTIES -Pci-build=true

- name: 🚫 Upload kover failed coverage reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: kover-error-report
path: |
compound/build/reports/kover/verify.err
- name: ✅ Upload kover report (disabled)
if: always()
run: echo "This is now done only once a day, see nightlyReports.yml"

- name: 🚫 Upload test results on error
if: failure()
uses: actions/upload-artifact@v4
with:
name: tests-and-screenshot-tests-results
path: |
**/build/roborazzi/failures/
**/build/reports/tests/*UnitTest/
# https://github.com/codecov/codecov-action
- name: ☂️ Upload coverage reports to codecov
if: always()
uses: codecov/codecov-action@v3
# with:
# files: build/reports/kover/xml/report.xml
13 changes: 13 additions & 0 deletions .github/workflows/validate-lfs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Validate Git LFS

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
name: Validate
steps:
- uses: nschloe/action-cached-lfs-checkout@v1.2.2

- run: |
./scripts/validate_lfs.sh
Loading

0 comments on commit e57649f

Please sign in to comment.