From 7d7b5b49c591c10ab8c9a94a0a0abbbb13d5ea71 Mon Sep 17 00:00:00 2001 From: Soren Rasmussen Date: Thu, 25 Jul 2024 11:48:26 -0600 Subject: [PATCH] Docker will checkout PR if being run during PR CI --- .github/workflows/ci_test_docker.yml | 4 +++- docker/Dockerfile | 23 +++++++++++++++++------ scm/src/run_scm.py | 12 ++++++------ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci_test_docker.yml b/.github/workflows/ci_test_docker.yml index 51991a10d..730a5381c 100644 --- a/.github/workflows/ci_test_docker.yml +++ b/.github/workflows/ci_test_docker.yml @@ -4,6 +4,7 @@ on: [pull_request,workflow_dispatch] env: TEST_TAG: dtcenter/ccpp-scm:test + PR_NUMBER: ${{ github.event.number }} jobs: docker: @@ -22,8 +23,9 @@ jobs: file: docker/Dockerfile load: true tags: ${{ env.TEST_TAG }} + build-args: PR_NUMBER=${{ github.event.number }} - name: Test run: | mkdir $HOME/output chmod a+rw $HOME/output - docker run --rm -v $HOME/output:/home ${{ env.TEST_TAG }} ./run_scm.py -f ../../test/rt_test_cases.py --runtime_mult 0.1 -d -a + docker run --rm -v $HOME/output:/home ${{ env.TEST_TAG }} ./run_scm.py -f ../../test/rt_test_cases.py --runtime_mult 0.1 -d --stop_on_error diff --git a/docker/Dockerfile b/docker/Dockerfile index 85ad4d856..f269fff5f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,8 +1,10 @@ FROM debian:12 LABEL maintainer="Michael Kavulich " -# Set up base OS environment +# arguments that can be passed in +ARG PR_NUMBER +# Set up base OS environment RUN apt-get -y update # Get "essential" tools and libraries @@ -70,11 +72,20 @@ ENV sp_ROOT=/comsoftware/nceplibs ENV w3emc_ROOT=/comsoftware/nceplibs # Obtain CCPP SCM source code, build code, and download static data -RUN cd /comsoftware \ - && git clone --recursive -b main https://github.com/NCAR/ccpp-scm \ - && mkdir /comsoftware/ccpp-scm/scm/bin - -RUN cd /comsoftware/ccpp-scm/scm/bin \ +RUN if [ -z "$PR_NUMBER" ]; then \ + cd /comsoftware \ + && git clone --recursive -b main https://github.com/NCAR/ccpp-scm; \ + else \ + cd /comsoftware \ + && git clone https://github.com/NCAR/ccpp-scm \ + && cd ccpp-scm \ + && git fetch origin pull/${PR_NUMBER}/head:test_pr \ + && git checkout test_pr \ + && git submodule update --init --recursive; \ + fi + +RUN mkdir /comsoftware/ccpp-scm/scm/bin \ + && cd /comsoftware/ccpp-scm/scm/bin \ && cmake ../src \ && make -j diff --git a/scm/src/run_scm.py b/scm/src/run_scm.py index 35222f168..40c658843 100755 --- a/scm/src/run_scm.py +++ b/scm/src/run_scm.py @@ -34,6 +34,7 @@ # Default command string to run MPI apps (number of processes should be 1 since SCM is not set up to use more than 1 yet) DEFAULT_MPI_COMMAND = 'mpirun -np 1' + # Copy executable to run directory if true (otherwise it will be linked) COPY_EXECUTABLE = False @@ -120,7 +121,7 @@ parser.add_argument('--n_itt_out', help='period of instantaneous output (number of timesteps)', required=False, type=int) parser.add_argument('--n_itt_diag', help='period of diagnostic output (number of timesteps)', required=False, type=int) parser.add_argument('-dt', '--timestep', help='timestep (s)', required=False, type=float) -parser.add_argument('-a', '--actions', help='if running from Github Actions this will select correct configuration', required=False, action='store_true') +parser.add_argument('--stop_on_error', help='when running multiple SCM runs, stop on first error', required=False, action='store_true') parser.add_argument('-v', '--verbose', help='set logging level to debug and write log to file', action='count', default=0) parser.add_argument('-f', '--file', help='name of file where SCM runs are defined') parser.add_argument('--mpi_command', help='command used to invoke the executable via MPI (including options)', required=False) @@ -191,14 +192,14 @@ def parse_arguments(): bin_dir = args.bin_dir timestep = args.timestep mpi_command = args.mpi_command - github_actions = args.actions + stop_on_error = args.stop_on_error if not sdf: sdf = DEFAULT_SUITE return (file, case, sdf, namelist, tracers, gdb, runtime, runtime_mult, docker, \ verbose, levels, npz_type, vert_coord_file, case_data_dir, n_itt_out, \ - n_itt_diag, run_dir, bin_dir, timestep, mpi_command, github_actions) + n_itt_diag, run_dir, bin_dir, timestep, mpi_command, stop_on_error) def find_gdb(): """Detect gdb, abort if not found""" @@ -767,7 +768,7 @@ def copy_outdir(exp_dir): def main(): (file, case, sdf, namelist, tracers, use_gdb, runtime, runtime_mult, docker, \ verbose, levels, npz_type, vert_coord_file, case_data_dir, n_itt_out, \ - n_itt_diag, run_dir, bin_dir, timestep, mpi_command, github_actions) = parse_arguments() + n_itt_diag, run_dir, bin_dir, timestep, mpi_command, stop_on_error) = parse_arguments() setup_logging(verbose) @@ -884,8 +885,7 @@ def main(): l_ignore_error = MULTIRUN_IGNORE_ERROR else: l_ignore_error = False - # need to correctly fail if running Github Actions - if github_actions: + if stop_on_error: l_ignore_error = False (status, time_elapsed) = launch_executable(use_gdb, gdb, mpi_command, ignore_error = l_ignore_error)