|
| 1 | +name: Package |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - src/** |
| 7 | + |
| 8 | +jobs: |
| 9 | + verify: |
| 10 | + name: Verify |
| 11 | + runs-on: Ubuntu-20.04 |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v2 |
| 15 | + |
| 16 | + - name: Fetch branch from where the PR started |
| 17 | + run: git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* |
| 18 | + |
| 19 | + - name: Find packages |
| 20 | + id: find-packages |
| 21 | + run: echo "::set-output name=packages::$(php .github/get-modified-packages.php $(find src/Symfony -mindepth 2 -type f -name composer.json -printf '%h\n' | jq -R -s -c 'split("\n")[:-1]') $(git diff --name-only origin/${{ github.base_ref }} HEAD | grep src/ | jq -R -s -c 'split("\n")[:-1]'))" |
| 22 | + |
| 23 | + - name: Verify meta files are correct |
| 24 | + run: | |
| 25 | + ok=0 |
| 26 | +
|
| 27 | + _file_exist() { |
| 28 | + if [ ! -f "${1}" ]; then |
| 29 | + echo "File ${1} does not exist" |
| 30 | + return 1 |
| 31 | + fi |
| 32 | + } |
| 33 | +
|
| 34 | + _file_not_exist() { |
| 35 | + if [ -f "${1}" ]; then |
| 36 | + echo "File ${1} should not be here" |
| 37 | + return 1 |
| 38 | + fi |
| 39 | + } |
| 40 | +
|
| 41 | + _correct_license_file() { |
| 42 | + FIRST_LINE="Copyright (c) $(date +"%Y") Fabien Potencier" |
| 43 | + PACKAGE_FIRST_LINE=$(head -1 ${1}) |
| 44 | + if [[ "$FIRST_LINE" != "$PACKAGE_FIRST_LINE" ]]; then |
| 45 | + echo "First line of the license file is wrong. Maybe it is the wrong year?" |
| 46 | + return 1 |
| 47 | + fi |
| 48 | +
|
| 49 | + TEMPLATE=$(tail -n +2 LICENSE) |
| 50 | + PACKAGE_LICENSE=$(tail -n +2 ${1}) |
| 51 | + if [[ "$TEMPLATE" != "$PACKAGE_LICENSE" ]]; then |
| 52 | + echo "Wrong content in license file" |
| 53 | + return 1 |
| 54 | + fi |
| 55 | + } |
| 56 | +
|
| 57 | + json='${{ steps.find-packages.outputs.packages }}' |
| 58 | + for package in $(echo "${json}" | jq -r '.[] | @base64'); do |
| 59 | + _jq() { |
| 60 | + echo ${package} | base64 --decode | jq -r ${1} |
| 61 | + } |
| 62 | +
|
| 63 | + DIR=$(_jq '.directory') |
| 64 | + NAME=$(_jq '.name') |
| 65 | + echo "::group::$NAME" |
| 66 | + localExit=0 |
| 67 | +
|
| 68 | + _file_exist $DIR/.gitattributes || localExit=1 |
| 69 | + _file_exist $DIR/.gitignore || localExit=1 |
| 70 | + _file_exist $DIR/CHANGELOG.md || localExit=1 |
| 71 | + _file_exist $DIR/LICENSE || localExit=1 |
| 72 | + _file_exist $DIR/phpunit.xml.dist || localExit=1 |
| 73 | + _file_exist $DIR/README.md || localExit=1 |
| 74 | + _file_not_exist $DIR/phpunit.xml || localExit=1 |
| 75 | +
|
| 76 | + if [ $(_jq '.new') == true ]; then |
| 77 | + echo "Verifying new package" |
| 78 | + _correct_license_file $DIR/LICENSE || localExit=1 |
| 79 | +
|
| 80 | + if [ $(_jq '.component_bridge') == false ]; then |
| 81 | + if [ ! $(cat composer.json | jq -e ".replace.\"$NAME\"|test(\"self.version\")") ]; then |
| 82 | + echo "Composer.json's replace section needs to contain $NAME" |
| 83 | + localExit=1 |
| 84 | + fi |
| 85 | + fi |
| 86 | + fi |
| 87 | +
|
| 88 | + ok=$(( $localExit || $ok )) |
| 89 | + echo ::endgroup:: |
| 90 | + if [ $localExit -ne 0 ]; then |
| 91 | + echo "::error::$NAME failed" |
| 92 | + fi |
| 93 | + done |
| 94 | +
|
| 95 | + exit $ok |
0 commit comments