diff --git a/.github/workflows/validate_coins.yml b/.github/workflows/validate_coins.yml new file mode 100644 index 000000000..2f6021cd3 --- /dev/null +++ b/.github/workflows/validate_coins.yml @@ -0,0 +1,81 @@ +name: Validate Coins +on: + pull_request: + types: [opened, synchronize, reopened] + push: + branches: [master, dev] + +jobs: + validate-coins: + runs-on: ubuntu-latest + steps: + - name: Checkout the code + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '14' + + - name: Install JSON tools + run: | + 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: | + echo "hash=$(jq -r .coins_repo_commit coins_ci.json)" >> $GITHUB_ENV + shell: bash + + - name: Get coins.json and coins_config.json from KomodoPlatform/coins repo + run: | + curl -O https://raw.githubusercontent.com/KomodoPlatform/coins/${hash}/coins + curl -O https://raw.githubusercontent.com/KomodoPlatform/coins/${hash}/utils/coins_config.json + + - name: Compare coins.json + run: json-diff assets/coins.json coins + + - name: Compare coins_config.json + run: json-diff assets/coins_config.json coins_config.json + + - name: Check wallet-only coins + run: | + 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: | + 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)') + " +