From e482d579e9059f760d5b71806d173cbebfad6e4a Mon Sep 17 00:00:00 2001 From: Arjan Bal Date: Thu, 16 Jan 2025 15:44:27 +0530 Subject: [PATCH] Use subdirs for before and after --- .github/workflows/deps.yml | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deps.yml b/.github/workflows/deps.yml index d8050f5b3ccb..914d1427ed94 100644 --- a/.github/workflows/deps.yml +++ b/.github/workflows/deps.yml @@ -31,20 +31,26 @@ jobs: - name: Compare dependencies run: | set -eux - BASE_REF="${GITHUB_BASE_REF:-master}" - # Suffixes passed to mktemp must not contain "/". - BEFORE_SUFFIX="${BASE_REF//\//_}" - AFTER_SUFFIX="${GITHUB_HEAD_REF//\//_}" + TEMP_DIR="$(mktemp -d)" + # GITHUB_BASE_REF is set when the job is triggered by a PR. + TARGET_REF="${GITHUB_BASE_REF:-master}" + # GITHUB_HEAD_REF is set when the job is triggered by a PR. + SOURCE_REF="${GITHUB_HEAD_REF:-source}" - BEFORE="$(mktemp -d --suffix="-${BEFORE_SUFFIX}")" - AFTER="$(mktemp -d --suffix="-${AFTER_SUFFIX}")" + # Replace special characters in the branch names. + BEFORE_DIR_NAME="$(echo "${SOURCE_REF}" | sed 's/[^a-zA-Z0-9._-]/_/g')" + AFTER_DIR_NAME="$(echo "${TARGET_REF}" | sed 's/[^a-zA-Z0-9._-]/_/g')" - scripts/gen-deps.sh "${AFTER}" - # GITHUB_BASE_REF is set when the job is triggered by a PR. - git checkout origin/"${BASE_REF}" - scripts/gen-deps.sh "${BEFORE}" + + mkdir "${TEMP_DIR}/${AFTER_DIR_NAME}" + scripts/gen-deps.sh "${TEMP_DIR}/${AFTER_DIR_NAME}" + + git checkout "origin/${TARGET_REF}" + mkdir "${TEMP_DIR}/${BEFORE_DIR_NAME}" + scripts/gen-deps.sh "${TEMP_DIR}/${BEFORE_DIR_NAME}" echo "Comparing dependencies..." + cd "${TEMP_DIR}" # Run grep in a sub-shell since bash does not support ! in the middle of a pipe - diff -u0 -r "${BEFORE}" "${AFTER}" | bash -c '! grep -v "@@"' + diff -u0 -r "./${BEFORE_DIR_NAME}" "./${AFTER_DIR_NAME}" | bash -c '! grep -v "@@"' echo "No changes detected."