First attempt at CI action (#652)

* First attempt at CI action

* Split lints and test steps.

* Only run validate job on PR.

* First attempt at beta deploy via Github Actions

* Try to archive a debug version of application.

* Use static version of NDK.

* Add ENV variables to building the release.

* Ensure all secrets are used!

* Attempt to publish feature branch.

* Make sure all files are in place first.

* Ensure keystore is still accessible during deployment.

* Update README.md for the lack of automation for now.
This commit is contained in:
Justin Bassett 2020-07-05 17:48:00 -04:00 committed by GitHub
parent 949a826e15
commit ad64855220
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 138 additions and 89 deletions

85
.github/workflows/beta.yml vendored Normal file
View file

@ -0,0 +1,85 @@
name: Beta Deploy
# Triggers the workflow on push events but only for the master branch
on:
push:
branches: [ master ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
deploy:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Make sure we have the correct JDK setup
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
# Copy over the mock google-services.json
- name: Mock debug google-services.json
run: mv .github/mock-google-services.json app/src/debug/google-services.json
- name: Inflate release_keystore.keystore
env:
KEYSTORE: ${{ secrets.KEYSTORE_FILE }}
run: echo $KEYSTORE | base64 --decode > app/release_keystore.keystore
- name: Inflate google-services.json
env:
GOOGLE_SERVICES: ${{ secrets.GoogleServices }}
run: echo $GOOGLE_SERVICES > app/google-services.json
- name: Inflate firebaseAppDistributionServiceCredentialsFile.json
env:
CREDS: ${{ secrets.FirebaseCreds }}
run: echo $CREDS > firebaseAppDistributionServiceCredentialsFile.json
- name: Inflate playStorePublishServiceCredentialsFile.json
env:
CREDS: ${{ secrets.PlaystoreCreds }}
run: echo $CREDS > app/playStorePublishServiceCredentialsFile.json
- name: Validate ktlint
run: ./gradlew ktlintCheck
- name: Validate Lint
run: ./gradlew lint
- name: Validate Tests
run: ./gradlew test
- name: Build Release
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEYSTORE_ALIAS: ${{ secrets.KEYSTORE_ALIAS }}
KEYSTORE_ALIAS_PASSWORD: ${{ secrets.KEYSTORE_ALIAS_PASSWORD }}
run: ./gradlew assembleRelease
- name: Create Release Notes
run: |
mkdir -p app/src/main/play/release-notes/en-US/
git log --format=%s | head -n 1 > app/src/main/play/release-notes/en-US/default.txt
previous=`git tag -l --sort=-creatordate | head -n 1`
echo "Diff from production: https://github.com/home-assistant/home-assistant-android/compare/${previous}...master" >> app/src/main/play/release-notes/en-US/default.txt
- name: Deploy to Firebase
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEYSTORE_ALIAS: ${{ secrets.KEYSTORE_ALIAS }}
KEYSTORE_ALIAS_PASSWORD: ${{ secrets.KEYSTORE_ALIAS_PASSWORD }}
run: ./gradlew appDistributionUploadRelease
- name: Deploy to Playstore Beta
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEYSTORE_ALIAS: ${{ secrets.KEYSTORE_ALIAS }}
KEYSTORE_ALIAS_PASSWORD: ${{ secrets.KEYSTORE_ALIAS_PASSWORD }}
run: ./gradlew publishReleaseBundle

45
.github/workflows/pr.yml vendored Normal file
View file

@ -0,0 +1,45 @@
name: Pull Request
# Triggers the workflow on pull request events but only for the master branch
on:
pull_request:
branches: [ master ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
validate:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Make sure we have the correct JDK setup
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
# Copy over the mock google-services.json
- name: Mock google-services.json
run: mv .github/mock-google-services.json app/google-services.json
- name: Validate ktlint
run: ./gradlew ktlintCheck
- name: Validate Lint
run: ./gradlew lint
- name: Validate Tests
run: ./gradlew test
- name: Build Debug APK
run: ./gradlew assembleDebug
- name: Archive Debug Build
uses: actions/upload-artifact@v2
with:
path: ./app/build/outputs/apk/debug/app-debug.apk

View file

@ -1,28 +0,0 @@
language: android
dist: trusty
git:
depth: false
before_install:
- chmod ugo+x .travis/before_install.sh
- ./.travis/before_install.sh
android:
components:
- android-29
- build-tools-29.0.2
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
script:
- chmod ugo+x .travis/script.sh
- ./.travis/script.sh

View file

@ -1,16 +0,0 @@
#!/bin/bash
set -ev
if [ "$TRAVIS_PULL_REQUEST" = "false" ]
then
openssl aes-256-cbc -K $encrypted_6c4fc944fe71_key -iv $encrypted_6c4fc944fe71_iv -in .travis/secrets.tar.enc -out .travis/secrets.tar -d
tar xvf .travis/secrets.tar
mv google-services.json app/google-services.json
mv upload_keystore.keystore app/release_keystore.keystore
mv home-assistant-mobile-apps-0b13292f44c4.json app/playStorePublishServiceCredentialsFile.json
mv home-assistant-mobile-apps-5fd6b9dd0fdb.json firebaseAppDistributionServiceCredentialsFile.json
mv .travis/mock-google-services.json app/src/debug/google-services.json
else
mv .travis/mock-google-services.json app/google-services.json
fi

View file

@ -1,39 +0,0 @@
#!/bin/bash
set -ev
if [ "$TRAVIS_PULL_REQUEST" != "false" ]
then
echo "Building PR"
./gradlew test
./gradlew lint
./gradlew ktlintCheck
elif [ -n "$TRAVIS_TAG" ]
then
echo "Promoting Beta to Production"
mkdir -p app/src/main/play/release-notes/en-US/
previous=`git tag -l --sort=-creatordate | head -n 2 | tail -n 1`
current=`git tag -l --sort=-creatordate | head -n 1`
echo "Full patch change log: https://github.com/home-assistant/home-assistant-android/compare/${previous}...${current}" > app/src/main/play/release-notes/en-US/default.txt
./gradlew promoteArtifact --from-track beta --promote-track production
elif [ "$TRAVIS_BRANCH" = "master" ]
then
echo "Building Master"
mkdir -p app/src/main/play/release-notes/en-US/
git log --format=%s | head -n 1 > app/src/main/play/release-notes/en-US/default.txt
previous=`git tag -l --sort=-creatordate | head -n 1`
echo "Diff from production: https://github.com/home-assistant/home-assistant-android/compare/${previous}...master" >> app/src/main/play/release-notes/en-US/default.txt
export VERSION_CODE=`git rev-list --count HEAD`
./gradlew test
./gradlew lint
./gradlew ktlintCheck
./gradlew assembleRelease appDistributionUploadRelease publishReleaseBundle
fi

Binary file not shown.

View file

@ -15,7 +15,7 @@ If you are looking for documentation around the companion applications check out
- Now download the `google-services.json` file and put it in the _home-assistant-Android/app_ folder
[You can also use the mock services file instead of generating your own](/.travis/mock-google-services.json)
[You can also use the mock services file instead of generating your own](/.github/mock-google-services.json)
The file should contain client IDs for `io.homeassistant.companion.android` and `io.homeassistant.companion.android.debug` for debugging to work properly. **If you do not generate your own file push notification will never work**
- Start Android Studio, open your source code folder and check if the Gradle build will be successful
@ -54,11 +54,10 @@ The project currently uses [lokalise](https://lokalise.com/public/145814835dd655
## Generating a release to production
Edit the build number in `/app/build.gradle` to your desired version. Be sure to leave `${vCode}`!!
Update Config.kt with new Version:
```kotlin
def vName = "X.X.X-${vCode}"
const val version = "X.X.X"
```
Merge that into master and allow the build to complete and validate on the beta channel. (Deploy there automatic)
Add release in Github, then log into play store and promote beta to production.
Once ready to move to production tag the master branch and travis will start the promotion from beta -> production.
Automation TBD after changes to Github Actions

View file

@ -22,6 +22,8 @@ buildscript {
android {
compileSdkVersion(Config.Android.compileSdk)
ndkVersion = Config.Android.ndk
defaultConfig {
applicationId = "io.homeassistant.companion.android"
minSdkVersion(Config.Android.minSdk)

View file

@ -21,6 +21,7 @@ object Config {
const val compileSdk = 29
const val minSdk = 21
const val targetSdk = 29
const val ndk = "21.3.6528147"
}
object Dependency {