diff --git a/.ci/github/archive_allow.txt b/.ci/github/archive_allow.txt new file mode 100644 index 000000000..2d1d28b28 --- /dev/null +++ b/.ci/github/archive_allow.txt @@ -0,0 +1,7 @@ +lib/ +CHANGELOG.md +COPYRIGHT +LICENSE +README.md +UPGRADE_TO_1_2 +composer.json diff --git a/.ci/github/files_between_commits.sh b/.ci/github/files_between_commits.sh new file mode 100755 index 000000000..a0496dbe9 --- /dev/null +++ b/.ci/github/files_between_commits.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +branch=$1 +hash=$2 + +git fetch origin + +# root folder of added files +git diff --color --name-only --diff-filter=A ${branch}..${hash} | cut -d/ -f1 || exit 1 + +# list changed root files +git diff --name-only ${branch}..${hash} | grep '/' -v || exit 1 + +# the previous command lists the changed files as their new name, so we list the original names too +git diff ${branch}..${hash} | grep '^rename from' | sed 's/^rename from //' | cut -d/ -f1 || exit 1 diff --git a/.ci/github/number_of_files_changed_in_root.sh b/.ci/github/number_of_files_changed_in_root.sh new file mode 100755 index 000000000..53014753c --- /dev/null +++ b/.ci/github/number_of_files_changed_in_root.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +cat - | sort | uniq | wc -l diff --git a/.ci/github/validate_archive.sh b/.ci/github/validate_archive.sh new file mode 100644 index 000000000..8630306b2 --- /dev/null +++ b/.ci/github/validate_archive.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +archive_name=$1 +pattern_file=$(dirname $0)/archive_allow.txt + +if [ ! -f "$pattern_file" ] +then + echo "config file not exists: $pattern_file" + exit 1 +fi + +# test for empty + +archive_content=$(tar -tf $archive_name) + +for pattern in $(cat $pattern_file) +do + archive_content=$(echo "$archive_content" | grep -v "^$pattern") +done + +if [ $(echo "$archive_content" | grep ^$ -v | wc -l) -gt 0 ] +then + echo "Files not allowed in archive:" + echo "$archive_content" + exit 1 +fi diff --git a/.github/workflows/archive-validation.yml b/.github/workflows/archive-validation.yml new file mode 100644 index 000000000..5c4adbb3f --- /dev/null +++ b/.github/workflows/archive-validation.yml @@ -0,0 +1,35 @@ +name: Git Archive Content Check + +on: + pull_request: + branches: + - master + paths: + - .github/workflows/archive-validation.yml + - .ci/github/archive_allow.txt + - ./* + push: + branches: + - master + paths: + - .github/workflows/archive-validation.yml + - .ci/github/archive_allow.txt + - ./* + +jobs: + archive-validation: + name: Git Archive Content Check + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - id: number-of-changed-files + run: | + echo "NO_OF_FILES_CHANGED_IN_ROOT=$(.ci/github/files_between_commits.sh origin/$GITHUB_BASE_REF $GITHUB_SHA | .ci/github/number_of_files_changed_in_root.sh)" >> $GITHUB_ENV + + - run: | + git archive -o archive.tar $GITHUB_SHA && sh .ci/github/validate_archive.sh archive.tar + if: ${{ steps.number-of-changed-files.outputs.no_of_changed_files_in_root > 0 }} +