diff options
| author | Menny Even Danan <menny@evendanan.net> | 2020-02-27 15:48:05 +0000 |
|---|---|---|
| committer | Menny Even Danan <menny@evendanan.net> | 2020-02-27 18:37:37 +0000 |
| commit | fb509d0111dc641f27b2ec2d9632e78a33a7b751 (patch) | |
| tree | 30f661c3f080a4f12607136c359bebdeb4dd512c | |
| parent | 870cb389c8e3d116eab9cd03d096efb034565eee (diff) | |
| download | AnySoftKeyboard-fb509d0111dc641f27b2ec2d9632e78a33a7b751.tar.gz AnySoftKeyboard-fb509d0111dc641f27b2ec2d9632e78a33a7b751.tar.bz2 | |
loggin build result
| -rwxr-xr-x | .github/actions/test-shard-run/run_tests.sh | 2 | ||||
| -rw-r--r-- | .github/workflows/checks.yml | 17 | ||||
| -rw-r--r-- | .github/workflows/third_party_update.yml | 5 | ||||
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | build.gradle | 18 | ||||
| -rw-r--r-- | buildSrc/src/main/java/BuildLogger.java | 119 | ||||
| -rwxr-xr-x | scripts/retry-on-SIGSEGV.sh | 21 |
7 files changed, 171 insertions, 14 deletions
diff --git a/.github/actions/test-shard-run/run_tests.sh b/.github/actions/test-shard-run/run_tests.sh index 1f312bbc0..66f54bcac 100755 --- a/.github/actions/test-shard-run/run_tests.sh +++ b/.github/actions/test-shard-run/run_tests.sh @@ -12,7 +12,7 @@ echo "Will run tests for module '${MODULE}' with extra args '${EXTRA_ARGS}' for #extra args needs to come before the coverage task so "--tests" will be passed to the test tasks # we automatically re-try on gradle crash -./scripts/retry-on-SIGSEGV.sh 2 6,134 ./gradlew "${MODULE}testDebugUnitTest" ${EXTRA_ARGS} "${MODULE}testDebugUnitTestCoverage" +./scripts/retry-on-SIGSEGV.sh 3 ./gradlew "${MODULE}testDebugUnitTest" ${EXTRA_ARGS} "${MODULE}testDebugUnitTestCoverage" #see https://github.com/actions/cache/issues/133 [[ -n "${GITHUB_ACTIONS}" ]] && chmod -R a+rwx . diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 2df749adc..b2712da6f 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -84,8 +84,13 @@ jobs: - uses: actions/upload-artifact@v1.0.0 if: always() with: - name: app-tests_${{ matrix.index }} + name: app-tests-${{ matrix.index }} path: collected_reports + - uses: actions/upload-artifact@v1.0.0 + if: always() + with: + name: app-tests-${{ matrix.index }}-build-logging + path: build-logging app-all-sdks-tests: runs-on: ubuntu-18.04 @@ -117,6 +122,11 @@ jobs: with: name: app-less-tests path: collected_reports + - uses: actions/upload-artifact@v1.0.0 + if: always() + with: + name: app-all-sdks-tests-build-logging + path: build-logging app-less-tests: runs-on: ubuntu-18.04 @@ -148,6 +158,11 @@ jobs: with: name: app-less-tests path: collected_reports + - uses: actions/upload-artifact@v1.0.0 + if: always() + with: + name: app-less-tests-build-logging + path: build-logging deploy-dry-run: if: github.event_name == 'pull_request' diff --git a/.github/workflows/third_party_update.yml b/.github/workflows/third_party_update.yml index 0bb08560e..efb410476 100644 --- a/.github/workflows/third_party_update.yml +++ b/.github/workflows/third_party_update.yml @@ -25,6 +25,7 @@ jobs: - name: verify-greps run: ./scripts/verify-third-party-update-greps.sh "${GREP_VERSION_CLASSES}" gradle-update: + if: github.event_name == 'schedule' runs-on: ubuntu-18.04 container: menny/ndk_ask:1.13.6 steps: @@ -57,6 +58,7 @@ jobs: assignees: menny branch: 'bot-pr/gradle-update' robolectric-update: + if: github.event_name == 'schedule' runs-on: ubuntu-18.04 container: menny/ndk_ask:1.13.6 steps: @@ -91,6 +93,7 @@ jobs: assignees: menny branch: 'bot-pr/robolectric-update' build-tools-update: + if: github.event_name == 'schedule' runs-on: ubuntu-18.04 container: menny/ndk_ask:1.13.6 steps: @@ -124,6 +127,7 @@ jobs: assignees: menny branch: 'bot-pr/build-tools-update' error-prone-update: + if: github.event_name == 'schedule' runs-on: ubuntu-18.04 container: menny/ndk_ask:1.13.6 steps: @@ -165,6 +169,7 @@ jobs: assignees: menny branch: 'bot-pr/error-prone-update' google-format-update: + if: github.event_name == 'schedule' runs-on: ubuntu-18.04 container: menny/ndk_ask:1.13.6 steps: diff --git a/.gitignore b/.gitignore index d552e0e0a..a4b29fa42 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ outputs/ add_ons_apks/ .robolectric-android-all-jars/ + +#gradle build loggin +build-logging/
\ No newline at end of file diff --git a/build.gradle b/build.gradle index 0fdc1fd8c..6ddd5d0ef 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,14 @@ System.setProperty("file.encoding", "UTF-8") +def logFile = rootProject.file("build-logging/build-log-${System.currentTimeMillis()}.log") +gradle.addBuildListener(new BuildLogger(logFile)) + buildscript { repositories { google() mavenLocal() jcenter() - maven { url 'https://repo1.maven.org/maven2' /*maven-central with HTTPS*/} + maven { url 'https://repo1.maven.org/maven2' /*maven-central with HTTPS*/ } maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } maven { url 'https://jitpack.io' } maven { url "https://plugins.gradle.org/m2/" } @@ -30,7 +33,7 @@ allprojects { repositories { google() mavenLocal() - maven { url 'https://repo1.maven.org/maven2' /*maven-central with HTTPS*/} + maven { url 'https://repo1.maven.org/maven2' /*maven-central with HTTPS*/ } jcenter() maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } maven { url "https://jitpack.io" } @@ -40,3 +43,14 @@ allprojects { apply from: "${rootDir}/gradle/emoji_generator.gradle" apply from: "${rootDir}/gradle/root_all_projects_ext.gradle" apply from: "${rootDir}/gradle/fdroid_yaml_output.gradle" + + +tasks.register("clean", Delete) { + delete buildDir + //we do not want to delete the current log file + logFile.parentFile.listFiles().each { + if (it != null && it.absolutePath != logFile.absolutePath) { + delete it + } + } +} diff --git a/buildSrc/src/main/java/BuildLogger.java b/buildSrc/src/main/java/BuildLogger.java new file mode 100644 index 000000000..a27ae92b9 --- /dev/null +++ b/buildSrc/src/main/java/BuildLogger.java @@ -0,0 +1,119 @@ +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; +import java.time.Instant; +import java.util.Locale; +import org.gradle.BuildListener; +import org.gradle.BuildResult; +import org.gradle.api.initialization.Settings; +import org.gradle.api.invocation.Gradle; +import org.gradle.api.tasks.TaskState; + +public class BuildLogger implements BuildListener { + + private final File mOutputFile; + + public BuildLogger(File outputFile) { + mOutputFile = outputFile; + if (mOutputFile.getParentFile().exists() || mOutputFile.getParentFile().mkdirs()) { + try { + try (OutputStreamWriter writer = + new OutputStreamWriter( + new FileOutputStream(mOutputFile, false), StandardCharsets.UTF_8)) { + writer.append("Build log created at ") + .append(Instant.now().toString()) + .append(System.lineSeparator()); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } else { + throw new IllegalStateException( + String.format( + Locale.ROOT, + "Can not create parent folder '%s' for logging!", + mOutputFile.getParentFile().getAbsolutePath())); + } + } + + @Override + public void buildStarted(Gradle gradle) {} + + @Override + public void settingsEvaluated(Settings settings) {} + + @Override + public void projectsLoaded(Gradle gradle) {} + + @Override + public void projectsEvaluated(Gradle gradle) { + StringBuilder log = new StringBuilder(); + log.append("Build started at ") + .append(Instant.now().toString()) + .append(System.lineSeparator()); + log.append("Gradle ").append(gradle.getGradleVersion()).append(System.lineSeparator()); + appendToFile(log.toString()); + } + + @Override + public void buildFinished(BuildResult buildResult) { + StringBuilder log = new StringBuilder(); + log.append("Build finished at ") + .append(Instant.now().toString()) + .append(System.lineSeparator()); + log.append("build action: ").append(buildResult.getAction()).append(System.lineSeparator()); + log.append("build result ") + .append( + buildResult.getFailure() != null + ? "FAILED with " + exceptionToString(buildResult.getFailure()) + : "SUCCESS") + .append(System.lineSeparator()); + log.append("build tasks:").append(System.lineSeparator()); + final Gradle gradle = buildResult.getGradle(); + if (gradle != null) { + gradle.getTaskGraph() + .getAllTasks() + .forEach( + t -> + log.append("* ") + .append(t.getPath()) + .append(" state: ") + .append(taskToString(t.getState())) + .append(System.lineSeparator())); + } + appendToFile(log.toString()); + } + + private static String taskToString(TaskState state) { + if (state.getSkipped()) return "SKIPPED"; + if (state.getNoSource()) return "NO-SOURCE"; + if (state.getUpToDate()) return "UP-TO-DATE"; + if (state.getFailure() != null) return "FAILED " + exceptionToString(state.getFailure()); + if (state.getExecuted()) return "EXECUTED"; + return "unknown"; + } + + private static String exceptionToString(Throwable throwable) { + StringBuilder builder = new StringBuilder(throwable.getMessage()); + while (throwable.getCause() != null) { + throwable = throwable.getCause(); + builder.append(" ]> ").append(throwable.getMessage()); + } + + return builder.toString(); + } + + private void appendToFile(String output) { + try { + try (OutputStreamWriter writer = + new OutputStreamWriter( + new FileOutputStream(mOutputFile, true), StandardCharsets.UTF_8)) { + writer.append(output); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/scripts/retry-on-SIGSEGV.sh b/scripts/retry-on-SIGSEGV.sh index 0f05c7e1d..a9aa5dcd8 100755 --- a/scripts/retry-on-SIGSEGV.sh +++ b/scripts/retry-on-SIGSEGV.sh @@ -2,19 +2,21 @@ retries=$1 shift -IFS=',' read -r -a retry_exit_codes_array <<< "$1" -retry_exit_codes=" ${retry_exit_codes_array[*]} " -shift -echo "Will retry '$*' for ${retries} when exit-codes are '${retry_exit_codes}':" +echo "Will retry '$*' for ${retries} times:" + +function needsRetry() { + local contents + contents=$(cat "$(ls -t build-logging/*.log | head -1)") + + [[ "$contents" =~ .*"finished with non-zero exit value 134".* ]] && echo "RETRY" +} + set +e count=0 -EXIT_CODE=0 -pwd "$@" EXIT_CODE=$? -echo "EXIT_CODE is ${EXIT_CODE}" -while [[ "${retry_exit_codes}" =~ .*" ${EXIT_CODE} ".* ]]; do +while needsRetry; do count=$((count + 1)) if [[ ${count} -lt ${retries} ]]; then echo "************** Retry ${count}/${retries} exited ${EXIT_CODE}, retrying in ${count} seconds..." @@ -25,7 +27,6 @@ while [[ "${retry_exit_codes}" =~ .*" ${EXIT_CODE} ".* ]]; do echo "EXIT_CODE is ${EXIT_CODE}" else echo "Retry ${count}/${retries} exited ${EXIT_CODE}, no more retries left." + exit ${EXIT_CODE} fi done - -exit ${EXIT_CODE}
\ No newline at end of file |
