Skip to content

Developer tools

Test phone and email validation in GitHub Actions

Run integration tests against the Qelka API in GitHub Actions with a test key stored as a secret, then check the live key after each deploy with a free call.

Updated 2026-11-26

This recipe runs your validation code against the real Qelka API in GitHub Actions without spending credits, then checks after each deploy that production runs with a working live key. There is no Qelka action to install: the workflow uses node --test, curl and two repository secrets.

Test keys make CI tests both real and stable. A sk_test_ key runs the same request validation and rate limits as a live key, but returns fixed answers chosen by the input, so undeliverable@example.com is always undeliverable and your tests never flake.

What you need

  • A GitHub repository with Actions enabled.
  • A Qelka test key for CI. It never spends credits: see Test mode.
  • A live key for the smoke check. Make it a restricted key with only account ticked: it can read the key mode and balance but cannot call a paid endpoint. See restricted keys.
  • The GitHub CLI (gh) if you prefer to set secrets from a terminal.

Steps

1. Store the keys as secrets

Add two repository secrets, QELKA_API_KEY_TEST and QELKA_API_KEY_LIVE. In the repository, open Settings, then Secrets and variables, then Actions, and click New repository secret. Or from a terminal, where gh prompts for the value so it never lands in your shell history:

Terminal
gh secret set QELKA_API_KEY_TEST
gh secret set QELKA_API_KEY_LIVE

GitHub's naming rules: letters, digits and underscores only, no GITHUB_ prefix, not starting with a digit. GitHub masks secret values in logs, but its documentation says the redaction is not guaranteed, so never print the key. The code below only logs the key prefix, which is safe.

2. Write fail-open validation code

Put the API calls in one module that your app and your tests share. It sets a timeout on every call, retries once on 429, and never throws: any API problem returns unchecked, logged with the error type and the X-Request-Id.

src/validation.mjs
const apiBaseUrl = 'https://api.qelka.com/v1'

export async function check(path, body, { apiKey = process.env.QELKA_API_KEY, timeoutMs = 8000 } = {}) {
  for (let attempt = 1; attempt <= 2; attempt += 1) {
    let response
    try {
      response = await fetch(`${apiBaseUrl}${path}`, {
        method: 'POST',
        headers: {
          Authorization: `Bearer ${apiKey}`,
          'Content-Type': 'application/json',
        },
        body: JSON.stringify(body),
        signal: AbortSignal.timeout(timeoutMs),
      })
    } catch (error) {
      console.warn(`check skipped: ${error.name}`)
      return { status: 'unchecked', reason: 'unreachable' }
    }

    const result = await response.json().catch(() => ({}))
    if (response.ok) return result

    const retryAfter = Number(response.headers.get('Retry-After'))
    if (response.status === 429 && attempt === 1 && retryAfter > 0 && retryAfter <= 5) {
      await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000))
      continue
    }

    const type = result.error?.type ?? `http_${response.status}`
    console.warn(`check skipped: ${type} request ${response.headers.get('X-Request-Id')}`)
    return { status: 'unchecked', reason: type }
  }
}

export const verifyEmail = (email, mode = 'fast') => check('/email', { email, mode })

export const validatePhone = (phone, country) => check('/phone', { phone, country })

fast is the default here because a signup form or a webhook handler should answer quickly: it runs the syntax, DNS and list checks and skips the mailbox check. Pass 'full' when you need the mailbox answer. See the email reference.

3. Write the tests

Each test input below has a fixed answer with a test key:

Input Mode status reason
undeliverable@example.com full undeliverable mailbox_not_found
disposable@example.com fast risky disposable
unknown@example.com full unknown smtp_timeout
Any other well-formed address full deliverable accepted_email
Any address fast unknown smtp_not_checked, except nomx@ and disposable@

Phone numbers are parsed for real, so formatting tests are exact. The last test checks the fail-open path with a key that does not exist:

test/validation.test.mjs
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { check, validatePhone, verifyEmail } from '../src/validation.mjs'

test('rejects an address that cannot receive mail', async () => {
  const result = await verifyEmail('undeliverable@example.com', 'full')
  assert.equal(result.status, 'undeliverable')
  assert.equal(result.reason, 'mailbox_not_found')
})

test('flags a disposable address without spending credits', async () => {
  const result = await verifyEmail('disposable@example.com')
  assert.equal(result.reason, 'disposable')
  assert.equal(result.credits_used, 0)
})

test('keeps an inconclusive address', async () => {
  const result = await verifyEmail('unknown@example.com', 'full')
  assert.equal(result.status, 'unknown')
})

