From d0b1ba3f80486fb53192bc3ffd4d2c0a59eee363 Mon Sep 17 00:00:00 2001 From: marchingon12 Date: Wed, 7 Apr 2021 11:28:09 +0200 Subject: [PATCH] Add initial CI Build --- .gitlab-ci.yml | 45 +++++++++++++++++++++++++++++++++++++++++++++ ci-notify.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 ci-notify.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..07c065025 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,45 @@ +image: jangrewe/gitlab-ci-android + +before_script: +- COMMIT_URL="https://gitlab.com/AuroraOSS/AuroraStore/-/commit/${CI_COMMIT_SHA}" +- MSG_URL="https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" +- export GRADLE_USER_HOME=$(pwd)/.gradle +- chmod +x ./gradlew + +cache: + key: ${CI_PROJECT_ID} + paths: + - .gradle/ + +stages: +- build +# - test +- notify + +# lintDebug: +# stage: build +# script: +# - ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint + +assembleDebug: + stage: build + script: + - ./gradlew assembleDebug + - 'curl -s -X POST ${MSG_URL} -d chat_id=${TELEGRAM_CHAT_ID} + -d "disable_web_page_preview=true" + -d "parse_mode=html" + -d text=Project: ${CI_PROJECT_NAME}\n⚒️ Building with HEAD at ${CI_COMMIT_SHORT_SHA} by ${CI_COMMIT_AUTHOR}\nBranch: ${CI_COMMIT_BRANCH}' + artifacts: + paths: + - app/build/outputs/ + +# testDebug: +# stage: test +# script: +# - ./gradlew -Pci --console=plain :app:testDebug + +# Once build finished or failed, notify using Telegram +notifyTelegram: + stage: notify + script: + - script -c "bash -x ci-notify.sh" > ci-logs.log # build succeeded with apk file attached or failed \ No newline at end of file diff --git a/ci-notify.sh b/ci-notify.sh new file mode 100644 index 000000000..f54c42037 --- /dev/null +++ b/ci-notify.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +MSG_URL="https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" +DOC_URL="https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendDocument" +# COMMIT_URL="https://gitlab.com/AuroraOSS/AuroraStore/-/commit/$CI_COMMIT_SHA" +# TEXT="Project:$CI_PROJECT_NAMEBuilding with HEAD at $CI_COMMIT_SHORT_SHA by $CI_COMMIT_AUTHOR.%0ABranch:+$CI_COMMIT_REF_SLUG" +#TEXT="Build status: $1%0A%0AProject:+$CI_PROJECT_NAME%0AURL:+$CI_PROJECT_URL/pipelines/$CI_PIPELINE_ID/%0ABranch:+$CI_COMMIT_REF_SLUG" + +#curl -s --max-time $TIME -d "chat_id=$TELEGRAM_CHAT_ID&disable_web_page_preview=1&text=$TEXT" $MSG_URL > /dev/null + +# curl -s -X POST $MSG_URL -d chat_id=$TELEGRAM_CHAT_ID \ +# -d "disable_web_page_preview=true" \ +# -d "parse_mode=html" \ +# -d text=$TEXT + +if [ -f app/build/outputs/apk/debug/app-debug.apk ]; then + cp app/build/outputs/apk/debug/app-debug.apk app/build/outputs/apk/debug/AuroraStore_$DATE.apk + cd app/build/outputs/apk/debug/ + APK=$(echo AuroraStore_*.apk) + curl -F document=@"$APK" $DOC_URL \ + -F chat_id=$TELEGRAM_CHAT_ID \ + -F "disable_web_page_preview=true" \ + -F "parse_mode=html" \ + -F caption="✅ CI build completed successfully!" + rm -rf app/build/outputs/apk +else + curl -s -X POST $MSG_URL -d chat_id=$TELEGRAM_CHAT_ID \ + -d "disable_web_page_preview=true" \ + -d "parse_mode=html" \ + -d text="❌ Build error, exiting now!" +fi