Skip to content

Commit

Permalink
add workflow to check the content of the archive
Browse files Browse the repository at this point in the history
  • Loading branch information
connorhu committed Feb 29, 2024
1 parent f7a6e29 commit 28fa64f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
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
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: ${{ steps.number-of-changed-files.outputs.no_of_changed_files_in_root > 0 }}

0 comments on commit 28fa64f

Please sign in to comment.