From bea3cd5457e331f04a9aeb5c99267f14908f5eaa Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Tue, 25 Feb 2020 15:22:05 +0530 Subject: [PATCH] CI workflow improvements (#642) * github: Only run debug tasks in PRs * github: Remove nightly deploys * github: Setup automatic debug branch deployment * Tweak Gradle config in CI Signed-off-by: Harsh Shandilya Co-authored-by: Aditya Wasan --- .github/ci-gradle.properties | 6 ++++ ...ightly_snapshots.yml => branch_deploy.yml} | 31 ++++++++++--------- .github/workflows/deploy_snapshot.yml | 3 ++ .github/workflows/pull_request.yml | 5 ++- release/deploy-telegram.sh | 13 ++++++++ 5 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 .github/ci-gradle.properties rename .github/workflows/{deploy_nightly_snapshots.yml => branch_deploy.yml} (53%) create mode 100755 release/deploy-telegram.sh diff --git a/.github/ci-gradle.properties b/.github/ci-gradle.properties new file mode 100644 index 000000000..053002826 --- /dev/null +++ b/.github/ci-gradle.properties @@ -0,0 +1,6 @@ +org.gradle.daemon=true +org.gradle.configureondemand=true +android.enableBuildCache=true +org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.caching=true +org.gradle.parallel=true diff --git a/.github/workflows/deploy_nightly_snapshots.yml b/.github/workflows/branch_deploy.yml similarity index 53% rename from .github/workflows/deploy_nightly_snapshots.yml rename to .github/workflows/branch_deploy.yml index 57effc96d..7b681ab78 100644 --- a/.github/workflows/deploy_nightly_snapshots.yml +++ b/.github/workflows/branch_deploy.yml @@ -1,11 +1,13 @@ -name: "Release nightly snapshots" on: - schedule: - - cron: '0 0 * * *' + push: + branches-ignore: + - master +name: Build debug jobs: - deploy-release-snapshot: + generate-debug-build: runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[ci skip]')" steps: - name: Checkout repository uses: actions/checkout@v1 @@ -15,6 +17,9 @@ jobs: env: ENCRYPT_KEY: ${{ secrets.ENCRYPT_KEY }} + - name: Copy CI gradle.properties + run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties + - uses: actions/cache@v1 with: path: ~/.gradle/caches @@ -23,19 +28,15 @@ jobs: - name: Download gradle dependencies run: ./gradlew dependencies - - name: Build release app - run: ./gradlew :app:assembleRelease - env: - SNAPSHOT: "true" + - name: Build debug app + run: ./gradlew :app:assembleDebug - name: Clean secrets run: release/signing-cleanup.sh - - name: Deploy snapshot - run: release/deploy-snapshot.sh + - name: Send APK to Telegram + run: release/deploy-telegram.sh env: - ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }} - SSH_USERNAME: ${{ secrets.SSH_USERNAME }} - SERVER_ADDRESS: ${{ secrets.SERVER_ADDRESS }} - SERVER_DESTINATION: ${{ secrets.SERVER_DESTINATION }} - SSH_PORT: ${{ secrets.SSH_PORT }} + TG_TO: ${{ secrets.TELEGRAM_TO }} + TG_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} + TG_FILE: ./app/build/outputs/apk/debug/app-debug.apk diff --git a/.github/workflows/deploy_snapshot.yml b/.github/workflows/deploy_snapshot.yml index 4c5bda07c..e1f6abb7f 100644 --- a/.github/workflows/deploy_snapshot.yml +++ b/.github/workflows/deploy_snapshot.yml @@ -17,6 +17,9 @@ jobs: env: ENCRYPT_KEY: ${{ secrets.ENCRYPT_KEY }} + - name: Copy CI gradle.properties + run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties + - uses: actions/cache@v1 with: path: ~/.gradle/caches diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 283699b9f..9d4d1f076 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -8,12 +8,15 @@ jobs: - uses: actions/checkout@master + - name: Copy CI gradle.properties + run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties + - uses: actions/cache@v1 with: path: ~/.gradle/caches key: gradle-${{ runner.os }}-${{ hashFiles('**/build.gradle') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/dependencies.gradle') }} - - run: ./gradlew spotlessCheck build test lintDebug -Dpre-dex=false + - run: ./gradlew spotlessCheck assembleDebug testDebug lintDebug -Dpre-dex=false - uses: actions/upload-artifact@master with: diff --git a/release/deploy-telegram.sh b/release/deploy-telegram.sh new file mode 100755 index 000000000..79ae94586 --- /dev/null +++ b/release/deploy-telegram.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +function send_to_tg() { + local FILE + local CHAT_ID + local CAPTION + FILE="${1}" + CHAT_ID="${2}" + CAPTION="${3}" + curl -F chat_id="${CHAT_ID}" -F document="@${FILE}" -F caption="${CAPTION}" -F parse_mode="Markdown" "https://api.telegram.org/bot${TG_TOKEN:?}/sendDocument" >/dev/null 2>&1 +} + +send_to_tg "${TG_FILE:?}" "${TG_TO:?}" "aps-${GITHUB_RUN_NUMBER}-debug"