diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a6e3102212a11c52555979b414a49583269397af..b61c48c88878ef179aa0edfb7abe9c409fb5bc2f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,13 +30,29 @@ check-pipeline-status: when: always script: - | + getLastSuccessful() { + python3 .gitlab-ci/getpipelineinfo.py \ + --access-token $CI_JOB_API_READ_TOKEN \ + --look-for latest-merge \ + --print-format commit-sha + } + if ! python3 .gitlab-ci/getpipelineinfo.py --access-token $CI_JOB_API_READ_TOKEN \ --look-for HEAD \ --print-format pipeline-id; then - echo "No successful pipeline found. Triggering new pipeline..." + echo "No successful pipeline found." + + REFERENCE_SHA="" + if getLastSuccessful; then + REFERENCE_SHA=$(getLastSuccessful); + echo "Triggering new pipeline against reference commit $REFERENCE_SHA." + else + echo "Latest successful pipeline not found. Trigger complete pipeline." + fi + curl --request POST --form "token=$CI_JOB_TOKEN" \ --form ref=$CI_COMMIT_BRANCH \ - --form "variables[CI_TEST_AGAINST_LAST_SUCCESSFUL]=true" \ + --form "variables[CI_REFERENCE_SHA]=$REFERENCE_SHA" \ "https://git.iws.uni-stuttgart.de/api/v4/projects/31/trigger/pipeline" else echo "Found successful pipeline for the current state of the branch. Not testing again." @@ -57,10 +73,8 @@ check-pipeline-status: include: .gitlab-ci/default.yml strategy: depend variables: - TRIGGER_SOURCE: $CI_PIPELINE_SOURCE - COMMIT_BRANCH: $CI_COMMIT_BRANCH MR_TARGET_BRANCH_NAME: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME - TEST_AGAINST_LAST_SUCCESSFUL: $CI_TEST_AGAINST_LAST_SUCCESSFUL + REFERENCE_SHA: $CI_REFERENCE_SHA rules: - if: $CI_PIPELINE_SOURCE == "schedule" when: always @@ -121,6 +135,7 @@ trigger lecture: branch: master strategy: depend variables: - DUMUX_PIPELINE_SOURCE: $CI_PIPELINE_SOURCE DUMUX_MERGE_REQUEST_SOURCE_BRANCH: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME DUMUX_MERGE_REQUEST_TARGET_BRANCH: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME + DUMUX_COMMIT_SHA: $CI_COMMIT_SHA + DUMUX_REFERENCE_SHA: $CI_REFERENCE_SHA diff --git a/.gitlab-ci/default.yml b/.gitlab-ci/default.yml index 36e5e7d9b228a58fc0ec2ef4591769b7dd515abc..15a7192fb4c6b00f8141b174faefbad0c6f7e911 100644 --- a/.gitlab-ci/default.yml +++ b/.gitlab-ci/default.yml @@ -12,23 +12,15 @@ workflow: # variables that should be overwritten by the trigger variables: - TRIGGER_SOURCE: "undefined" - COMMIT_BRANCH: "undefined" - MR_TARGET_BRANCH_NAME: "undefined" + MR_TARGET_BRANCH_NAME: "" + REFERENCE_SHA: "" select tests: stage: configure script: - dunecontrol --opts=$DUNE_OPTS_FILE --current all - | - getLastSuccesful() { - python3 .gitlab-ci/getpipelineinfo.py \ - --access-token $CI_JOB_API_READ_TOKEN \ - --look-for latest-merge \ - --print-format commit-sha - } - - if [[ "$TRIGGER_SOURCE" == "merge_request_event" ]]; then + if [[ -n "$MR_TARGET_BRANCH_NAME" ]]; then echo "Detecting changes w.r.t to target branch '$MR_TARGET_BRANCH_NAME'" python3 bin/testing/getchangedfiles.py --outfile changedfiles.txt \ --target-tree origin/$MR_TARGET_BRANCH_NAME @@ -36,30 +28,17 @@ select tests: --file-list changedfiles.txt \ --build-dir build-cmake - elif [[ "$TRIGGER_SOURCE" == "schedule" ]]; then - echo "Starting scheduled pipeline" - echo "Skipping test selection, build/test stages will consider all tests!" - touch affectedtests.json - - elif [ -n $TEST_AGAINST_LAST_SUCCESSFUL ]; then - echo "Determining sha of the last successful pipeline to test against" - - if ! getLastSuccesful; then - echo "Could not find a successful pipeline, will build/run all tests" - touch affectedtests.json - else - COMMIT_SHA=$(getLastSuccesful) - echo "Comparing against sha $COMMIT_SHA" - python3 bin/testing/getchangedfiles.py --outfile changedfiles.txt \ - --source-tree HEAD \ - --target-tree $COMMIT_SHA - python3 bin/testing/findtests.py --outfile affectedtests.json \ - --file-list changedfiles.txt \ - --build-dir build-cmake - fi + elif [[ -n "$REFERENCE_SHA" ]]; then + echo "Detecting changes w.r.t to reference commit $REFERENCE_SHA" + python3 bin/testing/getchangedfiles.py --outfile changedfiles.txt \ + --source-tree HEAD \ + --target-tree $REFERENCE_SHA + python3 bin/testing/findtests.py --outfile affectedtests.json \ + --file-list changedfiles.txt \ + --build-dir build-cmake else - echo "Unknown pipeline trigger event" + echo "No reference information given." echo "Skipping test selection, build/test stages will consider all tests!" touch affectedtests.json fi