diff --git a/.github/actions/cache-build-paths/action.yml b/.github/actions/cache-build-paths/action.yml new file mode 100644 index 0000000..8671b95 --- /dev/null +++ b/.github/actions/cache-build-paths/action.yml @@ -0,0 +1,17 @@ +name: 'Cache Build' +description: 'Cache build paths' +inputs: + key: + description: 'Cache key' + required: true +runs: + using: 'composite' + steps: + - name: Cache build artifacts + uses: actions/cache@v3 + with: + path: | + app/build + key: ${{ inputs.key }} + restore-keys: | + ${{ inputs.key }} diff --git a/.github/workflows/ktlint.yml b/.github/workflows/ktlint.yml new file mode 100644 index 0000000..6448ddc --- /dev/null +++ b/.github/workflows/ktlint.yml @@ -0,0 +1,31 @@ +name: Kotlin-Linter + +on: + pull_request: + +jobs: + ktlint: + runs-on: macos-latest + steps: + - name: Get changed files + id: changes + run: | + URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" + RESPONSE=$(curl -s -X GET -G $URL --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}') + CHANGED_KOTLIN_FILES=$(echo $RESPONSE | jq -r '.[] | .filename' | grep -E "\.kt$" | tr \'\\n\' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//') + echo "Changed Kotlin files: ${CHANGED_KOTLIN_FILES}" + echo "changed_kotlin_files=${CHANGED_KOTLIN_FILES}" >> $GITHUB_ENV + + - name: "checkout" + if: env.changed_kotlin_files != '' + uses: actions/checkout@v4 + + - name: Install ktlint + if: env.changed_kotlin_files != '' + run: | + curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.50.0/ktlint && chmod a+x ktlint && sudo mv ktlint /usr/local/bin/ + + - name: run ktlint + if: env.changed_kotlin_files != '' + run: | + ktlint . '!**/build/**' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a732a3e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,63 @@ +name: Android CI + +env: + cache-name: android-gradle + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + setup: + runs-on: macos-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'adopt' + cache: gradle + + - name: Cache build artifacts + uses: ./.github/actions/cache-build-paths + with: + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.sha }} + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Assemble with Gradle + run: ./gradlew jar + + unit-tests: + needs: setup + + runs-on: macos-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'adopt' + cache: gradle + + - name: Cache build artifacts + uses: ./.github/actions/cache-build-paths + with: + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.sha }} + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Run unit tests + run: ./gradlew test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 03b7e5c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: java - -before_cache: - - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock - -directories: - - $HOME/.gradle/caches/ - - $HOME/.gradle/wrapper/ - -jdk: - - openjdk11 - -notifications: - email: - - eranbou@gmail.com - -script: -- ./gradlew ktlintCheck clean assemble test