Skip to content

Commit

Permalink
Merge pull request #26 from creative-commoners/pulls/1.0/allow-dev
Browse files Browse the repository at this point in the history
ENH Allow require-dev changes in composer.json
  • Loading branch information
GuySartorelli authored Aug 30, 2023
2 parents 8bc5884 + 50165f1 commit e2c573b
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,51 @@ runs:
FILES=$(jq -r .files[].filename __compare.json)
rm __compare.json
# Don't allow merge-ups when there are changes in dependency files
DEPENDENCY_FILES="composer.json package.json yarn.lock"
# Don't allow merge-ups when there are changes in javascript dependency files
DEPENDENCY_FILES="package.json yarn.lock"
for DEPENDENCY_FILE in $DEPENDENCY_FILES; do
if [[ $(echo "$FILES" | grep $DEPENDENCY_FILE) != "" ]]; then
echo "Unable to mergeup between $FROM_BRANCH and $INTO_BRANCH - there are changes in $DEPENDENCY_FILE"
echo "Unable to mergeup $FROM_BRANCH into $INTO_BRANCH - there are changes in $DEPENDENCY_FILE"
exit 1
fi
done
# Don't allow merge-ups where the are changes composer.json, unless the only changes are in "require-dev"
if [[ $(echo "$FILES" | grep composer.json) != "" ]]; then
RESP_CODE=$(curl -w %{http_code} -s -o __composer_from.json https://raw.githubusercontent.com/$GITHUB_REPOSITORY/$FROM_BRANCH/composer.json)
if [[ $RESP_CODE != 200 ]]; then
echo "Unable to download composer.json for branch $FROM_BRANCH - HTTP response code was $RESP_CODE"
exit 1
fi
RESP_CODE=$(curl -w %{http_code} -s -o __composer_into.json https://raw.githubusercontent.com/$GITHUB_REPOSITORY/$INTO_BRANCH/composer.json)
if [[ $RESP_CODE != 200 ]]; then
echo "Unable to download composer.json for branch $INTO_BRANCH - HTTP response code was $RESP_CODE"
exit 1
fi
CAN_MERGE_UP_COMPOSER_JSON=$(php -r '
$from = json_decode(file_get_contents("__composer_from.json"), true);
$into = json_decode(file_get_contents("__composer_into.json"), true);
if (!$from) {
throw new Exception("Could not parse __composer_from.json - " . json_last_error_msg());
}
if (!$into) {
throw new Exception("Could not parse __composer_into.json - " . json_last_error_msg());
}
if (array_key_exists("require-dev", $from)) {
unset($from["require-dev"]);
}
if (array_key_exists("require-dev", $into)) {
unset($into["require-dev"]);
}
echo json_encode($from) === json_encode($into) ? "1" : "0";
')
rm __composer_from.json
rm __composer_into.json
if [[ $CAN_MERGE_UP_COMPOSER_JSON == "0" ]]; then
echo "Unable to mergeup $FROM_BRANCH into $INTO_BRANCH - there are non require-dev changes in composer.json"
exit 1
fi
fi
done
# actions/checkout with fetch-depth: 0 will fetch ALL git history for the repository
Expand Down

0 comments on commit e2c573b

Please sign in to comment.