Skip to content
Snippets Groups Projects
Commit f2ce1f8d authored by Dennis Gläser's avatar Dennis Gläser Committed by Timo Koch
Browse files

[ci] find ref commit in check-pipeline

This allows us to psas that reference commit downstream to e.g.
dumux-lecture
parent 680f07eb
No related branches found
No related tags found
1 merge request!2663[ci] find ref commit in check-pipeline
Pipeline #4921 waiting for manual action
...@@ -30,13 +30,29 @@ check-pipeline-status: ...@@ -30,13 +30,29 @@ check-pipeline-status:
when: always when: always
script: 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 \ if ! python3 .gitlab-ci/getpipelineinfo.py --access-token $CI_JOB_API_READ_TOKEN \
--look-for HEAD \ --look-for HEAD \
--print-format pipeline-id; then --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" \ curl --request POST --form "token=$CI_JOB_TOKEN" \
--form ref=$CI_COMMIT_BRANCH \ --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" "https://git.iws.uni-stuttgart.de/api/v4/projects/31/trigger/pipeline"
else else
echo "Found successful pipeline for the current state of the branch. Not testing again." echo "Found successful pipeline for the current state of the branch. Not testing again."
...@@ -57,10 +73,8 @@ check-pipeline-status: ...@@ -57,10 +73,8 @@ check-pipeline-status:
include: .gitlab-ci/default.yml include: .gitlab-ci/default.yml
strategy: depend strategy: depend
variables: variables:
TRIGGER_SOURCE: $CI_PIPELINE_SOURCE
COMMIT_BRANCH: $CI_COMMIT_BRANCH
MR_TARGET_BRANCH_NAME: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME 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: rules:
- if: $CI_PIPELINE_SOURCE == "schedule" - if: $CI_PIPELINE_SOURCE == "schedule"
when: always when: always
...@@ -121,6 +135,7 @@ trigger lecture: ...@@ -121,6 +135,7 @@ trigger lecture:
branch: master branch: master
strategy: depend strategy: depend
variables: variables:
DUMUX_PIPELINE_SOURCE: $CI_PIPELINE_SOURCE
DUMUX_MERGE_REQUEST_SOURCE_BRANCH: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME DUMUX_MERGE_REQUEST_SOURCE_BRANCH: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
DUMUX_MERGE_REQUEST_TARGET_BRANCH: $CI_MERGE_REQUEST_TARGET_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
...@@ -12,23 +12,15 @@ workflow: ...@@ -12,23 +12,15 @@ workflow:
# variables that should be overwritten by the trigger # variables that should be overwritten by the trigger
variables: variables:
TRIGGER_SOURCE: "undefined" MR_TARGET_BRANCH_NAME: ""
COMMIT_BRANCH: "undefined" REFERENCE_SHA: ""
MR_TARGET_BRANCH_NAME: "undefined"
select tests: select tests:
stage: configure stage: configure
script: script:
- dunecontrol --opts=$DUNE_OPTS_FILE --current all - dunecontrol --opts=$DUNE_OPTS_FILE --current all
- | - |
getLastSuccesful() { if [[ -n "$MR_TARGET_BRANCH_NAME" ]]; then
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
echo "Detecting changes w.r.t to target branch '$MR_TARGET_BRANCH_NAME'" echo "Detecting changes w.r.t to target branch '$MR_TARGET_BRANCH_NAME'"
python3 bin/testing/getchangedfiles.py --outfile changedfiles.txt \ python3 bin/testing/getchangedfiles.py --outfile changedfiles.txt \
--target-tree origin/$MR_TARGET_BRANCH_NAME --target-tree origin/$MR_TARGET_BRANCH_NAME
...@@ -36,30 +28,17 @@ select tests: ...@@ -36,30 +28,17 @@ select tests:
--file-list changedfiles.txt \ --file-list changedfiles.txt \
--build-dir build-cmake --build-dir build-cmake
elif [[ "$TRIGGER_SOURCE" == "schedule" ]]; then elif [[ -n "$REFERENCE_SHA" ]]; then
echo "Starting scheduled pipeline" echo "Detecting changes w.r.t to reference commit $REFERENCE_SHA"
echo "Skipping test selection, build/test stages will consider all tests!" python3 bin/testing/getchangedfiles.py --outfile changedfiles.txt \
touch affectedtests.json --source-tree HEAD \
--target-tree $REFERENCE_SHA
elif [ -n $TEST_AGAINST_LAST_SUCCESSFUL ]; then python3 bin/testing/findtests.py --outfile affectedtests.json \
echo "Determining sha of the last successful pipeline to test against" --file-list changedfiles.txt \
--build-dir build-cmake
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
else else
echo "Unknown pipeline trigger event" echo "No reference information given."
echo "Skipping test selection, build/test stages will consider all tests!" echo "Skipping test selection, build/test stages will consider all tests!"
touch affectedtests.json touch affectedtests.json
fi fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment