Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archive validation #129

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .ci/github/archive_allow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
lib/
CHANGELOG.md
COPYRIGHT
LICENSE
README.md
UPGRADE_TO_1_2
composer.json
15 changes: 15 additions & 0 deletions .ci/github/files_between_commits.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .ci/github/number_of_files_changed_in_root.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

cat - | sort | uniq | wc -l
26 changes: 26 additions & 0 deletions .ci/github/validate_archive.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 35 additions & 0 deletions .github/workflows/archive-validation.yml
Original file line number Diff line number Diff line change
@@ -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 }}