diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml new file mode 100644 index 0000000..bed7e5e --- /dev/null +++ b/.github/workflows/actions.yml @@ -0,0 +1,184 @@ +name: 'Android application builder' +on: push +jobs: + +# copy_keystore: +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v2 + +# - run: env + +# # Add private key to ssh agent +# - run: mkdir ~/.ssh; chmod 700 ~/.ssh +# - run: echo "${{ secrets.PRIVATE_KEY }}" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa +# - run: eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_rsa +# - run: ssh-keyscan github.com >> ~/.ssh/known_hosts + +# # Clone keystore repository +# - run: git clone git@github.com:javavirys/MediaPlayerKeystore.git +# - run: mkdir ~/keystore +# - run: ls +# - run: ls ~ +# - run: find . -name '*.jks' -exec cp "{}" ~/keystore/ \; +# - run: ls ~/keystore +# - uses: actions/cache@v2 +# id: restore-build +# with: +# path: ~/keystore +# key: ${{ github.sha }} +# Test ================================= + copy_keystore: + runs-on: ubuntu-latest + container: + image: javavirys/android:30.0.3 + steps: + - uses: actions/checkout@v2 + + - run: apt install -y git + + # Add private key to ssh agent + - run: mkdir /root/.ssh; chmod 700 /root/.ssh + - run: echo "${{ secrets.PRIVATE_KEY }}" > /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa + - run: eval "$(ssh-agent -s)" && ssh-add /root/.ssh/id_rsa + - run: ssh-keyscan github.com >> /root/.ssh/known_hosts + + # Clone keystore repository + - run: git clone git@github.com:javavirys/MediaPlayerKeystore.git + - run: mkdir /keystore + # Copy keystore to keystore directory + - run: find . -name '*.jks' -exec cp "{}" /keystore/ \; + - run: ls /keystore + - uses: actions/cache@v2 + id: restore-build + with: + path: /keystore + key: ${{ github.sha }} + + tests: + needs: [ copy_keystore ] + runs-on: ubuntu-latest + container: + image: javavirys/android:30.0.3 + steps: + - uses: actions/checkout@v2 + + - uses: actions/cache@v2 + id: restore-build + with: + path: /keystore + key: ${{ github.sha }} + + - run: ls /keystore + + - name: Run tests + run: ./gradlew test + env: + KEY_ALIAS: ${{ secrets.KEY_ALIAS }} + KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} + STORE_FILE: /keystore/keystore.jks + STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} + + lint: + needs: [ copy_keystore ] + runs-on: ubuntu-latest + container: + image: javavirys/android:30.0.3 + steps: + - uses: actions/checkout@v2 + + - uses: actions/cache@v2 + id: restore-build + with: + path: /keystore + key: ${{ github.sha }} + + - run: ls /keystore + + - name: Run lint + run: ./gradlew lint + env: + KEY_ALIAS: ${{ secrets.KEY_ALIAS }} + KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} + STORE_FILE: /keystore/keystore.jks + STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} + + - name: Archive artifacts + uses: actions/upload-artifact@v2 + with: + name: lint + path: + app/build/reports + + buildApks: + needs: [ lint, tests ] + runs-on: ubuntu-latest + container: + image: javavirys/android:30.0.3 + steps: + - uses: actions/checkout@v2 + + - uses: actions/cache@v2 + id: restore-build + with: + path: /keystore + key: ${{ github.sha }} + + - run: ls /keystore + + - name: Build apks + run: ./gradlew assemble + env: + KEY_ALIAS: ${{ secrets.KEY_ALIAS }} + KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} + STORE_FILE: /keystore/keystore.jks + STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} + + - name: Archive artifacts + uses: actions/upload-artifact@v2 + with: + name: Apks + path: + app/build/outputs/apk + + buildBundles: + needs: [ lint, tests ] + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + container: + image: javavirys/android:30.0.3 + steps: + - uses: actions/checkout@v2 + + - uses: actions/cache@v2 + id: restore-build + with: + path: /keystore + key: ${{ github.sha }} + + - run: ls /keystore + + - name: Build bundles + run: ./gradlew bundle + env: + KEY_ALIAS: ${{ secrets.KEY_ALIAS }} + KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} + STORE_FILE: /keystore/keystore.jks + STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} + + - name: Archive artifacts + uses: actions/upload-artifact@v2 + with: + name: Bundles + path: + app/build/outputs/bundle + + publishToPlay: + needs: [ buildBundles ] + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + container: + image: javavirys/android:30.0.3 + steps: + - uses: actions/checkout@v2 + - run: echo Not Implemented yet! diff --git a/.gitignore b/.gitignore index aa724b7..073bf60 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ .externalNativeBuild .cxx local.properties +keystore.properties diff --git a/app/.gitignore b/app/.gitignore index 42afabf..73b491a 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1 +1,3 @@ -/build \ No newline at end of file +/build +*.aab +/release/* \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index fd6b396..2642857 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,3 +1,5 @@ +import gradleutils.Keystore + plugins { id 'com.android.application' id 'kotlin-android' @@ -8,6 +10,8 @@ plugins { id 'com.google.firebase.crashlytics' } +def keystore = new Keystore(rootProject) + android { compileSdkVersion 30 buildToolsVersion "30.0.3" @@ -29,8 +33,18 @@ android { } + signingConfigs { + release { + keyAlias keystore.getProperty('KEY_ALIAS') + keyPassword keystore.getProperty('KEY_PASSWORD') + storeFile file(keystore.getProperty('STORE_FILE')) + storePassword keystore.getProperty('STORE_PASSWORD') + } + } + buildTypes { release { + signingConfig signingConfigs.release minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' @@ -89,4 +103,4 @@ dependencies { //di implementation Dependencies.koin implementation Dependencies.koinExt -} \ No newline at end of file +} diff --git a/buildSrc/src/main/java/gradleutils/Keystore.kt b/buildSrc/src/main/java/gradleutils/Keystore.kt new file mode 100644 index 0000000..0dc1341 --- /dev/null +++ b/buildSrc/src/main/java/gradleutils/Keystore.kt @@ -0,0 +1,23 @@ +package gradleutils; + +import org.gradle.api.Project +import java.io.FileInputStream +import java.util.* + +class Keystore(rootProject: Project) { + + private val keystoreProperties = Properties() + + init { + val keystoreFile = rootProject.file("keystore.properties") + if (keystoreFile.exists()) { + keystoreProperties.load(FileInputStream(keystoreFile)) + } + } + + fun getProperty(key: String): String = when { + keystoreProperties.containsKey(key) -> keystoreProperties[key] as String + System.getenv(key) != null -> System.getenv(key) + else -> throw RuntimeException("Property not found!") + } +} \ No newline at end of file