Skip to content

Commit

Permalink
poc
Browse files Browse the repository at this point in the history
  • Loading branch information
connorhu committed Feb 29, 2024
1 parent f7a6e29 commit 2890b74
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
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
9 changes: 9 additions & 0 deletions .ci/github/files_between_commits.sh
Original file line number Diff line number Diff line change
@@ -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
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
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/.gitignore export-ignore
/.github export-ignore

/docker-compose.yml
/.ci export-ignore

/docker-compose.yml export-ignore
/tests export-ignore
/tools export-ignore
38 changes: 38 additions & 0 deletions .github/workflows/archive-validation.yml
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit 2890b74

Please sign in to comment.