From 6537e30251b461edb27699133e5d171e2622eb7d Mon Sep 17 00:00:00 2001 From: Philip Korsholm Date: Wed, 20 Oct 2021 16:04:36 +0200 Subject: [PATCH] update scripts to handle github actions --- scripts/assert-changed-files-circleci.sh | 36 ++++++++++++++++++++++++ scripts/assert-changed-files.sh | 10 +++++-- 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100755 scripts/assert-changed-files-circleci.sh mode change 100755 => 100644 scripts/assert-changed-files.sh diff --git a/scripts/assert-changed-files-circleci.sh b/scripts/assert-changed-files-circleci.sh new file mode 100755 index 0000000000..1efc93e933 --- /dev/null +++ b/scripts/assert-changed-files-circleci.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +IS_CI="${CI:-false}" +GREP_PATTERN=$1 + +if [ "$IS_CI" = true ]; then + git config --local url."https://github.com/".insteadOf git@github.com: + git config --local user.name "Medusajs Bot" + git config --local user.email "core@medusa-commerce.com" + + git fetch origin + git merge --no-edit origin/master + + if [ $? -ne 0 ]; then + echo "Branch has conflicts with master, rolling back test." + git merge --abort + fi + + git config --local --unset user.name + git config --local --unset user.email + git config --local --unset url."https://github.com/".insteadOf +fi + +FILES_COUNT="$(git diff-tree --no-commit-id --name-only -r "$CIRCLE_BRANCH" origin/master | grep -E "$GREP_PATTERN" -c)" + +if [ "$IS_CI" = true ]; then + # reset to previous state + git reset --hard $CIRCLE_SHA1 +fi + +if [ "$FILES_COUNT" -eq 0 ]; then + echo "0 files matching '$GREP_PATTERN'; exiting and marking successful." + exit 1 +else + echo "$FILES_COUNT file(s) matching '$GREP_PATTERN'; continuing." +fi diff --git a/scripts/assert-changed-files.sh b/scripts/assert-changed-files.sh old mode 100755 new mode 100644 index 4f5833cc14..2a45a8f650 --- a/scripts/assert-changed-files.sh +++ b/scripts/assert-changed-files.sh @@ -21,16 +21,20 @@ if [ "$IS_CI" = true ]; then git config --local --unset url."https://github.com/".insteadOf fi -FILES_COUNT="$(git diff-tree --no-commit-id --name-only -r "$CIRCLE_BRANCH" origin/master | grep -E "$GREP_PATTERN" -c)" +# Make sure that we are diffing towards the right branch, in github actions this is different +# depending on whether or not we are creating a pull request or not. +[ ! -z ${GITHUB_BASE_REF} ] && HAS_BASE=true || HAS_BASE=false +[ HAS_BASE = true ] && COMPARE="${GITHUB_BASE_REF#refs/heads/}" || COMPARE="develop" +FILES_COUNT="$(git diff-tree --no-commit-id --name-only -r origin/"$COMPARE" | grep -E "$GREP_PATTERN" -c)" if [ "$IS_CI" = true ]; then # reset to previous state - git reset --hard $CIRCLE_SHA1 + git reset --hard $GITHUB_SHA fi if [ "$FILES_COUNT" -eq 0 ]; then echo "0 files matching '$GREP_PATTERN'; exiting and marking successful." - circleci step halt || exit 1 + exit 1 else echo "$FILES_COUNT file(s) matching '$GREP_PATTERN'; continuing." fi