From 34c63b3ceec294b05b27ecf0ec6935d3c841e40d Mon Sep 17 00:00:00 2001 From: Karoly Gossler Date: Thu, 29 Feb 2024 08:53:32 +0100 Subject: [PATCH 1/2] add workflow to check the content of the archive --- .ci/github/archive_allow.txt | 7 ++++ .ci/github/files_between_commits.sh | 15 ++++++++ .ci/github/number_of_files_changed_in_root.sh | 3 ++ .ci/github/validate_archive.sh | 26 ++++++++++++++ .github/workflows/archive-validation.yml | 35 +++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 .ci/github/archive_allow.txt create mode 100755 .ci/github/files_between_commits.sh create mode 100755 .ci/github/number_of_files_changed_in_root.sh create mode 100644 .ci/github/validate_archive.sh create mode 100644 .github/workflows/archive-validation.yml diff --git a/.ci/github/archive_allow.txt b/.ci/github/archive_allow.txt new file mode 100644 index 00000000..2d1d28b2 --- /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 00000000..a0496dbe --- /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 00000000..53014753 --- /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 00000000..8630306b --- /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 00000000..e7f6dbe8 --- /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: ${{ env.NO_OF_FILES_CHANGED_IN_ROOT > 0 }} + From 7d95525c3e498bd1c1ad14b97b523ab33ae5434f Mon Sep 17 00:00:00 2001 From: Karoly Gossler Date: Thu, 29 Feb 2024 09:29:28 +0100 Subject: [PATCH 2/2] add missing ignores --- .gitattributes | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index bf85d2fd..c4d21f55 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,7 +2,8 @@ /.gitattributes export-ignore /.gitignore export-ignore /.github export-ignore +/.ci export-ignore -/docker-compose.yml +/docker-compose.yml export-ignore /tests export-ignore /tools export-ignore