# GitLab CI/CD Pipeline for SilverDROID (Dark Side Admin) # Android APK Build & Deployment image: mingc/android-build-box:latest variables: ANDROID_COMPILE_SDK: "35" ANDROID_BUILD_TOOLS: "34.0.0" ANDROID_SDK_TOOLS: "9477386" GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.caching=true" GIT_SUBMODULE_STRATEGY: recursive stages: - prepare - test - build - deploy before_script: - export GRADLE_USER_HOME=$(pwd)/.gradle - chmod +x ./gradlew - rm -f /opt/android-sdk/platforms/android-35/package.xml || true - yes | sdkmanager "platforms;android-35" || true - yes | sdkmanager --licenses || true # Cache Gradle dependencies cache: key: ${CI_COMMIT_REF_SLUG} paths: - .gradle/wrapper - .gradle/caches - build/ - app/build/ # =========================== # STAGE: Prepare # =========================== prepare:dependencies: stage: prepare script: - echo "Downloading Gradle dependencies..." - ./gradlew --version - ./gradlew dependencies cache: key: ${CI_COMMIT_REF_SLUG} paths: - .gradle/ policy: pull-push only: - main - develop - merge_requests # =========================== # STAGE: Test # =========================== lint: stage: test script: - echo "Running Android Lint..." - ./gradlew lint artifacts: name: "lint-${CI_COMMIT_SHORT_SHA}" paths: - app/build/reports/lint-results*.html - app/build/reports/lint-results*.xml expire_in: 1 week when: always only: - main - develop - merge_requests unit_tests: stage: test script: - echo "Running unit tests..." - ./gradlew test artifacts: name: "tests-${CI_COMMIT_SHORT_SHA}" paths: - app/build/reports/tests/ reports: junit: app/build/test-results/test*UnitTest/**.xml expire_in: 1 week when: always only: - main - develop - merge_requests # =========================== # STAGE: Build # =========================== build:debug: stage: build script: - echo "Building Debug APK..." - ./gradlew assembleDebug - echo "APK built successfully!" - ls -lh app/build/outputs/apk/debug/ artifacts: name: "silverdroid-debug-${CI_COMMIT_SHORT_SHA}" paths: - app/build/outputs/apk/debug/app-debug.apk expire_in: 30 days only: - main - develop - merge_requests - tags build:release: stage: build script: - echo "Building Release APK..." - ./gradlew assembleRelease - echo "Release APK built successfully!" - ls -lh app/build/outputs/apk/release/ artifacts: name: "silverdroid-release-${CI_COMMIT_SHORT_SHA}" paths: - app/build/outputs/apk/release/app-release-unsigned.apk expire_in: 90 days only: - main - tags build:bundle: stage: build script: - echo "Building Android App Bundle (AAB)..." - ./gradlew bundleRelease - echo "AAB built successfully!" - ls -lh app/build/outputs/bundle/release/ artifacts: name: "silverdroid-bundle-${CI_COMMIT_SHORT_SHA}" paths: - app/build/outputs/bundle/release/app-release.aab expire_in: 90 days only: - main - tags # =========================== # STAGE: Deploy # =========================== deploy:staging: stage: deploy script: - echo "Deploying to staging environment..." - echo "APK available at ${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/download" dependencies: - build:debug environment: name: staging url: https://gitlab.silverlabs.uk/${CI_PROJECT_PATH}/-/jobs/${CI_JOB_ID}/artifacts/download only: - develop deploy:production: stage: deploy script: - echo "Deploying to production..." - echo "Release APK app/build/outputs/apk/release/app-release-unsigned.apk" - echo "Creating release tag..." dependencies: - build:release environment: name: production url: https://gitlab.silverlabs.uk/${CI_PROJECT_PATH}/-/releases when: manual only: - tags # =========================== # Additional Jobs # =========================== # Security scan security:scan: stage: test script: - echo "Running security scan..." - ./gradlew dependencyCheckAnalyze || true artifacts: paths: - build/reports/dependency-check-report.html expire_in: 1 week when: always allow_failure: true only: - main - develop # Generate APK info apk:info: stage: deploy script: - echo "Extracting APK information..." - APK_SIZE=$(du -h app/build/outputs/apk/debug/app-debug.apk | cut -f1) - echo "APK Size$APK_SIZE" - echo "Commit ${CI_COMMIT_SHORT_SHA}" - echo "---" > apk-info.txt - echo "SilverDROID - Dark Side Admin" >> apk-info.txt - echo "Build ${CI_COMMIT_SHORT_SHA}" >> apk-info.txt - echo "Size $APK_SIZE" >> apk-info.txt - echo "Date $(date)" >> apk-info.txt dependencies: - build:debug artifacts: paths: - apk-info.txt expire_in: 30 days only: - main - develop # Notification (optional - requires webhook setup) notify:success: stage: deploy script: - echo "Build successful! Pipeline ${CI_PIPELINE_URL}" when: on_success allow_failure: true only: - main notify:failure: stage: deploy script: - echo "Build failed! Pipeline ${CI_PIPELINE_URL}" when: on_failure allow_failure: true only: - main