From a42f4c61f7484d44144edea0f2e5e858871e433c Mon Sep 17 00:00:00 2001 From: Paul Rybitskyi Date: Sun, 18 Aug 2024 12:52:39 +0300 Subject: [PATCH] Improve CI scripts (#50) --- .github/ci-gradle.properties | 23 ----- .github/workflows/build.yml | 88 ++++++------------- .../workflows/gradle-wrapper-validation.yml | 20 ----- .github/workflows/release.yml | 42 ++++----- checksum.sh | 23 ----- 5 files changed, 41 insertions(+), 155 deletions(-) delete mode 100644 .github/ci-gradle.properties delete mode 100644 .github/workflows/gradle-wrapper-validation.yml delete mode 100755 checksum.sh diff --git a/.github/ci-gradle.properties b/.github/ci-gradle.properties deleted file mode 100644 index 1eb73a3..0000000 --- a/.github/ci-gradle.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright 2021 Paul Rybitskyi, paul.rybitskyi.work@gmail.com -# -# 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. -# - -org.gradle.daemon=false -org.gradle.parallel=true -org.gradle.jvmargs=-Xmx5120m -org.gradle.workers.max=2 - -# https://stackoverflow.com/questions/50138863/why-does-my-kotlin-gradle-build-die-with-exit-code-137 -kotlin.compiler.execution.strategy=in-process \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2b65cd2..dd8f8d8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,6 +6,10 @@ on: pull_request: branches: [ master ] +env: + JDK_JAVA_DISTRIBUTION: 'temurin' + JDK_JAVA_VERSION: '17' + jobs: static-analysis: name: Static Analysis @@ -14,30 +18,16 @@ jobs: steps: - name: Checkout Repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v2 + - name: Set up JDK + uses: actions/setup-java@v4 with: - distribution: 'temurin' - java-version: '17' - - - name: Generate a Cache Key - run: ./checksum.sh checksum.txt + distribution: ${{ env.JDK_JAVA_DISTRIBUTION }} + java-version: ${{ env.JDK_JAVA_VERSION }} - - name: Copy CI Gradle Properties - run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties - - - name: Cache Gradle Folders - uses: actions/cache@v2 - with: - path: | - ~/.gradle/caches/ - ~/.gradle/wrapper/ - key: cache-gradle-${{ runner.os }}-${{ hashFiles('checksum.txt') }} - restore-keys: | - cache-gradle-${{ runner.os }}- - cache-gradle- + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 - name: Run Static Analysis Tools run: ./gradlew lint --continue @@ -48,30 +38,16 @@ jobs: steps: - name: Checkout Repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v2 + - name: Set up JDK + uses: actions/setup-java@v4 with: - distribution: 'temurin' - java-version: '17' - - - name: Generate a Cache Key - run: ./checksum.sh checksum.txt + distribution: ${{ env.JDK_JAVA_DISTRIBUTION }} + java-version: ${{ env.JDK_JAVA_VERSION }} - - name: Copy CI Gradle Properties - run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties - - - name: Cache Gradle Folders - uses: actions/cache@v2 - with: - path: | - ~/.gradle/caches/ - ~/.gradle/wrapper/ - key: cache-gradle-${{ runner.os }}-${{ hashFiles('checksum.txt') }} - restore-keys: | - cache-gradle-${{ runner.os }}- - cache-gradle- + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 - name: Run Unit Tests run: ./gradlew test @@ -82,30 +58,16 @@ jobs: steps: - name: Checkout Repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v2 + - name: Set up JDK + uses: actions/setup-java@v4 with: - distribution: 'temurin' - java-version: '17' - - - name: Generate a Cache Key - run: ./checksum.sh checksum.txt + distribution: ${{ env.JDK_JAVA_DISTRIBUTION }} + java-version: ${{ env.JDK_JAVA_VERSION }} - - name: Copy CI Gradle Properties - run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties - - - name: Cache Gradle Folders - uses: actions/cache@v2 - with: - path: | - ~/.gradle/caches/ - ~/.gradle/wrapper/ - key: cache-gradle-${{ runner.os }}-${{ hashFiles('checksum.txt') }} - restore-keys: | - cache-gradle-${{ runner.os }}- - cache-gradle- + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 - name: Build Debug APK run: ./gradlew assembleDebug \ No newline at end of file diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml deleted file mode 100644 index c40f586..0000000 --- a/.github/workflows/gradle-wrapper-validation.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Gradle Wrapper Validation - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - validation: - name: Gradle Wrapper Validation - runs-on: ubuntu-latest - if: ${{ !contains(github.event.head_commit.message, '[ci skip]') }} - - steps: - - name: Checkout Repo - uses: actions/checkout@v2 - - - name: Validate Gradle Wrapper - uses: gradle/wrapper-validation-action@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b5c693d..d3596ee 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,47 +5,37 @@ on: tags: - 'v*' +env: + JDK_JAVA_DISTRIBUTION: 'temurin' + JDK_JAVA_VERSION: '17' + jobs: release: + name: Create a GitHub Release runs-on: [ubuntu-latest] + permissions: + contents: write steps: - name: Checkout Repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v2 + - name: Set up JDK + uses: actions/setup-java@v4 with: - distribution: 'temurin' - java-version: '17' - - - name: Generate a Cache Key - run: ./checksum.sh checksum.txt + distribution: ${{ env.JDK_JAVA_DISTRIBUTION }} + java-version: ${{ env.JDK_JAVA_VERSION }} - - name: Copy CI Gradle Properties - run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties - - - name: Cache Gradle Folders - uses: actions/cache@v2 - with: - path: | - ~/.gradle/caches/ - ~/.gradle/wrapper/ - key: cache-gradle-${{ runner.os }}-${{ hashFiles('checksum.txt') }} - restore-keys: | - cache-gradle-${{ runner.os }}- - cache-gradle- + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 - name: Build Debug APK run: ./gradlew assembleDebug - name: Create GitHub Release - uses: softprops/action-gh-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: softprops/action-gh-release@v2 with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} + name: Release ${{ github.ref }} draft: true prerelease: false files: app/build/outputs/apk/debug/sample-debug.apk diff --git a/checksum.sh b/checksum.sh deleted file mode 100755 index e624cd4..0000000 --- a/checksum.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -RESULT_FILE=$1 - -if [ -f $RESULT_FILE ]; then - rm $RESULT_FILE -fi -touch $RESULT_FILE - -checksum_file() { - echo $(openssl md5 $1 | awk '{print $2}') -} - -FILES=() -while read -r -d ''; do - FILES+=("$REPLY") -done < <(find . -type f \( -name "build.gradle*" -o -name "Dependencies.kt" -o -name "gradle-wrapper.properties" \) -print0) - -# Loop through files and append MD5 to result file -for FILE in ${FILES[@]}; do - echo $(checksum_file $FILE) >> $RESULT_FILE -done -# Now sort the file so that it is -sort $RESULT_FILE -o $RESULT_FILE \ No newline at end of file