Skip to main content
📬 Get weekly Production AI insightsPractical notes on Kubernetes, AI infrastructure and platform engineering. No spam.Subscribe free
Editorial cover for an event-driven CI/CD engineering guide
DevOps

Event-Driven CI/CD: Stop Polling, Skip No-Op Updates, and Build Only When Needed

Replace runner sleeps with deployment events, make automated updates idempotent, and use fail-safe Git diffs to avoid unnecessary Vercel builds.

Luca Berton

· The Production AI Expert

Published ·7 min read

An optimized pipeline is not just a faster pipeline. It is a pipeline that knows when there is nothing to do. A runner waiting for a hosting provider, a scheduled job rewriting an unchanged JSON document, and a production build triggered by a workflow-only edit are three different forms of the same problem: spending compute without creating useful new output.

During a recent multi-site CI/CD optimization project, I found all three patterns. This article describes the improvements, their failure modes, and how to validate them. The sites are intentionally anonymized. It follows my multi-site pipeline standardization guide and build ownership and cost guide.

1. Replace waiting with an event

A workflow triggered by a Git push can easily finish before the corresponding Vercel deployment is available. If its next task notifies search engines about new URLs, sending the notification immediately can expose stale pages or a 404. One common workaround is a fixed sleep:

- name: Wait for hosting
  run: sleep 120
- name: Notify search engines
  run: node scripts/submit-indexnow.cjs

This consumes two runner minutes regardless of how quickly hosting finishes, and it still cannot prove that production is ready. Polling improves the evidence but continues occupying a runner. If the hosting integration emits a reliable completion event, let that event start the notification instead.

name: IndexNow
on:
  deployment_status:
permissions:
  contents: read
concurrency:
  group: indexnow-production
  cancel-in-progress: false
jobs:
  submit:
    if: >-
      github.event.deployment_status.state == 'success' &&
      github.event.deployment_status.environment == 'Production'
    runs-on: ubuntu-24.04
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v5
        with:
          ref: ${{ github.event.deployment.sha }}
          persist-credentials: false
      - uses: actions/setup-node@v5
        with:
          node-version: '22'
          package-manager-cache: false
      - run: node scripts/submit-indexnow.cjs --live

This illustrative workflow assumes the configured provider emits the documented environment label and the script supports a live-sitemap mode. Pin reviewed action SHAs in production, and adapt the runtime to the application. See the GitHub deployment_status event reference.

Before adopting it, inspect real event history. Verify the source, production environment, intended commit and canonical production alias. If you intend to process a particular revision, confirm it is still the active production revision or use a verified release ledger. A successful status on an old deployment does not necessarily mean its content is currently served. Never use a preview status as evidence of a production release.

In the investigation, one public repository’s first event-triggered notification job ran successfully after the change. A second repository received the event but its runner failed before executing the submission. Event delivery and successful execution are distinct milestones. Keep the old delivery mechanism until the replacement has been demonstrated, or provide a bounded reconciliation path for missed events.

2. Avoid rebuilding merely to read a sitemap

If the goal is to notify IndexNow after publication, a production sitemap is often the appropriate source. There is usually no reason to reinstall the framework or compile a second static site just to generate a sitemap that production already serves.

Fetch the canonical sitemap over HTTPS with a bounded timeout. Validate its structure, follow only approved same-origin sitemap documents if it is an index, and filter URLs to the registered host. Deduplicate them, enforce protocol batch limits, and validate the response. Prefer changed URLs when the deployment diff can be determined reliably; a full sitemap submission on every deploy can create unnecessary network traffic.

The IndexNow protocol allows submissions after URLs are added, updated or deleted. A notification is not a guarantee of indexing. Distinguish the HTTP response from crawler behavior and search visibility. Repeated deployment events can also cause repeated notifications: a durable idempotency record keyed by site and deployment or content version can prevent duplicates. A concurrency group alone is not such a record.

3. Make scheduled updates idempotent

Consider a weekly task that mirrors a product catalog into a JSON snapshot. A naive implementation writes a new timestamp on every execution, even when the product set is identical. That timestamp creates a Git diff, a pull request, another CI run and potentially a hosting deployment.

Compare the semantic payload first. For a catalog where only the set of product slugs matters, order and duplicate entries should not produce changes:

function normalize(values) {
  if (!Array.isArray(values) || !values.length ||
      values.some(v => typeof v !== 'string' || !v.trim() || v !== v.trim())) {
    throw new Error('Invalid product slug list');
  }
  return [...new Set(values)].sort();
}

function reconcile(previous, incoming, now = new Date().toISOString()) {
  const oldSlugs = normalize(previous.product_slugs);
  const newSlugs = normalize(incoming);
  if (JSON.stringify(oldSlugs) === JSON.stringify(newSlugs)) return null;
  return { ...previous, product_slugs: newSlugs, fetched_at: now };
}