test('stores phone numbers in E.164', async () => {
  const result = await validatePhone('(415) 555-0123', 'US')
  assert.equal(result.e164, '+14155550123')
})

test('fails open when the key is wrong', async () => {
  const result = await check('/email', { email: 'jane@example.com' }, { apiKey: 'sk_test_does_not_exist' })
  assert.deepEqual(result, { status: 'unchecked', reason: 'invalid_api_key' })
})

Run them locally with your test key exported: node --test.

4. Run them on every push

.github/workflows/ci.yml
name: CI

on:
  push:
    branches: [main]
  pull_request:

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    env:
      QELKA_API_KEY: ${{ secrets.QELKA_API_KEY_TEST }}
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - name: Integration tests against the API in test mode
        if: env.QELKA_API_KEY != ''
        run: node --test

The job maps the secret to the QELKA_API_KEY variable that the code reads. Secrets cannot be tested directly in an if:, which is why the condition checks the variable: on a fork pull request, where GitHub passes no secrets, the step is skipped instead of failing. For Python, the pytest version of these tests in Test mode runs the same way after actions/setup-python.

5. Check the live key after each deploy

Add a job after your deploy job. It calls GET https://api.qelka.com/v1/account, which is free, and fails only when the key is wrong:

.github/workflows/deploy.yml
  smoke:
    needs: deploy
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - name: Check the production API key
        env:
          QELKA_API_KEY: ${{ secrets.QELKA_API_KEY_LIVE }}
        run: |
          status=$(curl --silent --max-time 10 \
            --header "Authorization: Bearer $QELKA_API_KEY" \
            --dump-header headers.txt --output account.json \
            --write-out '%{http_code}' \
            https://api.qelka.com/v1/account) || status=000
          request_id=$(grep -i '^x-request-id:' headers.txt 2>/dev/null | cut -d ' ' -f 2 | tr -d '\r') || true
          case "$status" in
            200)
              mode=$(jq -r '.key.mode' account.json)
              prefix=$(jq -r '.key.prefix' account.json)
              if [ "$mode" != "live" ]; then
                echo "::error::Production runs with a $mode key ($prefix)"
                exit 1
              fi
              echo "Key $prefix is live, $(jq -r '.credits.balance' account.json) credits left"
              ;;
            401|403)
              echo "::error::API key refused: $(jq -r '.error.type' account.json), request $request_id"
              exit 1
              ;;
            *)
              echo "::warning::API key check skipped: HTTP $status, request $request_id"
              ;;
          esac

The step needs curl and jq on the runner: install them first if your runner image lacks them.

Result Meaning What the step does
200, key.mode is live The key works and is a live key Passes and logs the key prefix and balance
200, key.mode is test Production would trust simulated answers Fails
401 invalid_api_key The key is missing, mistyped or revoked Fails
403 forbidden The key is restricted and lacks account Fails: create a key with account ticked
429, 5xx or no answer A temporary problem, on our side or the network's Warns and passes

If you deploy with a GitHub environment, you can store the live key as an environment secret instead, so only jobs that reference the environment can read it. As far as we know, environment secrets in private repositories need a paid GitHub plan: check yours.

Handle errors and rate limits

Nothing is billed on errors, and test keys are never billed at all. A 401 or 429 refused by the API does not count toward your limits. A key allows 200 requests per 10 seconds, and test keys share the organization window with your live traffic, so a CI suite that fires hundreds of requests at once can slow production down: keep suites small and sequential, as node --test runs the tests of one file in order. The validation module retries a 429 once when Retry-After is short, and otherwise returns unchecked. See Errors, Rate limits and the Go-live checklist.

Frequently asked questions

Do CI runs spend credits?
Not with a sk_test_ key: test keys never debit credits, and credits_used is 0 on every answer. They do share the rate limits of live keys, and every key of your organization shares one organization window, so keep test suites small. The smoke check uses GET /account, which is free with any key.
What happens on pull requests from forks?
GitHub does not pass repository secrets to workflows triggered from a fork, or to Dependabot runs, so the key variable is empty there. The workflow below skips the integration step when the variable is empty instead of failing. Your own branches and pull requests run the tests normally.
Should a failed smoke check fail the deploy?
Fail it when the key itself is wrong: a revoked, mistyped or test key in production needs a fix before traffic arrives. Do not fail it when the API is slow, rate limited or unreachable. The step below turns those cases into a warning, so an outage on our side never blocks your release.

More in Developer tools

All integrations

Put this check in your product

Get an API key in under a minute. 100 free credits every month, no card required.

  • 100 free credits a month
  • No card
  • Test keys spend nothing
  • Cancel any time