From 10b731a7a0df2407acb443584a343f087f00a923 Mon Sep 17 00:00:00 2001 From: MR3Y Date: Mon, 5 Feb 2024 14:55:36 +0200 Subject: [PATCH] Add build on CI workflow --- .github/workflows/build.yml | 76 +++++++++++++++++++++++++++++++++++++ app/build.gradle.kts | 16 ++++++-- 2 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..23c8e288 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,76 @@ +name: Build and run local tests + +on: + push: + branches: + - main + tags-ignore: + - 'v*' + paths-ignore: + - '**.md' + - '**.txt' + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +env: + API_KEY: ${{ secrets.API_KEY }} + API_SECRET: ${{ secrets.API_SECRET }} + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v2 + + - name: set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle + + - name: Setup Gradle + uses: gradle/gradle-build-action@v3 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build debug + run: ./gradlew assembleDebug --stacktrace + + - name: Run local tests + run: ./gradlew testDebug --stacktrace + + - name: Apply ktlint formatting to (.kt/s) files. + run: ./gradlew ktlintFormat --stacktrace + + - name: Commit and push changes (if any). + if: ${{ github.ref == 'refs/heads/main' }} + uses: EndBug/add-and-commit@v9 + with: + author_name: GitHub Actions + author_email: github-actions@github.com + message: Apply style formatting + push: true + + - name: Upload build outputs (APKs) + uses: actions/upload-artifact@v4 + with: + name: build-outputs + path: | + **/build/outputs/* + + - name: Upload build reports + if: always() + uses: actions/upload-artifact@v4 + with: + name: build-reports + path: ./**/build/reports \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d66e82a6..4ce9fdd6 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -33,10 +33,8 @@ android { useSupportLibrary = true } - val properties = Properties() - properties.load(FileInputStream(rootProject.file("local.properties"))) - buildConfigField("String", "API_KEY", "\"${properties.getProperty("API_KEY")}\"") - buildConfigField("String", "API_SECRET", "\"${properties.getProperty("API_SECRET")}\"") + buildConfigField("String", "API_KEY", "\"${getValueOfKey("API_KEY")}\"") + buildConfigField("String", "API_SECRET", "\"${getValueOfKey("API_SECRET")}\"") } buildTypes { @@ -125,6 +123,16 @@ ksp { arg("lyricist.packageName", "com.mr3y.podcaster") } +fun getValueOfKey(key: String) { + if (System.getenv("CI").toBoolean()) { + System.getenv(key) + } else { + val properties = Properties() + properties.load(FileInputStream(rootProject.file("local.properties"))) + properties.getProperty(key) + } +} + dependencies { implementation(libs.core.ktx) implementation(libs.splashscreen)