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

Add automated PR checks #322

Merged
merged 1 commit into from
Feb 25, 2024
Merged
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
98 changes: 98 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: pr-checks

Check failure on line 1 in .github/workflows/pr-checks.yml

View workflow job for this annotation

GitHub Actions / PR automated checks

Only additions of token icons (in the /images folder) or platform logos (in the /platforms folder) are permitted

on:
pull_request:
branches: [ "main" ]

workflow_dispatch:

permissions:
pull-requests: write

jobs:
changed_files:
runs-on: ubuntu-latest
name: PR automated checks
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v42
- name: Process changed files
id: changes-errors
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo 'errorsStr<<EOF' >> $GITHUB_OUTPUT

for file in $ALL_CHANGED_FILES; do
echo "Processing file: $file"

if [[ $file != images/* ]] && [[ $file != platforms/* ]] ;
then
errorText="Only additions of token icons (in the /images folder) or platform logos (in the /platforms folder) are permitted"
errorOutputText="- Error with \`$file\`: $errorText"
echo "::error file=$file::$errorText"
echo "$errorOutputText" >> $GITHUB_OUTPUT
fi

# Only check token icon additions, not platform icons which don't have anything automated
if [[ $file == images/assets* ]] ;
then
if [[ $file != *.png ]] ;
then
errorText="The new icon must be a PNG file"
errorOutputText="- Error with \`$file\`: $errorText"
echo "::error file=$file::$errorText"
echo "$errorOutputText" >> $GITHUB_OUTPUT
elif [[ ! $file =~ ^images/assets(-[a-z]+)?/[a-z0-9]+\.png$ ]] ;
then
errorText="The new icon's filename must be entirely lowercase"
errorOutputText="- Error with \`$file\`: $errorText"
echo "::error file=$file::$errorText"
echo "$errorOutputText" >> $GITHUB_OUTPUT
fi
fi
done

echo 'EOF' >> $GITHUB_OUTPUT
- name: Check if errors
id: check-if-errors
env:
ERRORS: ${{ steps.changes-errors.outputs.errorsStr }}
run: |
errorsStrLength=${#ERRORS}
echo "prev output : $ERRORS $errorsStrLength"

if (( errorsStrLength == 0 ));
then
echo 'hasErrors=false'
echo "hasErrors=false" >> "$GITHUB_OUTPUT"
else
echo 'hasErrors=true'
echo "hasErrors=true" >> "$GITHUB_OUTPUT"
fi
- name: Comment on PR if error
env:
ERRORS: ${{ steps.changes-errors.outputs.errorsStr }}
HAS_ERRORS: ${{ steps.check-if-errors.outputs.hasErrors }}
uses: thollander/actions-comment-pull-request@v2
if: ${{ env.HAS_ERRORS == 'true' }}
with:
message: |
Changes are required before your pull request can be reviewed:

${{ env.ERRORS }}
- name: Exit with error
env:
ERRORS: ${{ steps.changes-errors.outputs.errorsStr }}
HAS_ERRORS: ${{ steps.check-if-errors.outputs.hasErrors }}
if: ${{ env.HAS_ERRORS == 'true' }}
run: |
mapfile myarray <<< $ERRORS
for ((i = 0; i < ${#myarray[@]}; ++i)); do
echo "::error::${myarray[i]}"
done
exit 1
Loading