From f46638a1199d72a5d690675d5ccb02e5961f1db5 Mon Sep 17 00:00:00 2001 From: naezith Date: Fri, 23 Jun 2023 17:58:48 +0300 Subject: [PATCH 1/5] Create validate_coins.yml --- .github/workflows/validate_coins.yml | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/validate_coins.yml diff --git a/.github/workflows/validate_coins.yml b/.github/workflows/validate_coins.yml new file mode 100644 index 000000000..eab5a84aa --- /dev/null +++ b/.github/workflows/validate_coins.yml @@ -0,0 +1,56 @@ +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: Get coins repo commit + id: coins + run: | + echo "::set-output name=hash::$(jq -r .coins_repo_commit coins_ci.json)" + shell: bash + + - name: Get coins.json and coins_config.json from KomodoPlatform/coins repo + run: | + curl -O https://raw.githubusercontent.com/KomodoPlatform/coins/${{ steps.coins.outputs.hash }}/coins + curl -O https://raw.githubusercontent.com/KomodoPlatform/coins/${{ steps.coins.outputs.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: | + 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 + + - 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 From 8057bd8313d80a37e22a8eedb2a6cc7be293484b Mon Sep 17 00:00:00 2001 From: naezith Date: Mon, 26 Jun 2023 15:41:49 +0300 Subject: [PATCH 2/5] 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)') +" From 74fdafb25ef9bb82852cf71aa4b9db9b875f54f7 Mon Sep 17 00:00:00 2001 From: naezith Date: Mon, 26 Jun 2023 15:48:12 +0300 Subject: [PATCH 3/5] multi-line python in .yml --- .github/workflows/validate_coins.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/validate_coins.yml b/.github/workflows/validate_coins.yml index ed3638aeb..9ee02cbc3 100644 --- a/.github/workflows/validate_coins.yml +++ b/.github/workflows/validate_coins.yml @@ -47,7 +47,7 @@ jobs: - name: Check wallet-only coins run: | - python3 -c " + python3 -c """ import json, re with open('assets/coins_config.json', 'r') as f: coins_json = json.load(f) @@ -58,11 +58,11 @@ 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 " + python3 -c """ import re, requests with open('lib/app_config/app_config.dart', 'r') as f: dart_file = f.read() @@ -77,4 +77,4 @@ for url in urls: raise AssertionError(f'{cleaned_url} is unreachable (HTTP {response.status_code})') except requests.ConnectionError: raise AssertionError(f'{cleaned_url} is unreachable (Connection Error)') -" +""" From df9cc67875fcfdb7b7f0f422ece0b66b8bba898d Mon Sep 17 00:00:00 2001 From: naezith Date: Mon, 26 Jun 2023 15:52:23 +0300 Subject: [PATCH 4/5] indent python code --- .github/workflows/validate_coins.yml | 57 ++++++++++++++-------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/.github/workflows/validate_coins.yml b/.github/workflows/validate_coins.yml index 9ee02cbc3..6e734808e 100644 --- a/.github/workflows/validate_coins.yml +++ b/.github/workflows/validate_coins.yml @@ -47,34 +47,35 @@ jobs: - 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}' -""" + 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)') -""" + 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)') + " + From 58f68fa59054528535976bd5eb638f9c7b119046 Mon Sep 17 00:00:00 2001 From: naezith Date: Mon, 26 Jun 2023 16:00:05 +0300 Subject: [PATCH 5/5] fix set-output will be deprecated --- .github/workflows/validate_coins.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/validate_coins.yml b/.github/workflows/validate_coins.yml index 6e734808e..2f6021cd3 100644 --- a/.github/workflows/validate_coins.yml +++ b/.github/workflows/validate_coins.yml @@ -31,13 +31,13 @@ jobs: - name: Get coins repo commit id: coins run: | - echo "::set-output name=hash::$(jq -r .coins_repo_commit coins_ci.json)" + 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/${{ steps.coins.outputs.hash }}/coins - curl -O https://raw.githubusercontent.com/KomodoPlatform/coins/${{ steps.coins.outputs.hash }}/utils/coins_config.json + 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