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 100644 index 000000000..de2e05175 --- /dev/null +++ b/.ci/github/files_between_commits.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +branch=${1#refs/} +hash=$2 + +git diff --name-only ${branch}..${hash} || exit 1 + +# the previous commit 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 //' || exit 1 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..a84b7b695 --- /dev/null +++ b/.github/workflows/archive-validation.yml @@ -0,0 +1,38 @@ +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_changed_files_in_root=$(for file in $(bash .ci/github/files_between_commits.sh $GITHUB_REF $GITHUB_SHA) + do + dirname $file; + done | sort | uniq | grep '^\.$' | wc -l)" >> $GITHUB_OUTPUT + + - 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 }} +