From 4b8662e57f99709a9552e887f6d6d08a556f8d26 Mon Sep 17 00:00:00 2001 From: Teake Nutma <t.a.nutma@rug.nl> Date: Mon, 20 Jun 2022 16:35:02 +0200 Subject: [PATCH] Use the first parent commit for changed files as fallback --- README.rst | 2 +- templates/changedfiles/all.yml | 2 +- templates/changedfiles/branch.yml | 24 ++++++++++++++++++++++++ templates/changedfiles/push.yml | 12 ------------ 4 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 templates/changedfiles/branch.yml delete mode 100644 templates/changedfiles/push.yml diff --git a/README.rst b/README.rst index 7b06f6f..9a14ad8 100644 --- a/README.rst +++ b/README.rst @@ -413,7 +413,7 @@ a job, respectively. The full list of variables is as follows: `autopep8` CI_AWE_SKIP_AUTOFORMAT CI_AWE_RUN_AUTOFORMAT `templates/autoformat/autopep8.yml` `black` CI_AWE_SKIP_AUTOFORMAT CI_AWE_RUN_AUTOFORMAT `templates/autoformat/black.yml` `changed_files_mr` CI_AWE_SKIP_CHANGED_FILES CI_AWE_RUN_CHANGED_FILES `templates/changedfiles/mergerequest.yml` -`changed_files_push` CI_AWE_SKIP_CHANGED_FILES CI_AWE_RUN_CHANGED_FILES `templates/changedfiles/push.yml` +`changed_files_branch` CI_AWE_SKIP_CHANGED_FILES CI_AWE_RUN_CHANGED_FILES `templates/changedfiles/branch.yml` `conda_build` CI_AWE_SKIP_CONDA_BUILD_TEST CI_AWE_RUN_CONDA_BUILD_TEST `templates/conda/build.yml` `conda_test` CI_AWE_SKIP_CONDA_BUILD_TEST CI_AWE_RUN_CONDA_BUILD_TEST `templates/conda/build.yml` `conda_upload` CI_AWE_SKIP_CONDA_UPLOAD CI_AWE_RUN_CONDA_UPLOAD `templates/conda/release.yml` diff --git a/templates/changedfiles/all.yml b/templates/changedfiles/all.yml index 8e1e773..5e21115 100644 --- a/templates/changedfiles/all.yml +++ b/templates/changedfiles/all.yml @@ -1,3 +1,3 @@ include: - local: '/templates/changedfiles/mergerequest.yml' - - local: '/templates/changedfiles/push.yml' + - local: '/templates/changedfiles/branch.yml' diff --git a/templates/changedfiles/branch.yml b/templates/changedfiles/branch.yml new file mode 100644 index 0000000..8123b3c --- /dev/null +++ b/templates/changedfiles/branch.yml @@ -0,0 +1,24 @@ +include: + - local: '/templates/changedfiles/_shared.yml' + +changed_files_branch: + extends: .changed_files + variables: + CHANGED_FILES_COMPARE_REF: $CI_COMMIT_BEFORE_SHA + rules: + - if: $CI_AWE_SKIP_CHANGED_FILES + when: never + - if: $CI_AWE_RUN_CHANGED_FILES + - !reference [.primary_ref_jobs, rules] + before_script: + # An additional check because $CI_COMMIT_BEFORE_SHA is not always set. + # See https://stackoverflow.com/a/71601191/2097. We use CI_COMMIT_BEFORE_SHA + # when it's set because that will point to the correct commit when you push + # multiple commits at once. If it's not set, use the first parent of the + # commit (which for merge commits is from the branch where you merged into). + - | + if [ "$CI_COMMIT_BEFORE_SHA" = "0000000000000000000000000000000000000000"]; then + echo "CI_COMMIT_BEFORE_SHA is not set." + CHANGED_FILES_COMPARE_REF=$(git rev-parse HEAD^) + echo "Using ${CHANGED_FILES_COMPARE_REF} as previous reference instead." + fi diff --git a/templates/changedfiles/push.yml b/templates/changedfiles/push.yml deleted file mode 100644 index bea5621..0000000 --- a/templates/changedfiles/push.yml +++ /dev/null @@ -1,12 +0,0 @@ -include: - - local: '/templates/changedfiles/_shared.yml' - -changed_files_push: - extends: .changed_files - variables: - CHANGED_FILES_COMPARE_REF: $CI_COMMIT_BEFORE_SHA - rules: - - if: $CI_AWE_SKIP_CHANGED_FILES || $CI_PIPELINE_SOURCE != 'push' - when: never - - if: $CI_AWE_RUN_CHANGED_FILES - - !reference [.primary_ref_jobs, rules] -- GitLab