From 22859e18863564d459ea9f72d5f23be43c5e7889 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Mon, 15 Nov 2021 13:24:42 +0800 Subject: [PATCH] ! update ci scripts, prepair for appveyor ci --- README-EN.md | 3 +- README.md | 3 +- appveyor.yml | 108 ++++++++++++++++++++++++------------ clear-appveyor-cache.ps1 | 29 ++++++++++ pom.xml | 6 -- pom4ide.xml | 6 -- scripts/codecov.sh | 2 +- scripts/common.sh | 8 +++ scripts/common_build.sh | 2 +- scripts/integration-test.sh | 4 ++ scripts/prepare-jdk.sh | 39 ++++++------- 11 files changed, 133 insertions(+), 77 deletions(-) create mode 100755 clear-appveyor-cache.ps1 diff --git a/README-EN.md b/README-EN.md index 99ea42876..d778403c7 100644 --- a/README-EN.md +++ b/README-EN.md @@ -1,7 +1,6 @@ # [![📌 TransmittableThreadLocal(TTL) 📌](docs/logo-blue.png)](#dummy) -[![Build Status](https://img.shields.io/travis/alibaba/transmittable-thread-local/master?logo=travis-ci&logoColor=white)](https://travis-ci.org/alibaba/transmittable-thread-local) -[![Windows Build Status](https://img.shields.io/appveyor/ci/oldratlee/transmittable-thread-local/master?label=windows%20build&logo=appveyor&logoColor=white)](https://ci.appveyor.com/project/oldratlee/transmittable-thread-local) +[![Build Status](https://img.shields.io/appveyor/ci/oldratlee/transmittable-thread-local/master?logo=appveyor&logoColor=white)](https://ci.appveyor.com/project/oldratlee/transmittable-thread-local) [![Coverage Status](https://img.shields.io/codecov/c/github/alibaba/transmittable-thread-local/master?logo=codecov&logoColor=white)](https://codecov.io/gh/alibaba/transmittable-thread-local/branch/master) [![Maintainability](https://badgen.net/codeclimate/maintainability/codeclimate/codeclimate?icon=codeclimate)](https://codeclimate.com/github/alibaba/transmittable-thread-local) [![JDK support](https://img.shields.io/badge/JDK-6+-green?logo=java&logoColor=white)](https://openjdk.java.net/) diff --git a/README.md b/README.md index 6b785a25f..68dccc942 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # [![📌 TransmittableThreadLocal(TTL) 📌](docs/logo-blue.png)](#dummy) -[![Build Status](https://img.shields.io/travis/alibaba/transmittable-thread-local/master?logo=travis-ci&logoColor=white)](https://travis-ci.org/alibaba/transmittable-thread-local) -[![Windows Build Status](https://img.shields.io/appveyor/ci/oldratlee/transmittable-thread-local/master?label=windows%20build&logo=appveyor&logoColor=white)](https://ci.appveyor.com/project/oldratlee/transmittable-thread-local) +[![Build Status](https://img.shields.io/appveyor/ci/oldratlee/transmittable-thread-local/master?logo=appveyor&logoColor=white)](https://ci.appveyor.com/project/oldratlee/transmittable-thread-local) [![Coverage Status](https://img.shields.io/codecov/c/github/alibaba/transmittable-thread-local/master?logo=codecov&logoColor=white)](https://codecov.io/gh/alibaba/transmittable-thread-local/branch/master) [![Maintainability](https://badgen.net/codeclimate/maintainability/codeclimate/codeclimate?icon=codeclimate)](https://codeclimate.com/github/alibaba/transmittable-thread-local) [![JDK support](https://img.shields.io/badge/JDK-6+-green?logo=java&logoColor=white)](https://openjdk.java.net/) diff --git a/appveyor.yml b/appveyor.yml index adc6449b0..04ee488cc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,43 +1,77 @@ +# How to use AppVeyor to build a multi-arch Docker image for Linux and Windows +# https://stefanscherer.github.io/use-appveyor-to-build-multi-arch-docker-image/ +# +# Building ASP.NET Core apps on both Windows and Linux using AppVeyor +# https://andrewlock.net/building-asp-net-core-apps-on-both-windows-and-linux-using-appveyor/ +# +# appveyor.yml Example: +# https://github.com/cdcseacave/openMVS/blob/master/.appveyor.yml + version: '{build}' -os: Windows Server 2012 -build: off +image: + - Ubuntu2004 + - Visual Studio 2017 +build: false clone_depth: 50 branches: except: - - travis-ci.* + - travis-ci + - gh-pages environment: - matrix: - - JAVA_HOME: "C:\\Program Files (x86)\\Java\\jdk1.8.0" - - JAVA_HOME: "C:\\Program Files\\Java\\jdk1.8.0" - - JAVA_HOME: "C:\\Program Files\\Java\\jdk9" - - JAVA_HOME: "C:\\Program Files\\Java\\jdk10" - - JAVA_HOME: "C:\\Program Files\\Java\\jdk11" - -init: - - ps: "ls 'C:/Program Files/Java/jdk*'" - - ps: "ls 'C:/Program Files (x86)/Java/jdk*'" - -install: - - cmd: SET PATH=%JAVA_HOME%\bin;%PATH% - - cmd: SET MAVEN_OPTS=-Xmx768m -XX:MaxPermSize=128m - - cmd: SET JAVA_OPTS=-Xmx768m -XX:MaxPermSize=128m - - "ECHO JAVA_HOME=%JAVA_HOME%, HOMEPATH=%HOMEPATH%, PATH=%PATH%" - - cmd: ./mvnw.cmd --version - -test_script: - - ./mvnw.cmd clean install --batch-mode - - ./mvnw.cmd dependency:copy-dependencies -DincludeScope=test -DexcludeArtifactIds=javassist,jsr305 - - echo "Run Agent test" - - ps: | - $ttl_jar=Get-ChildItem target\transmittable-thread-local-*.jar -Exclude *-sources.jar | Select-Object -ExpandProperty FullName - $cp=Get-ChildItem target\dependency\*.jar | Select-Object -ExpandProperty FullName - $cp=$cp + 'target\test-classes' - $cp=$cp -join ';' - echo "java -Xmx256m -Xms256m -javaagent:$ttl_jar -cp $cp -ea com.alibaba.ttl.threadpool.agent.AgentCheck" - $output=java -Xmx256m -Xms256m -javaagent:$ttl_jar -cp $cp -ea com.alibaba.ttl.threadpool.agent.AgentCheck 2>&1 - $output.CategoryInfo.TargetName | Out-Default - -cache: - - C:\maven\ - - C:\Users\appveyor\.m2\ + APPVEYOR_YML_DISABLE_PS_LINUX: true + MAVEN_OPTS: "-Xmx768m -XX:MaxPermSize=128m -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2" + JAVA_OPTS: "-Xmx768m -XX:MaxPermSize=128m" + +for: + - + #------------------ + # Ubuntu + #------------------ + matrix: + only: + - image: Ubuntu2004 + + test_script: + - sh: ./scripts/integration-test.sh + + after_test: + - sh: ./scripts/codecov.sh + - sh: rm -rf $HOME/.m2/repository/com/alibaba/transmittable-thread-local* + - sh: rm -rf $HOME/.m2/repository/com/alibaba/ttl* + - sh: rm -rf $HOME/.sdkman/archives/* + + cache: + # if cache size is exceed appveyor limit: + # Compressed cache item cannot exceed 1,048,576,000 bytes + # skip below maven cache: + - $HOME/.m2/ + - $HOME/.sdkman/ + - + #------------------ + # Windows + #------------------ + matrix: + only: + - image: Visual Studio 2017 + install: + - ps: "ls 'C:/Program Files/Java/jdk*'" + - ps: "ls 'C:/Program Files (x86)/Java/jdk*'" + - cmd: echo JAVA_HOME=%JAVA_HOME%, HOMEPATH=%HOMEPATH%, PATH=%PATH% + + test_script: + # test under java 8 + - cmd: set JAVA_HOME=C:\Program Files\Java\jdk1.8.0 + - ./mvnw.cmd -V clean install --no-transfer-progress + # test under java 11 + - cmd: set JAVA_HOME=C:\Program Files\Java\jdk11 + - ./mvnw.cmd -V clean install --no-transfer-progress + + after_test: + - ps: Remove-Item -r -fo $home\.m2\repository\com\alibaba\transmittable-thread-local* + - ps: Remove-Item -r -fo $home\.m2\repository\com\alibaba\ttl* + + cache: + # https://www.appveyor.com/docs/build-cache/ + - '%HOMEDRIVE%%HOMEPATH%\.m2\' + diff --git a/clear-appveyor-cache.ps1 b/clear-appveyor-cache.ps1 new file mode 100755 index 000000000..85a1e78d5 --- /dev/null +++ b/clear-appveyor-cache.ps1 @@ -0,0 +1,29 @@ +#!/usr/bin/env pwsh + +# https://stackoverflow.com/questions/24649019/how-to-use-confirm-in-powershell +$confirmation = Read-Host "Are you Sure You Want To Clear cache of appveyor project oldratlee/transmittable-thread-local" +if ($confirmation -ne 'y') { + Write-Output "do nothing and exit" + exit +} + +# PowerShell: Run command from script's directory - Stack Overflow +# https://stackoverflow.com/questions/4724290 +$script_path = $MyInvocation.MyCommand.Path +$script_dir = Split-Path $script_path + +# Equivalent of bash's `source` command in Powershell? - Super User +# https://superuser.com/questions/71446 +# Script scope and dot sourcing - PowerShell | Microsoft Docs +# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scripts#script-scope-and-dot-sourcing +. "$script_dir\appveyor_token.ps1" +# file appveyor_token.ps1 provide appveyor token. content sample: +# $appveyor_token = xxx + +# https://www.appveyor.com/docs/build-cache/#remove-cache-entry-from-build-config +# https://www.appveyor.com/docs/api/#authentication + +$headers = @{} +$headers['Authorization'] = "Bearer $appveyor_token" +$headers["Content-type"] = "application/json" +Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/projects/oldratlee/transmittable-thread-local/buildcache' -Headers $headers -Method Delete diff --git a/pom.xml b/pom.xml index f9c97aa05..23d96cfdc 100644 --- a/pom.xml +++ b/pom.xml @@ -642,12 +642,6 @@ gen-code-cov - - - env.TRAVIS - true - - diff --git a/pom4ide.xml b/pom4ide.xml index f3581ea70..e26fde806 100644 --- a/pom4ide.xml +++ b/pom4ide.xml @@ -642,12 +642,6 @@ gen-code-cov - - - env.TRAVIS - true - - diff --git a/scripts/codecov.sh b/scripts/codecov.sh index 1b538712f..0c473a29e 100755 --- a/scripts/codecov.sh +++ b/scripts/codecov.sh @@ -11,6 +11,6 @@ source ./ttl_build.sh switch_to_jdk 8 MVN_WITH_BASIC_OPTIONS clean -MVN_WITH_BASIC_OPTIONS cobertura:cobertura +MVN_WITH_BASIC_OPTIONS -Pgen-code-cov cobertura:cobertura bash <(curl -s https://codecov.io/bash) diff --git a/scripts/common.sh b/scripts/common.sh index d76ab1826..836069462 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -78,6 +78,14 @@ versionLessThan() { [ "$(printf '%s\n' "$ver" "$destVer" | sort -V | head -n1)" = "$ver" ] } +loose() { + set +eEuo pipefail + "$@" + local exit_code=$? + set -eEuo pipefail + return $exit_code +} + logAndRun() { local simple_mode=false [ "$1" = "-s" ] && { diff --git a/scripts/common_build.sh b/scripts/common_build.sh index d0a6d7db9..626c5151c 100644 --- a/scripts/common_build.sh +++ b/scripts/common_build.sh @@ -36,7 +36,7 @@ __getMvnwExe() { } __getJavaVersion() { - "$JAVA_HOME/bin/java" -version 2>&1 | awk -F\" 'NR == 1 {print $2}' + "$JAVA_HOME/bin/java" -version 2>&1 | awk -F\" '/ version "/{print $2}' } __getMoreMvnOptionsWhenJdk11() { diff --git a/scripts/integration-test.sh b/scripts/integration-test.sh index afad96d2c..e16420b78 100755 --- a/scripts/integration-test.sh +++ b/scripts/integration-test.sh @@ -7,15 +7,19 @@ export TTL_CI_TEST_MODE=true source ./prepare-jdk.sh source ./ttl_build.sh "${1:-}" + # default jdk 11, do build and test switch_to_jdk 11 headInfo "test with Java 11: $JAVA_HOME" # run junit test in run-agent-test.sh logAndRun ./scripts/run-agent-test.sh skipClean + # test multi-version java home env # shellcheck disable=SC2154 for jhm_var_name in "${java_home_var_names[@]}"; do + [ "$jhm_var_name" = "JDK11_HOME" ] && continue + export JAVA_HOME="${!jhm_var_name}" headInfo "test with $jhm_var_name: $JAVA_HOME" diff --git a/scripts/prepare-jdk.sh b/scripts/prepare-jdk.sh index 80c0c3954..4e56f31ab 100644 --- a/scripts/prepare-jdk.sh +++ b/scripts/prepare-jdk.sh @@ -25,37 +25,32 @@ __loadSdkman() { this_time_install_sdk_man=true fi - set +u + logAndRun cat "$HOME/.sdkman/etc/config" + # shellcheck disable=SC1090 - source "$HOME/.sdkman/bin/sdkman-init.sh" - "$this_time_install_sdk_man" && logAndRun sdk ls java - set -u + loose source "$HOME/.sdkman/bin/sdkman-init.sh" + + if "$this_time_install_sdk_man"; then + loose logAndRun sdk ls java | sed -n '/^ Vendor/,/^===========/p' + fi } __loadSdkman jdks_install_by_sdkman=( - 7.0.302-zulu - 8.0.292-zulu - - 9.0.7-zulu - 10.0.2-zulu - 11.0.11-zulu - - 12.0.2-open - 13.0.5-zulu - 14.0.2-zulu - 15.0.2-zulu - 16.0.1-open - 17.ea.21-open + 6.0.119-zulu + 7.0.322-zulu + 8.312.07.1-amzn + + 11.0.13-ms + + 16.0.2.7.1-amzn + 17.0.1-ms ) java_home_var_names=() __setJdkHomeVarsAndInstallJdk() { blueEcho "prepared jdks:" - JDK6_HOME="${JDK6_HOME:-/usr/lib/jvm/java-6-openjdk-amd64}" - java_home_var_names=(JDK6_HOME) - printf '%s :\n\t%s\n' "JDK6_HOME" "${JDK6_HOME}" local jdkNameOfSdkman for jdkNameOfSdkman in "${jdks_install_by_sdkman[@]}"; do @@ -74,12 +69,12 @@ __setJdkHomeVarsAndInstallJdk() { # install jdk by sdkman [ ! -d "$jdkHomePath" ] && { set +u - logAndRun sdk install java "$jdkNameOfSdkman" || die "fail to install jdk $jdkNameOfSdkman by sdkman" + loose logAndRun sdk install java "$jdkNameOfSdkman" || die "fail to install jdk $jdkNameOfSdkman by sdkman" set -u } fi - java_home_var_names=("${java_home_var_names[@]}" "$jdkHomeVarName") + java_home_var_names=(${java_home_var_names[@]:+"${java_home_var_names[@]}"} "$jdkHomeVarName") printf '%s :\n\t%s\n\tspecified is %s\n' "$jdkHomeVarName" "${!jdkHomeVarName}" "$jdkNameOfSdkman" done