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)') +"