|
| 1 | +name: Currency Sync Check |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 1 * *' # First day of every month |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + check-currencies: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + timeout-minutes: 5 |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Check currency list against API |
| 19 | + run: | |
| 20 | + set -euo pipefail |
| 21 | +
|
| 22 | + # Currencies to exclude from the check (present in API but intentionally unsupported) |
| 23 | + EXCLUDED=(HRK) # Croatian Kuna — replaced by EUR |
| 24 | +
|
| 25 | + # Extract supported currencies from the Fiat enum in source code |
| 26 | + SUPPORTED=$(sed -n '/^pub enum Fiat/,/^}/p' src/currency/fiat.rs | grep -oP '^\s+[A-Z]{3}\b' | tr -d ' ') |
| 27 | +
|
| 28 | + if [ -z "$SUPPORTED" ]; then |
| 29 | + echo "::error::Failed to extract any currencies from src/currency/fiat.rs" |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | +
|
| 33 | + # Fetch currencies from the blockchain.info ticker API (with retries) |
| 34 | + API_RESPONSE="" |
| 35 | + for attempt in 1 2 3; do |
| 36 | + API_RESPONSE=$(curl -sf --connect-timeout 10 --max-time 30 https://blockchain.info/ticker) && break |
| 37 | + echo "::warning::API fetch attempt $attempt failed, retrying..." |
| 38 | + sleep 5 |
| 39 | + done |
| 40 | +
|
| 41 | + if [ -z "$API_RESPONSE" ]; then |
| 42 | + echo "::error::Failed to fetch blockchain.info ticker API after 3 attempts" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +
|
| 46 | + API_CURRENCIES=$(echo "$API_RESPONSE" | jq -r 'keys[]') || { |
| 47 | + echo "::error::Failed to parse API response as JSON" |
| 48 | + exit 1 |
| 49 | + } |
| 50 | +
|
| 51 | + # Filter out excluded currencies from API list |
| 52 | + for exc in "${EXCLUDED[@]}"; do |
| 53 | + API_CURRENCIES=$(echo "$API_CURRENCIES" | grep -v "^${exc}$") |
| 54 | + done |
| 55 | +
|
| 56 | + # Find currencies in API but not in code |
| 57 | + MISSING_IN_CODE="" |
| 58 | + while IFS= read -r currency; do |
| 59 | + if ! echo "$SUPPORTED" | grep -q "^${currency}$"; then |
| 60 | + MISSING_IN_CODE="${MISSING_IN_CODE} ${currency}" |
| 61 | + fi |
| 62 | + done <<< "$API_CURRENCIES" |
| 63 | +
|
| 64 | + # Find currencies in code but not in API |
| 65 | + MISSING_IN_API="" |
| 66 | + while IFS= read -r currency; do |
| 67 | + if ! echo "$API_CURRENCIES" | grep -q "^${currency}$"; then |
| 68 | + MISSING_IN_API="${MISSING_IN_API} ${currency}" |
| 69 | + fi |
| 70 | + done <<< "$SUPPORTED" |
| 71 | +
|
| 72 | + # Report results |
| 73 | + EXIT=0 |
| 74 | +
|
| 75 | + if [ -n "$MISSING_IN_CODE" ]; then |
| 76 | + echo "::error::Currencies in API but not in code:${MISSING_IN_CODE}" |
| 77 | + EXIT=1 |
| 78 | + fi |
| 79 | +
|
| 80 | + if [ -n "$MISSING_IN_API" ]; then |
| 81 | + echo "::warning::Currencies in code but not in API:${MISSING_IN_API}" |
| 82 | + fi |
| 83 | +
|
| 84 | + if [ ${#EXCLUDED[@]} -gt 0 ]; then |
| 85 | + echo "::notice::Excluded currencies: ${EXCLUDED[*]}" |
| 86 | + fi |
| 87 | +
|
| 88 | + if [ $EXIT -eq 0 ]; then |
| 89 | + echo "Currency list is in sync with the API." |
| 90 | + fi |
| 91 | +
|
| 92 | + exit $EXIT |
0 commit comments