From 8057bd8313d80a37e22a8eedb2a6cc7be293484b Mon Sep 17 00:00:00 2001 From: naezith Date: Mon, 26 Jun 2023 15:41:49 +0300 Subject: [PATCH] python for check wallet-only and URLs --- .github/workflows/validate_coins.yml | 44 +++++++++++++++++++++------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/.github/workflows/validate_coins.yml b/.github/workflows/validate_coins.yml index eab5a84aa..ed3638aeb 100644 --- a/.github/workflows/validate_coins.yml +++ b/.github/workflows/validate_coins.yml @@ -22,6 +22,12 @@ jobs: sudo npm install -g json-diff sudo apt-get install jq -y + - name: Install Python + run: | + sudo apt-get install python3 python3-pip -y + pip3 install jsonlines + pip3 install requests + - name: Get coins repo commit id: coins run: | @@ -41,16 +47,34 @@ jobs: - name: Check wallet-only coins run: | - jq -r '.[] | select(.wallet_only == true) | .ticker' assets/coins_config.json > coins_config_wallet_only.txt - grep -Fof coins_config_wallet_only.txt lib/app_config/app_config.dart + python3 -c " +import json, re +with open('assets/coins_config.json', 'r') as f: + coins_json = json.load(f) +wallet_only_coins = [coin['coin'] for coin in coins_json.values() if coin['wallet_only']] +with open('lib/app_config/app_config.dart', 'r') as f: + dart_file = f.read() +coins_dart = re.findall(r'walletOnlyCoins => \[\s*([^]]+?)\s*\]', dart_file) +coins_dart = [coin.strip().strip('\'') for coin in coins_dart[0].split(',') if coin] +missing_coins = set(wallet_only_coins) - set(coins_dart) +assert len(missing_coins) == 0, f'Missing coins: {missing_coins}' +" - name: Check URLs in app_config.dart run: | - urls=$(grep -Eo '(http|https)://[^ ]+' lib/app_config/app_config.dart) - for url in $urls; do - status=$(curl --write-out "%{http_code}" --silent --output /dev/null "$url") - if [[ "$status" -ge 400 ]]; then - echo "$url is unreachable (HTTP $status)" - exit 1 - fi - done + python3 -c " +import re, requests +with open('lib/app_config/app_config.dart', 'r') as f: + dart_file = f.read() +urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|/|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', dart_file) +for url in urls: + try: + if 'discord' in url or 'github.com' in url or url.endswith('?') or '/api/' in url: + continue + cleaned_url = url.rstrip('.,;\'"') + response = requests.head(cleaned_url, allow_redirects = True) + if response.status_code >= 400 and response.status_code != 405: + raise AssertionError(f'{cleaned_url} is unreachable (HTTP {response.status_code})') + except requests.ConnectionError: + raise AssertionError(f'{cleaned_url} is unreachable (Connection Error)') +"