Skip to content

Clean up code

Clean up code #299

Workflow file for this run

name: pr-checks
on:
pull_request_target:
branches: ["main"]
workflow_dispatch:
permissions:
pull-requests: write
contents: write
jobs:
changed_files:
runs-on: ubuntu-latest
name: PR automated checks
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
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
# Filter out .yml files
FILTERED_FILES=$(echo "$ALL_CHANGED_FILES" | tr ' ' '\n' | grep -v '\.yml$' | tr '\n' ' ')
for file in $FILTERED_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
update_tokenlist:
needs: changed_files
runs-on: ubuntu-latest
environment: tokenlist-check
if: ${{ !failure() }}
steps:
# Setup python and poetry (cached)
- name: Check out the repository
uses: actions/checkout@v3
- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: 3.11
poetry-version: 1.8.3
- name: Generate and upload tokenlist
env:
DRPC_KEY: ${{ secrets.DRPC_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
poetry run python upkeep.py