Write the file only when reconcile returns a new value. When the data is unchanged, preserve the original file byte-for-byte. The timestamp now represents a meaningful snapshot update rather than every attempted refresh. Keep an operational last-checked timestamp in logs or metrics if freshness monitoring needs one.

Test reordered values, duplicate values, genuine additions and removals, malformed data, and empty feed responses. This example rejects empty catalogs because the consuming application requires a nonempty fallback. Other catalogs may legitimately be empty; their validation contract should say so. Do not automatically merge a removal that breaks a consumer’s references.

4. Skip production builds only when the evidence is complete

Changing a CI workflow does not necessarily change the website. Vercel’s ignored build step can prevent unnecessary compilation, but its exit-code contract is easy to reverse: zero skips the build and one continues it.

The safer design uses a narrow allowlist and defaults to building if the deployment context is absent or ambiguous. Here is a simplified example for a project where the verified previous deployment revision and current revision are available:

#!/usr/bin/env bash
set -u
[[ "${VERCEL_ENV:-}" == production ]] || exit 1
[[ "${VERCEL_GIT_COMMIT_REF:-}" == main ]] || exit 1
base="${VERCEL_GIT_PREVIOUS_SHA:-}"
head="${VERCEL_GIT_COMMIT_SHA:-}"
[[ "$base" =~ ^[0-9a-fA-F]{40}$ && "$head" =~ ^[0-9a-fA-F]{40}$ ]] || exit 1
[[ "$base" != "$head" ]] || exit 1
[[ "$(git rev-parse HEAD 2>/dev/null)" == "$head" ]] || exit 1
git cat-file -e "$base^{commit}" 2>/dev/null || exit 1
git merge-base --is-ancestor "$base" "$head" || exit 1
changes=$(mktemp) || exit 1
trap 'rm -f "$changes"' EXIT
git diff --no-renames --name-only -z "$base" "$head" > "$changes" || exit 1
[[ -s "$changes" ]] || exit 1
while IFS= read -r -d '' file; do
  case "$file" in
    .github/workflows/*|.github/actions/*) ;;
    *) exit 1 ;;
  esac
done < "$changes"
exit 0

Use this only after confirming that the provider’s previous revision corresponds to the deployed baseline, that the Git history is available, and that none of those CI paths affects application output or required release behavior. A branch predecessor is not always the previous successful production deployment. If the variable is missing, the example deliberately builds. A verified baseline is particularly important after failed builds or skipped deployments.

Using a NUL-delimited diff avoids filename parsing errors, and disabling rename detection checks both the removed and the added paths. Empty diffs and same-SHA redeploys deliberately build; those redeploys may be needed after environment changes. Keep this allowlist narrow and test it in a temporary Git repository, including missing history and mixed application/CI edits. See the Vercel ignored build step guide.

An ignored build can still create a deployment attempt. It is not the same as preventing preview deployment creation. Measure the actual billed build duration and verify that a canceled build does not block a required production check.

5. Stop installing dependencies for dependency-free checks

A common CI smell is an npm installation before a script that imports only Node built-ins and local helpers. Inspect the whole dependency graph of the script before skipping installation. In one repository, the content generator, link checker and their local frontmatter helper did not require installed packages. Turning off installation for that job preserved its named check and removed one of three repeated dependency installations.

That is less disruptive than collapsing all named checks into a single job. Required GitHub checks and hosting deployment gates may depend on those names. Consolidation should follow an inventory of requirements, not precede it.

6. Reduce schedules intentionally

Another project started six scheduled release checks each day. The proposed schedule reduced that to one after the normal publishing window. Over a 30-day month, this removes 150 scheduled starts, or 83.3% of that schedule’s starts. If every removed run would have used two billed Linux minutes, the illustrative reduction is 300 minutes. Neither the equal-duration assumption nor the realized billing reduction has been established.

The trade-off is release latency: an episode or late external feed arriving outside the daily window might not be processed until the next successful run. If that is unacceptable, use an authenticated event from the publishing system and keep one daily reconciliation job. Do not remove time-sensitive publishing, recovery or security checks merely to improve a run-count chart.

7. Version shared improvements and validate the rollout

Once a common setup action accepts package manager, Node version, lockfile location and cache policy as inputs, another repository can consume it at an immutable commit. Retain a local wrapper so the rest of its workflows do not change. Start with one compatible public repository, validate its normal CI, and then migrate other runtime combinations. A pinned action is not automatically safe merely because it is shared; review updates, keep least-privilege permissions and ensure dependencies work in the consumer repository.

Record the rollout as separate facts: PR merged, workflow started, actual steps passed, intended production revision available, notification accepted, and savings measured. In this investigation, some private-repository jobs never executed their steps even after their proposed code changes were merged. Their integration is not proof of validation. The central scheduled controller also still requires an observed successful run before removing its local monitoring counterparts.

The recurring lesson is simple: compare state before writing, wait for evidence rather than sleeping, and skip work only when you can prove it is unnecessary. That is how an efficient delivery system avoids paying for the same result twice without sacrificing correctness.

Free 30-min Production AI consultation

Book Now