From e17ff540b6b4b0a993290f46cf450ed2f684b02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliv=C3=A9r=20Falvai?= Date: Tue, 27 Jul 2021 14:23:55 +0200 Subject: [PATCH] Remove NDK platforms dir check (#79) * Remove platforms dir check because it's missing from NDK r22+ * Add more E2E tests * Restructure Bitrise workflows * Fix broken React Native E2E test * Fix broken E2E test * Remove broken SDK20 E2E test * Re-add old project test, but without Gradle step * Use utility workflows for common logic * Fix failing sample app build * Fix another sample app build [STEP-247] --- bitrise.yml | 308 ++---------------------------------------------- e2e/bitrise.yml | 174 +++++++++++++++++++++++++++ main.go | 44 ------- 3 files changed, 187 insertions(+), 339 deletions(-) create mode 100644 e2e/bitrise.yml diff --git a/bitrise.yml b/bitrise.yml index 9d290cf..2a1b8ef 100755 --- a/bitrise.yml +++ b/bitrise.yml @@ -1,131 +1,19 @@ -format_version: "8" +format_version: "11" default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git -app: - envs: - # define these in your .bitrise.secrets.yml - - SAMPLE_APP_URL: https://github.com/bitrise-io/sample-apps-android-sdk22.git - - BRANCH: master - workflows: - # ---------------------------------------------------------------- - # --- workflow to Step Test - test: - envs: - - GRADLE_BUILD_FILE_PATH: build.gradle - - GRADLEW_PATH: ./gradlew + check: steps: - - script: - inputs: - - content: |- - #!/usr/bin/env bash - set -e - rm -rf ./_tmp - - change-workdir: - title: Switch working dir to test / _tmp dir - run_if: true - inputs: - - path: ./_tmp - - is_create_path: true - - git::https://github.com/bitrise-steplib/bitrise-step-simple-git-clone.git@master: - inputs: - - repository_url: $SAMPLE_APP_URL - - clone_into_dir: . - - branch: $BRANCH - - path::./: - title: Step test - - ci: - steps: - - go-list: - - golint: - - errcheck: - - go-test: - before_run: - - audit-this-step - after_run: - - test_ndk - - test_old_gradle - - test_android-sdk21-tools-21.0.1 - - test_android-sdk20 - - test_android-sdk22-subdir - - test_react_native - - test_ndk_install - - test_support_library + - git::https://github.com/bitrise-steplib/steps-check.git: {} - test_ndk: - envs: - - SAMPLE_APP_URL: https://github.com/bitrise-io/android-ndk-sample-project.git - - BRANCH: ndk22-compatible - - GRADLE_BUILD_FILE_PATH: ./build.gradle - - GRADLEW_PATH: ./gradlew - - ANDROID_NDK_HOME: "" + e2e: steps: - - script: - inputs: - - content: |- - #!/usr/bin/env bash - set -e - rm -rf ./_tmp - - change-workdir: - title: Switch working dir to test / _tmp dir - run_if: true - inputs: - - path: ./_tmp - - is_create_path: true - - git::https://github.com/bitrise-steplib/bitrise-step-simple-git-clone.git@master: - inputs: - - repository_url: $SAMPLE_APP_URL - - clone_into_dir: . - - branch: $BRANCH - - script: + - git::https://github.com/bitrise-steplib/steps-check.git: inputs: - - content: |- - #!/usr/bin/env bash - set -ex - rm -rf $ANDROID_HOME/ndk-bundle - - path::./: - title: Step test installing ndk - - path::./: - title: Step test installed ndk + - workflow: e2e - test_react_native: + sample: envs: - - SAMPLE_APP_URL: https://github.com/bitrise-io/ChainReactApp.git - - BRANCH: master - - GRADLE_BUILD_FILE_PATH: android/build.gradle - - GRADLEW_PATH: android/gradlew - steps: - - script: - inputs: - - content: |- - #!/usr/bin/env bash - set -e - rm -rf ./_tmp - - change-workdir: - title: Switch working dir to test / _tmp dir - run_if: true - inputs: - - path: ./_tmp - - is_create_path: true - - git::https://github.com/bitrise-steplib/bitrise-step-simple-git-clone.git@master: - inputs: - - repository_url: $SAMPLE_APP_URL - - clone_into_dir: . - - branch: $BRANCH - - script: - inputs: - - content: |- - #!/usr/bin/env bash - set -ex - yarn - - path::./: - title: Step test - - test_ndk_install: - envs: - - SAMPLE_APP_URL: https://github.com/bitrise-io/android-ndk-sample-project.git - - BRANCH: ndk22-compatible - GRADLE_BUILD_FILE_PATH: build.gradle - GRADLEW_PATH: ./gradlew steps: @@ -137,187 +25,17 @@ workflows: rm -rf ./_tmp - change-workdir: title: Switch working dir to test / _tmp dir - run_if: true + run_if: "true" inputs: - path: ./_tmp - is_create_path: true - git::https://github.com/bitrise-steplib/bitrise-step-simple-git-clone.git@master: inputs: - - repository_url: $SAMPLE_APP_URL + - repository_url: https://github.com/bitrise-io/sample-apps-android-sdk22.git - clone_into_dir: . - - branch: $BRANCH + - branch: master - path::./: - title: Not using NDK - inputs: - - ndk_revision: "" - - path::./: - title: Installing NDK r18 - inputs: - - ndk_revision: "18" - - path::./: - title: Already installed revision case + title: Execute step + - gradle-runner: inputs: - - ndk_revision: "18" - - path::./: - title: Another version case - inputs: - - ndk_revision: "17" - - test_android-sdk21-tools-21.0.1: - envs: - - SAMPLE_APP_URL: https://github.com/bitrise-io/android-sdk21-tools-21.0.1.git - - BRANCH: master - - GRADLE_BUILD_FILE_PATH: build.gradle - - GRADLEW_PATH: ./gradlew - steps: - - script: - inputs: - - content: |- - #!/usr/bin/env bash - set -e - rm -rf ./_tmp - - change-workdir: - title: Switch working dir to test / _tmp dir - run_if: true - inputs: - - path: ./_tmp - - is_create_path: true - - git::https://github.com/bitrise-steplib/bitrise-step-simple-git-clone.git@master: - inputs: - - repository_url: $SAMPLE_APP_URL - - clone_into_dir: . - - branch: $BRANCH - - path::./: - title: Step test - - test_support_library: - envs: - - SAMPLE_APP_URL: https://github.com/bitrise-io/sample-apps-android-x.git - - BRANCH: master - - GRADLE_BUILD_FILE_PATH: build.gradle - - GRADLEW_PATH: ./gradlew - steps: - - script: - inputs: - - content: |- - #!/usr/bin/env bash - set -e - rm -rf ./_tmp - - script: - inputs: - - content: |- - #!/usr/bin/env bash - sdkmanager --uninstall "extras;android;m2repository" - - change-workdir: - title: Switch working dir to test / _tmp dir - run_if: true - inputs: - - path: ./_tmp - - is_create_path: true - - git::https://github.com/bitrise-steplib/bitrise-step-simple-git-clone.git@master: - inputs: - - repository_url: $SAMPLE_APP_URL - - clone_into_dir: . - - branch: $BRANCH - - path::./: - title: Step test - - test_old_gradle: - envs: - - SAMPLE_APP_URL: https://github.com/bitrise-io/2048-android.git - - BRANCH: master - - GRADLE_BUILD_FILE_PATH: build.gradle - - GRADLEW_PATH: ./gradlew - steps: - - script: - inputs: - - content: |- - #!/usr/bin/env bash - set -e - rm -rf ./_tmp - - change-workdir: - title: Switch working dir to test / _tmp dir - run_if: true - inputs: - - path: ./_tmp - - is_create_path: true - - git::https://github.com/bitrise-steplib/bitrise-step-simple-git-clone.git@master: - inputs: - - repository_url: $SAMPLE_APP_URL - - clone_into_dir: . - - branch: $BRANCH - - path::./: - title: Step test - - test_android-sdk20: - envs: - - SAMPLE_APP_URL: https://github.com/bitrise-io/sample-apps-android-sdk20.git - - BRANCH: master - - GRADLE_BUILD_FILE_PATH: build.gradle - - GRADLEW_PATH: ./gradlew - steps: - - script: - inputs: - - content: |- - #!/usr/bin/env bash - set -e - rm -rf ./_tmp - - change-workdir: - title: Switch working dir to test / _tmp dir - run_if: true - inputs: - - path: ./_tmp - - is_create_path: true - - git::https://github.com/bitrise-steplib/bitrise-step-simple-git-clone.git@master: - inputs: - - repository_url: $SAMPLE_APP_URL - - clone_into_dir: . - - branch: $BRANCH - - path::./: - title: Step test - - test_android-sdk22-subdir: - envs: - - SAMPLE_APP_URL: https://github.com/bitrise-io/sample-apps-android-sdk22-subdir.git - - BRANCH: master - - GRADLE_BUILD_FILE_PATH: src/build.gradle - - GRADLEW_PATH: src/gradlew - steps: - - script: - inputs: - - content: |- - #!/usr/bin/env bash - set -e - rm -rf ./_tmp - - change-workdir: - title: Switch working dir to test / _tmp dir - run_if: true - inputs: - - path: ./_tmp - - is_create_path: true - - script: - inputs: - - content: |- - #!/usr/bin/env bash - if [[ -z "${SAMPLE_APP_URL}" ]]; then - echo "error: there is no SAMPLE_APP_URL env var specified" - exit 1 - elif [[ -z "${COMMIT}" && -z "${BRANCH}" ]]; then - echo "error: can't checkout: there is no BRANCH or COMMIT env var specified" - exit 1 - fi - git init - git remote add origin "${SAMPLE_APP_URL}" - git fetch || exit 1 - [[ -n "${COMMIT}" ]] && git checkout "${COMMIT}" || git checkout "${BRANCH}" - - path::./: - title: Step test - - audit-this-step: - steps: - - script: - inputs: - - content: |- - #!/usr/bin/env bash - set -ex - stepman audit --step-yml ./step.yml + - gradle_task: assembleDebug diff --git a/e2e/bitrise.yml b/e2e/bitrise.yml new file mode 100644 index 0000000..57f499a --- /dev/null +++ b/e2e/bitrise.yml @@ -0,0 +1,174 @@ +format_version: "11" +default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git + +workflows: + test_ndk: + summary: Test NDK compilation without specifying an NDK version in the step + envs: + - SAMPLE_APP_URL: https://github.com/bitrise-io/android-ndk-sample-project.git + - BRANCH: ndk22-compatible + - GRADLE_BUILD_FILE_PATH: ./build.gradle + - GRADLEW_PATH: ./gradlew + - ANDROID_NDK_HOME: "" + before_run: + - _setup + steps: + - script: + inputs: + - content: |- + #!/usr/bin/env bash + set -ex + rm -rf $ANDROID_HOME/ndk-bundle + after_run: + - _run_and_build + + test_react_native: + envs: + - SAMPLE_APP_URL: https://github.com/bitrise-io/Bitrise-React-Native-Sample.git + - BRANCH: master + - GRADLE_BUILD_FILE_PATH: android/build.gradle + - GRADLEW_PATH: android/gradlew + before_run: + - _setup + steps: + - script: + inputs: + - content: |- + #!/usr/bin/env bash + set -ex + yarn + after_run: + - _run_and_build + + test_ndk_install: + summary: Test installing multiple NDK revisions + envs: + - SAMPLE_APP_URL: https://github.com/bitrise-io/android-ndk-sample-project.git + - BRANCH: ndk22-compatible + - GRADLE_BUILD_FILE_PATH: build.gradle + - GRADLEW_PATH: ./gradlew + before_run: + - _setup + steps: + - path::./: + title: Execute step without NDK version + inputs: + - ndk_revision: "" + - path::./: + title: Execute step with NDK r18 + inputs: + - ndk_revision: "18" + - path::./: + title: Execute step again with NDK r18 + inputs: + - ndk_revision: "18" + - path::./: + title: Execute step with NDK r17 + inputs: + - ndk_revision: "17" + - path::./: + title: Execute step with NDK r22 + description: NDK r22 doesn't contain the platforms dir anymore + inputs: + - ndk_revision: "22" + - gradle-runner: + inputs: + - gradle_task: assembleDebug + + test_android-sdk21-tools-21.0.1: + envs: + - SAMPLE_APP_URL: https://github.com/bitrise-io/android-sdk21-tools-21.0.1.git + - BRANCH: master + - GRADLE_BUILD_FILE_PATH: build.gradle + - GRADLEW_PATH: ./gradlew + before_run: + - _setup + steps: + - path::./: + title: Execute step + # Not executing any Gradle build in this test because the SDK version used in this repo has a known issue and + # crashes the Gradle build (the issue is fixed in later SDK versions though) + + test_support_library: + envs: + - SAMPLE_APP_URL: https://github.com/bitrise-io/sample-apps-android-x.git + - BRANCH: master + - GRADLE_BUILD_FILE_PATH: build.gradle + - GRADLEW_PATH: ./gradlew + before_run: + - _setup + steps: + - script: + title: Uninstall Android SDK + inputs: + - content: |- + #!/usr/bin/env bash + sdkmanager --uninstall "extras;android;m2repository" + after_run: + - _run_and_build + + test_old_gradle: + envs: + - SAMPLE_APP_URL: https://github.com/bitrise-io/2048-android.git + - BRANCH: master + - GRADLE_BUILD_FILE_PATH: build.gradle + - GRADLEW_PATH: ./gradlew + before_run: + - _setup + after_run: + - _run_and_build + + test_android-sdk20: + summary: Test installing SDK platform 20 (not preinstalled on stacks) + envs: + - SAMPLE_APP_URL: https://github.com/bitrise-io/sample-apps-android-sdk20.git + - BRANCH: master + - GRADLE_BUILD_FILE_PATH: build.gradle + - GRADLEW_PATH: ./gradlew + before_run: + - _setup + steps: + - path::./: + title: Execute step + # Not executing any Gradle build in this test because the SDK version used in this repo has a known issue and + # crashes the Gradle build (the issue is fixed in later SDK versions though) + + test_android-sdk22-subdir: + envs: + - SAMPLE_APP_URL: https://github.com/bitrise-io/sample-apps-android-sdk22-subdir.git + - BRANCH: master + - GRADLE_BUILD_FILE_PATH: src/build.gradle + - GRADLEW_PATH: src/gradlew + before_run: + - _setup + after_run: + - _run_and_build + + _setup: + steps: + - script: + title: Clean _tmp dir + inputs: + - content: |- + #!/usr/bin/env bash + set -e + rm -rf ./_tmp + - change-workdir: + title: Switch working dir to _tmp + run_if: "true" + inputs: + - path: ./_tmp + - is_create_path: true + - git::https://github.com/bitrise-steplib/bitrise-step-simple-git-clone.git@master: + title: Clone sample app + inputs: + - repository_url: $SAMPLE_APP_URL + - clone_into_dir: . + - branch: $BRANCH + _run_and_build: + steps: + - path::./: + title: Execute step + - gradle-runner: + inputs: + - gradle_task: assembleDebug diff --git a/main.go b/main.go index 88f82dc..7fef228 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,6 @@ package main import ( "fmt" "os" - "path" "path/filepath" "runtime" "strings" @@ -19,7 +18,6 @@ import ( "github.com/hashicorp/go-version" ) -const platformDirName = "platforms" const androidNDKHome = "ANDROID_NDK_HOME" // Config ... @@ -109,10 +107,6 @@ func updateNDK(revision string) error { return err } - if err := ensureNDKPath(ndkHome); err != nil { - return err - } - if !inPath(ndkHome) { log.Printf("Append to $PATH") if err := tools.ExportEnvironmentWithEnvman("PATH", fmt.Sprintf("%s:%s", os.Getenv("PATH"), ndkHome)); err != nil { @@ -130,44 +124,6 @@ func updateNDK(revision string) error { return nil } -func ensureNDKPath(ndkHome string) error { - log.Printf("searching for platforms dir in %s", ndkHome) - var foundPDPath string - if err := filepath.Walk(ndkHome, func(currentPath string, info os.FileInfo, err error) error { - if err != nil { - return err - } - - if info.IsDir() && info.Name() == platformDirName { - foundPDPath = path.Dir(currentPath) - log.Printf("found platforms dir at %s", foundPDPath) - if foundPDPath != ndkHome { - return updateNDKPath(foundPDPath) - } - log.Printf("%s is a valid NDK dir, no need to update", foundPDPath) - return nil - } - return nil - }); err != nil { - return err - } - if foundPDPath == "" { - return fmt.Errorf("could not locate platform dir at ndk home: %s", ndkHome) - } - return nil -} - -func updateNDKPath(path string) error { - if err := os.Setenv(androidNDKHome, path); err != nil { - return fmt.Errorf("failed to add path key %s with value %s", androidNDKHome, path) - } - if err := tools.ExportEnvironmentWithEnvman(androidNDKHome, path); err != nil { - return fmt.Errorf("failed to export with envman key %s value %s", androidNDKHome, path) - } - log.Printf("updated NDK HOME path to %s", path) - return nil -} - func main() { // Input validation var config Config