Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Validate coin configs #40

Merged
merged 5 commits into from
Aug 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/validate_coins.yml
Original file line number Diff line number Diff line change
@@ -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)')
"