diff --git a/.circleci/config.yml b/.circleci/config.yml index 5fef4d6..cf30062 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,19 +37,27 @@ commands: upgrade: type: string default: "" + branch_path: + type: string + default: "" + steps: - run: name: Run basic tests command: | .circleci/integration-test.py run-test basic-tests \ test_hub.py test_install.py test_extensions.py \ - << parameters.upgrade >> + << parameters.upgrade >> << parameters.branch_path >> admin_tests: parameters: upgrade: type: string default: "" + branch_path: + type: string + default: "" + steps: - run: name: Run admin tests @@ -57,13 +65,17 @@ commands: .circleci/integration-test.py run-test \ --installer-args "--admin admin:admin" \ basic-tests test_admin_installer.py \ - << parameters.upgrade >> + << parameters.upgrade >> << parameters.branch_path >> plugin_tests: parameters: upgrade: type: string default: "" + branch_path: + type: string + default: "" + steps: - run: name: Run plugin tests @@ -80,6 +92,15 @@ commands: command: | py.test integration-tests/test_bootstrap.py + get_pr_branch: + steps: + - run: + name: Get PR branch + command: | + CIRCLE_PR_BRANCH=`curl -s https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER} \ + | grep '"ref":' | grep -v "master" | cut -d '"' -f4' + + jobs: unit-test: executor: ubuntu_docker @@ -127,19 +148,25 @@ jobs: command: | apk add --no-cache python3 pytest + - get_pr_branch + - checkout - setup_remote_docker - build_systemd_image - - basic-tests + - basic-tests: + branch_path: "git+https://github.com/{CIRCLE_PROJECT_USERNAME}/the-littlest-jupyterhub.git@${CIRCLE_PR_BRANCH}" - - admin_tests + - admin_tests: + branch_path: "git+https://github.com/{CIRCLE_PROJECT_USERNAME}/the-littlest-jupyterhub.git@${CIRCLE_PR_BRANCH}" - - plugin_tests + - plugin_tests: + branch_path: "git+https://github.com/{CIRCLE_PROJECT_USERNAME}/the-littlest-jupyterhub.git@${CIRCLE_PR_BRANCH}" - - bootstrap_checks + - bootstrap_checks: + branch_path: "git+https://github.com/{CIRCLE_PROJECT_USERNAME}/the-littlest-jupyterhub.git@${CIRCLE_PR_BRANCH}" upgrade-test: @@ -152,6 +179,8 @@ jobs: command: | apk add --no-cache python3 pytest + - get_pr_branch + - checkout - setup_remote_docker @@ -160,12 +189,15 @@ jobs: - basic-tests: upgrade: "--upgrade" + branch_path: "git+https://github.com/{CIRCLE_PROJECT_USERNAME}/the-littlest-jupyterhub.git@${CIRCLE_PR_BRANCH}" - admin_tests: upgrade: "--upgrade" + branch_path: "git+https://github.com/{CIRCLE_PROJECT_USERNAME}/the-littlest-jupyterhub.git@${CIRCLE_PR_BRANCH}" - plugin_tests: upgrade: "--upgrade" + branch_path: "git+https://github.com/{CIRCLE_PROJECT_USERNAME}/the-littlest-jupyterhub.git@${CIRCLE_PR_BRANCH}" documentation: diff --git a/.circleci/integration-test.py b/.circleci/integration-test.py index 7968533..fee8297 100755 --- a/.circleci/integration-test.py +++ b/.circleci/integration-test.py @@ -15,7 +15,7 @@ def build_systemd_image(image_name, source_path): ]) -def run_systemd_image(image_name, container_name): +def run_systemd_image(image_name, container_name, branch_path): """ Run docker image with systemd @@ -23,7 +23,7 @@ def run_systemd_image(image_name, container_name): Container named container_name will be started. """ - subprocess.check_call([ + cmd = [ 'docker', 'run', '--privileged', '--mount', 'type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup', @@ -34,7 +34,12 @@ def run_systemd_image(image_name, container_name): # If we change this, need to change all other references to this number. '--memory', '1G', image_name - ]) + ] + + if branch_path: + cmd.append('-e', f'TLJH_BOOTSTRAP_PIP_SPEC="{branch_path}"') + + subprocess.check_call(cmd) def stop_container(container_name): @@ -74,12 +79,12 @@ def copy_to_container(container_name, src_path, dest_path): ]) -def run_test(image_name, test_name, test_files, installer_args): +def run_test(image_name, test_name, branch_path, test_files, upgrade, installer_args): """ Wrapper that sets up tljh with installer_args & runs test_name """ stop_container(test_name) - run_systemd_image(image_name, test_name) + run_systemd_image(image_name, test_name, branch_path) source_path = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir) @@ -87,10 +92,20 @@ def run_test(image_name, test_name, test_files, installer_args): copy_to_container(test_name, os.path.join(source_path, 'bootstrap/.'), '/srv/src') copy_to_container(test_name, os.path.join(source_path, 'integration-tests/'), '/srv/src') + + + # Install TLJH master first to test upgrades + if upgrade: + run_container_command( + test_name, + f'curl https://raw.githubusercontent.com/jupyterhub/the-littlest-jupyterhub/master/bootstrap/bootstrap.py | python3 -' + ) + run_container_command( test_name, f'python3 /srv/src/bootstrap.py {installer_args}' ) + # Install pkgs from requirements in hub's pip, where # the bootstrap script installed the others run_container_command( @@ -140,7 +155,9 @@ def main(): run_test_parser = subparsers.add_parser('run-test') run_test_parser.add_argument('--installer-args', default='') + run_test_parser.add_argument('--upgrade', action='store_true') run_test_parser.add_argument('test_name') + run_test_parser.add_argument('branch_path') run_test_parser.add_argument('test_files', nargs='+') show_logs_parser = subparsers.add_parser('show-logs') @@ -151,7 +168,7 @@ def main(): image_name = 'tljh-systemd' if args.action == 'run-test': - run_test(image_name, args.test_name, args.test_files, args.installer_args) + run_test(image_name, args.test_name, args.branch_path, args.test_files, args.upgrade, args.installer_args) elif args.action == 'show-logs': show_logs(args.container_name) elif args.action == 'run': @@ -159,7 +176,7 @@ def main(): elif args.action == 'copy': copy_to_container(args.container_name, args.src, args.dest) elif args.action == 'start-container': - run_systemd_image(image_name, args.container_name) + run_systemd_image(image_name, args.container_name, args.branch_path) elif args.action == 'stop-container': stop_container(args.container_name) elif args.action == 'build-image':