Skip to content

Commit 34c63b3

Browse files
committed
add workflow to check the content of the archive
1 parent 931eef1 commit 34c63b3

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

.ci/github/archive_allow.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
lib/
2+
CHANGELOG.md
3+
COPYRIGHT
4+
LICENSE
5+
README.md
6+
UPGRADE_TO_1_2
7+
composer.json
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
branch=$1
4+
hash=$2
5+
6+
git fetch origin
7+
8+
# root folder of added files
9+
git diff --color --name-only --diff-filter=A ${branch}..${hash} | cut -d/ -f1 || exit 1
10+
11+
# list changed root files
12+
git diff --name-only ${branch}..${hash} | grep '/' -v || exit 1
13+
14+
# the previous command lists the changed files as their new name, so we list the original names too
15+
git diff ${branch}..${hash} | grep '^rename from' | sed 's/^rename from //' | cut -d/ -f1 || exit 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
cat - | sort | uniq | wc -l

.ci/github/validate_archive.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
archive_name=$1
4+
pattern_file=$(dirname $0)/archive_allow.txt
5+
6+
if [ ! -f "$pattern_file" ]
7+
then
8+
echo "config file not exists: $pattern_file"
9+
exit 1
10+
fi
11+
12+
# test for empty
13+
14+
archive_content=$(tar -tf $archive_name)
15+
16+
for pattern in $(cat $pattern_file)
17+
do
18+
archive_content=$(echo "$archive_content" | grep -v "^$pattern")
19+
done
20+
21+
if [ $(echo "$archive_content" | grep ^$ -v | wc -l) -gt 0 ]
22+
then
23+
echo "Files not allowed in archive:"
24+
echo "$archive_content"
25+
exit 1
26+
fi
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Git Archive Content Check
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
paths:
8+
- .github/workflows/archive-validation.yml
9+
- .ci/github/archive_allow.txt
10+
- ./*
11+
push:
12+
branches:
13+
- master
14+
paths:
15+
- .github/workflows/archive-validation.yml
16+
- .ci/github/archive_allow.txt
17+
- ./*
18+
19+
jobs:
20+
archive-validation:
21+
name: Git Archive Content Check
22+
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- id: number-of-changed-files
29+
run: |
30+
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
31+
32+
- run: |
33+
git archive -o archive.tar $GITHUB_SHA && sh .ci/github/validate_archive.sh archive.tar
34+
if: ${{ env.NO_OF_FILES_CHANGED_IN_ROOT > 0 }}
35+

0 commit comments

Comments
 (0)