Guide

CI/CD quality gate with a GitHub Action: fail the build when tests fail

Published

A quality gate is a check in your pipeline that decides whether a change may ship. TAIP offers one you can call three ways: a GitHub Action, a Node command-line tool with no dependencies, and webhooks for GitHub and GitLab. All three ask the same question: after running the tests you designated for this application, did every one pass? This guide shows how to wire each, with code copied from the TAIP platform repository, and how to make the job fail.

What a quality gate is

A quality gate is a rule applied at a fixed point in the pipeline, usually before a merge or a release: if the check does not pass, the change does not go on. What makes it a gate and not a report is that the outcome is binary and the pipeline obeys it.

TAIP's gate has exactly one rule: if a step fails, the gate fails. There is no minimum score, no non-blocking mode and no waiver by severity. A run still produces a score from 0 to 100, but the verdict does not depend on it: the gate passes only when the run completed and every selected test passed. The one exception is a test you put in quarantine: it still runs and its failure is reported, but it does not block. Apart from that, the strictness is on purpose, because a threshold such as “pass at 90” quietly turns a failing test into an accepted one.

Two things must exist before a call works: an API key, created in the TAIP app under Settings, API Keys (the app's labels are in English), and a gate suite, one of your existing suites, designated on the application (Application settings, Quality Gate Suite) or named on every call. Without a suite the call fails at once with NO_GATE_SUITE_CONFIGURED. The gate never falls back to running your whole test inventory, because a gate that quietly ran something else would report a green it has not earned.

Configure the GitHub Action

The Action is a composite action in the TAIP platform repository, in the folder tools/taip-gate. It needs Node.js 18 or later, which every GitHub-hosted runner has, and no install step. The workflow below is copied from that folder's README; your-org is the placeholder the README uses for the place where your copy of the folder lives.

name: Quality gate
on:
  pull_request:

jobs:
  quality-gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      # ... deploy your PR preview, capture its URL as $PREVIEW_URL ...

      - name: TAIP quality gate
        id: gate
        uses: your-org/taip-plataform/tools/taip-gate@main
        with:
          api-key: ${{ secrets.TAIP_API_KEY }}
          project: ${{ vars.TAIP_PROJECT_ID }}
          application: ${{ vars.TAIP_APPLICATION_ID }}
          url: ${{ env.PREVIEW_URL }}
          ref: ${{ github.sha }}
          timeout: '900'

      - name: Gate result
        if: always()
        run: |
          echo "state=${{ steps.gate.outputs.state }}"
          echo "score=${{ steps.gate.outputs.score }}"
          echo "evidence=${{ steps.gate.outputs.evidence-url }}"
From tools/taip-gate/README.md in the platform repository. The key comes from a repository secret, never from the file.

Four inputs are required: api-key, project, application and url. The key belongs in a secret, here TAIP_API_KEY, and the two ids in repository variables. Other inputs are suite, timeout (900 seconds by default), diff, config and api-url, and the workflow also sets ref to the commit SHA. The Action has three outputs, state, score and evidence-url, so a later step can post them on the pull request.

Inside, the Action checks that Node is 18 or later, then runs the command-line tool and hands it the key as an environment variable rather than an argument, so the key never appears in the shell's own argument list. It exits with the tool's exit code. The whole definition is below.

Show the whole action.yml
name: 'TAIP Quality Gate'
description: >-
  Runs the TAIP callable quality gate (POST/GET /api/v1/.../quality-gate/...)
  against a deployed environment and fails the job if the designated gate
  suite does not pass. Wraps tools/taip-gate/taip-gate.js -- a zero-runtime-
  dependency Node CLI -- so no npm install is needed in the consuming
  workflow.
author: 'TAIP'

inputs:
  api-key:
    description: 'TAIP API key. Pass this from a secret (e.g. ${{ secrets.TAIP_API_KEY }}) -- never hardcode it.'
    required: true
  project:
    description: 'TAIP project id.'
    required: true
  application:
    description: 'TAIP application id.'
    required: true
  url:
    description: 'URL of the deployed environment to run the gate against (e.g. a PR preview URL).'
    required: true
  ref:
    description: 'Commit SHA, PR number, or any string identifying the change under test.'
    required: false
  diff:
    description: >-
      Path to a unified diff of the change (e.g. produce it with
      `git diff origin/${{ github.base_ref }}...HEAD > taip.diff`). Only used by gates whose
      selection mode is IMPACTED. Omitting it is safe: such a gate then runs its FULL suite
      rather than narrowing on an unknown blast radius.
    required: false
    default: ${{ github.sha }}
  config:
    description: >-
      Path to a taip.yml declaring path->route/endpoint mappings, to unlock IMPACTED
      narrowing beyond what --diff's literal string matching can find on its own. Only
      'version' and 'paths' are honored in this release; a 'gates' section is parsed but
      never applied, and the CLI warns on stderr if one is present. Omitting it is safe.
    required: false
    default: ''
  suite:
    description: 'Explicit gate suite id, overriding the application''s configured default gate suite.'
    required: false
    default: ''
  timeout:
    description: 'Maximum seconds to wait for a terminal (PASSED/FAILED/ERROR) result.'
    required: false
    default: '900'
  api-url:
    description: 'TAIP API base URL.'
    required: false
    default: 'https://api.taiplabs.com'

outputs:
  state:
    description: 'Terminal state of the gate execution: PASSED, FAILED, or ERROR.'
    value: ${{ steps.run-gate.outputs.state }}
  score:
    description: 'Gate score (0-100), if the run reached a scored terminal state.'
    value: ${{ steps.run-gate.outputs.score }}
  evidence-url:
    description: 'Link to the run''s evidence/detail page in the TAIP app.'
    value: ${{ steps.run-gate.outputs.evidence-url }}

runs:
  using: 'composite'
  steps:
    - name: Check Node.js version
      shell: bash
      run: |
        if ! command -v node >/dev/null 2>&1; then
          echo "::error::node is not on PATH. This action needs Node.js >=18 (actions/setup-node@v4 with node-version >= 18 if your runner doesn't already have it)." >&2
          exit 1
        fi
        major=$(node -e "console.log(process.versions.node.split('.')[0])")
        if [ "$major" -lt 18 ]; then
          echo "::error::taip-gate needs Node.js >=18 for its built-in fetch; found $(node --version)." >&2
          exit 1
        fi

    - name: Run TAIP quality gate
      id: run-gate
      shell: bash
      env:
        TAIP_API_KEY: ${{ inputs.api-key }}
        TAIP_API_URL: ${{ inputs.api-url }}
        GATE_PROJECT: ${{ inputs.project }}
        GATE_APPLICATION: ${{ inputs.application }}
        GATE_URL: ${{ inputs.url }}
        GATE_REF: ${{ inputs.ref }}
        GATE_SUITE: ${{ inputs.suite }}
        GATE_DIFF: ${{ inputs.diff }}
        GATE_CONFIG: ${{ inputs.config }}
        GATE_TIMEOUT: ${{ inputs.timeout }}
      run: |
        set +e
        args=(--project "$GATE_PROJECT" --application "$GATE_APPLICATION" \
              --url "$GATE_URL" --ref "$GATE_REF" --timeout "$GATE_TIMEOUT" --json)
        if [ -n "$GATE_SUITE" ]; then
          args+=(--suite "$GATE_SUITE")
        fi
        if [ -n "$GATE_DIFF" ]; then
          args+=(--diff "$GATE_DIFF")
        fi
        if [ -n "$GATE_CONFIG" ]; then
          args+=(--config "$GATE_CONFIG")
        fi
        # --api-key is deliberately not passed as a plain argv value here --
        # TAIP_API_KEY (a step `env:`, GitHub Actions masks env values that
        # match a registered secret automatically) is picked up by the CLI
        # itself, so the raw key never appears in this shell's own argv or
        # in `set -x`-style debug logs.
        #
        # --json makes the CLI print exactly one JSON line to stdout on
        # every path (pass, fail, config error, infra error, timeout) --
        # captured here for output parsing. stderr is left to stream
        # straight into the job log uncaptured (it carries the same
        # human-readable summary, for anyone reading the log directly).
        result_file="$(mktemp)"
        node "${{ github.action_path }}/taip-gate.js" "${args[@]}" >"$result_file"
        exit_code=$?
        set -e

        cat "$result_file"

        state=$(node -e "try{const d=JSON.parse(require('fs').readFileSync(process.argv[1],'utf8').trim());process.stdout.write(d.state||'')}catch(e){process.stdout.write('')}" "$result_file")
        score=$(node -e "try{const d=JSON.parse(require('fs').readFileSync(process.argv[1],'utf8').trim());process.stdout.write(d.score===null||d.score===undefined?'':String(d.score))}catch(e){process.stdout.write('')}" "$result_file")
        evidence=$(node -e "try{const d=JSON.parse(require('fs').readFileSync(process.argv[1],'utf8').trim());process.stdout.write(d.evidence_url||'')}catch(e){process.stdout.write('')}" "$result_file")

        {
          echo "state=$state"
          echo "score=$score"
          echo "evidence-url=$evidence"
        } >> "$GITHUB_OUTPUT"

        rm -f "$result_file"
        exit $exit_code
tools/taip-gate/action.yml in the platform repository, the whole file.

The command-line tool, with no dependencies

The Action is a thin wrapper around taip-gate.js, a single Node file with no dependencies. It uses the fetch built into Node 18, so there is no npm install, no node_modules and no lockfile to audit. It starts an execution, asks for its state with a pause that grows from 2 seconds to a ceiling of 15, prints a summary and exits with a code your pipeline can act on.

Anywhere Node 18 runs, you can call it directly. This GitLab CI job is copied from the same README. It reads the key from the TAIP_API_KEY variable, which you define in GitLab as masked and protected, so the key never appears in the command line.

quality-gate:
  stage: test
  image: node:20-alpine
  # TAIP_API_KEY: define this in Settings -> CI/CD -> Variables as Masked
  # + Protected -- it does NOT need to be redeclared under `variables:`
  # here, GitLab already injects every project/group CI/CD variable into
  # the job environment. TAIP_PROJECT_ID / TAIP_APPLICATION_ID are your
  # own project/application ids from the TAIP app; PREVIEW_URL is
  # whatever an earlier step in this pipeline deployed and captured.
  script:
    - curl -fsSL -o taip-gate.js https://raw.githubusercontent.com/your-org/taip-plataform/main/tools/taip-gate/taip-gate.js
    - node taip-gate.js
        --project "$TAIP_PROJECT_ID"
        --application "$TAIP_APPLICATION_ID"
        --url "$PREVIEW_URL"
        --ref "$CI_COMMIT_SHA"
        --timeout 900
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
From tools/taip-gate/README.md. The job downloads the file from your copy of the repository; if the folder is already in your pipeline, copy taip-gate.js in at build time instead.

With --json the tool prints one JSON object on every path: state, score, passed and total tests, failing test names, blocking reasons and a link to the evidence page. Without Node at all, the same gate is two plain HTTP calls: a POST to /api/v1/projects/{project_id}/quality-gate/runs starts the execution and answers 202, and a GET to /api/v1/quality-gate/runs/{execution_id} returns its state. Both take the API key as a bearer token and are limited to 60 requests a minute.

Webhooks for GitHub and GitLab

The other way in is a webhook, which needs no workflow file: the Git host tells TAIP about each pull request and TAIP starts the gate itself.

  • GitHub

    You connect the repository in the project's Integrations settings, with an access token. TAIP creates the webhook and checks every delivery against its HMAC-SHA256 signature. The gate starts when a pull request is opened or updated, and only when it targets the default branch. TAIP then posts a commit status named TAIP Quality Gate and a check run with the same name, which carries the blocking reasons on the pull request. Either can be required in branch protection, but GitHub only offers a check in that list after it has run once on some commit.

  • GitLab

    You connect the project with an access token, through the TAIP API. TAIP then shows you a webhook secret once; paste it into GitLab's Add webhook form, because it cannot be read again. Every delivery must carry it in the X-Gitlab-Token header. The gate starts on a merge request event when the request is opened or updated and targets the default branch, and TAIP posts a commit status with the context taip-quality-gate.

Depending on your plan, gates started by pull or merge request webhooks may need the Starter plan, while the Action, the command line and the API run gates on demand. A connection with no application chosen starts nothing. The taip.yml file that can narrow which tests run is read by TAIP itself from the default branch, so a pull request cannot loosen its own gate by shipping a permissive file in the same commit. From the Action or the command line the file is supplied by the caller, and TAIP cannot confirm which branch it came from, so read it from a checkout you trust.

Make the job fail, and tell a failure from a fault

The exit code is the contract. 0 means the gate passed. 1 means the gate failed: a well-formed verdict that something did not pass. 2 means the call itself was wrong: a bad key, an unknown project or application, no gate suite, a missing address, or billing blocked. 3 means TAIP could not give a verdict: a network failure, an error response from TAIP, a run that ended in TAIP's own error state, or your timeout reached while the run was still pending.

The Action's step exits with that code, so the job turns red on 1, 2 and 3 without an extra line in the workflow. Keep the 1 apart from the 3. A 1 says the change should not ship; a 3 says nothing about the change, and running the job again is a reasonable response. A later step with if: always() can read the outputs, as in the workflow above, and post the evidence link on the pull request.

Know where it stops. The gate runs the suite you designated and nothing else, so it is only as good as that suite. A run still pending when the platform's own limit is reached, 10 minutes by default and adjustable per gate, ends in an error even if its tests are still running, so raise the limit for a long suite. The diff and config inputs can narrow a run to the impacted tests, but only when every changed file maps to a known route or endpoint; otherwise the whole suite runs, so expect narrowing to be rare.

Put a gate in front of your next merge

Connect your application, designate a gate suite and call the gate from one pipeline. Free Basic is free forever, with 500 credits a month and no credit card.