From 01bfa8c754e7a1e3cae41bd9fe7a9057518d8935 Mon Sep 17 00:00:00 2001 From: Camden Narzt Date: Mon, 30 Sep 2024 10:55:32 -0600 Subject: [PATCH] try to fix jenkins compat with GHA since migration is going slow --- dev/ci/lib/functions.sh | 35 ++++++++++++++++++------ dev/ci/lib/set-container-envvars.sh | 38 +++++++++++++++++---------- dev/ci/lib/setup-container.sh | 9 ++++++- dev/ci/setup-host | 5 ++-- dev/ci/tests/homebrew-packaging/setup | 19 +++++++++++--- 5 files changed, 78 insertions(+), 28 deletions(-) diff --git a/dev/ci/lib/functions.sh b/dev/ci/lib/functions.sh index 58adfd670d..8acb4ad3df 100644 --- a/dev/ci/lib/functions.sh +++ b/dev/ci/lib/functions.sh @@ -80,8 +80,18 @@ function autodetect_environment() if [ "${GITHUB_ACTIONS:-false}" = "true" ]; then echo "Running in Github Actions: yes" export CACHE_DIR="$RUNNER_TOOL_CACHE/$GITHUB_JOB/$RUNNER_OS" + elif [[ "$JENKINS_HOME" != "" ]]; then + echo "Running in Jenkins: yes" + export IN_JEKINS=true + if [ $OS = "linux" ]; then + export CACHE_DIR="$JENKINS_HOME/cache/$JOB_NAME/executor-$EXECUTOR_NUMBER" + else + require_envvar WORKSPACE "$WORKSPACE" + export CACHE_DIR="$WORKSPACE/cache/$JOB_NAME/executor-$EXECUTOR_NUMBER" + fi else - echo "Running in Github Actions: no" + echo "Running in CI: no" + export IN_JENKINS=false export CACHE_DIR="$PASSENGER_ROOT/.ci_cache" fi echo "Cache directory: $CACHE_DIR" @@ -89,20 +99,29 @@ function autodetect_environment() function sanity_check_environment() { - if [ "${GITHUB_ACTIONS:-false}" = "true" ]; then + if $IN_JENKINS; then + if [[ "$JOB_NAME" = "" ]]; then + echo "ERROR: Jenkins environment detected, but JOB_NAME environment variable not set." >&2 + return 1 + fi + if [[ "$EXECUTOR_NUMBER" = "" ]]; then + echo "ERROR: Jenkins environment detected, but EXECUTOR_NUMBER environment variable not set." >&2 + return 1 + fi + elif [ "${GITHUB_ACTIONS:-false}" = "true" ]; then if [ -z "$GITHUB_JOB" ]; then echo "ERROR: Github Actions environment detected, but GITHUB_JOB environment variable not set." >&2 return 1 - else - export "JOB_NAME=$GITHUB_JOB" + else + export "JOB_NAME=$GITHUB_JOB" fi if [ -z "$GITHUB_RUN_ID" ]; then echo "ERROR: Github Actions environment detected, but GITHUB_RUN_ID environment variable not set." >&2 return 1 - else - export "EXECUTOR_NUMBER=$GITHUB_RUN_ID" + else + export "EXECUTOR_NUMBER=$GITHUB_RUN_ID" fi - fi + fi } # The following is necessary to make the C++ tests work. @@ -112,7 +131,7 @@ function sanity_check_environment() function add_bundler_path_to_gem_path() { local bundle_path - + if bundle_path=$(bundle show rake); then bundle_path=$(dirname "$bundle_path") bundle_path=$(dirname "$bundle_path") diff --git a/dev/ci/lib/set-container-envvars.sh b/dev/ci/lib/set-container-envvars.sh index 50626f25a6..14836c2ab8 100644 --- a/dev/ci/lib/set-container-envvars.sh +++ b/dev/ci/lib/set-container-envvars.sh @@ -24,30 +24,40 @@ export CCACHE_LOGFILE="$(pwd)/buildout/testlogs/ccache.log" export NOEXEC_DISABLE=1 if [[ "$EXECUTOR_NUMBER" != "" ]]; then +if [ "${GITHUB_ACTIONS:-false}" = "false" ]; then + (( TEST_PORT_BASE=64000+EXECUTOR_NUMBER*10 )) +else (( TEST_PORT_BASE=64000 )) +fi export TEST_PORT_BASE fi -if [[ "$OS" != macos ]]; then +if [[ "$OS" = macos ]]; then + if [ "${GITHUB_ACTIONS:-false}" = "false" ]; then + # Ensure that Homebrew tools can be found + eval "$(/usr/libexec/path_helper -s)" + fi +else export LC_CTYPE=C.UTF-8 fi if [[ -f ~/.rvm/scripts/rvm ]]; then - # shellcheck source=/dev/null - source ~/.rvm/scripts/rvm + # shellcheck source=/dev/null + source ~/.rvm/scripts/rvm elif [[ -f /usr/local/rvm/scripts/rvm ]]; then - # shellcheck source=/dev/null - source /usr/local/rvm/scripts/rvm + # shellcheck source=/dev/null + source /usr/local/rvm/scripts/rvm fi if command -v rvm; then - if [[ "$TEST_RUBY_VERSION" != "" ]]; then - header2 "Using Ruby version $TEST_RUBY_VERSION" - run rvm use "$TEST_RUBY_VERSION" - echo - fi - # RVM's cd override causes problems (probably thanks to bash - # error handling being weird and quirky: - # https://news.ycombinator.com/item?id=14321213) - unset cd +if [[ "$TEST_RUBY_VERSION" != "" ]]; then + header2 "Using Ruby version $TEST_RUBY_VERSION" + run rvm use "$TEST_RUBY_VERSION" + echo +fi + +# RVM's cd override causes problems (probably thanks to bash +# error handling being weird and quirky: +# https://news.ycombinator.com/item?id=14321213) +unset cd fi diff --git a/dev/ci/lib/setup-container.sh b/dev/ci/lib/setup-container.sh index 2b72b7b33a..e0271d0310 100644 --- a/dev/ci/lib/setup-container.sh +++ b/dev/ci/lib/setup-container.sh @@ -18,9 +18,16 @@ header2 "Creating test/config.json" if [[ "$OS" = linux ]]; then run cp test/config.json.travis test/config.json else + + if [ "${GITHUB_ACTIONS:-false}" = "true" ]; then + KEYCHAIN_PATH='/Library/Keychains/System.keychain' + else + KEYCHAIN_PATH='~/Library/Keychains/login.keychain-db' + fi + sed \ -e "s/_AUTHORITY_/Developer/" \ - -e "s|_KEYCHAIN_|/Library/Keychains/System.keychain|" \ + -e "s|_KEYCHAIN_|$KEYCHAIN_PATH|" \ -e "s/_USER_/$USER/" \ test/config.json.travis-osx > test/config.json fi diff --git a/dev/ci/setup-host b/dev/ci/setup-host index b1ee944e6f..fbed8658d4 100755 --- a/dev/ci/setup-host +++ b/dev/ci/setup-host @@ -19,7 +19,7 @@ if [[ "$OS" = macos && "$1" = "" ]]; then exit 1 fi -if [ "${GITHUB_ACTIONS:-false}" = "true" ]; then +if [ "${CI:-false}" = "true" ]; then # Relax permissions. Necessary for unit tests which test permissions. header2 "Relaxing file permissions" echo "+ Setting umask" @@ -31,9 +31,10 @@ if [ "${GITHUB_ACTIONS:-false}" = "true" ]; then find ./* -type d -print0 | xargs -0 -n 512 chmod g+rx,o+rx # Create this file now because otherwise it would be owned by root, + # which CI runner cannot remove. run touch test/test.log - if [ "$OS" = "macos" ]; then + if [ "${GITHUB_ACTIONS:-false}" = "true" ] && [ "$OS" = "macos" ]; then brew update brew install ccache sudo security authorizationdb write com.apple.trust-settings.admin allow diff --git a/dev/ci/tests/homebrew-packaging/setup b/dev/ci/tests/homebrew-packaging/setup index 8208009507..7dcb2b2c72 100644 --- a/dev/ci/tests/homebrew-packaging/setup +++ b/dev/ci/tests/homebrew-packaging/setup @@ -1,13 +1,26 @@ #!/usr/bin/env bash set -e -if ! gem list | grep -qE '^rack '; then +if command -v rvm-exec; then + GEM_COMMAND='rvm-exec system gem' + RAKE_COMMAND='rvm-exec system rake' + SUDO_COMMAND='rvmsudo' +else + GEM_COMMAND='gem' + RAKE_COMMAND='rake' + SUDO_COMMAND='sudo' +fi + +# rvm or system ruby +if ! $GEM_COMMAND list | grep -qE '^rack '; then # The native packaging test runs passenger-install-*-module with the system Ruby, # which in turn requires the 'rack' gem to be installed in the system Ruby's # default RubyGems path. 'rake test:install_deps' installs to a local bundler # directory but not to the default RubyGems path. - retry_run 3 sudo gem install rack --no-document + export rvmsudo_secure_path=0 + retry_run 3 $SUDO_COMMAND $GEM_COMMAND install rack --no-document fi -retry_run 3 rake test:install_deps DEVDEPS_DEFAULT=no BASE_DEPS=yes SUDO=yes +retry_run 3 $RAKE_COMMAND test:install_deps DEVDEPS_DEFAULT=no BASE_DEPS=yes SUDO=yes +# just system ruby retry_run 3 gem install bundler -v '~>1.0' --no-document retry_run 3 rake test:install_deps BASE_DEPS=yes