DEV Community

Ti Gg
Ti Gg

Posted on

Stop rebuilding the same pipelines: 14 CI/CD templates and the conventions behind them

Every new repository starts the same way: someone copies the pipeline from the
previous repo, edits a couple of lines, and moves on. Six months later you have
seven pipelines that all claim to run the tests, and no two of them do it the
same way. The staging deploy on repo 3 has no cache; repo 5 runs npm ci twice;
repo 7 never uploads its SBOM. Nobody decides this — it just happens.

The alternative is to treat CI configuration as a library: a small set of
templates that agree on names, secrets and artifact paths, so a pipeline can be
dropped into a repo and adapted rather than written from scratch.

Here is the set of decisions that makes that work, with the actual configuration
behind each one.

The conventions everything else depends on

Before the individual pipelines, four rules. They are what turns "14 YAML files"
into a set that composes.

One file per pipeline. A workflow file does one job: pr-check.yml,
release.yml, staging-deploy.yml. A 400-line workflow that builds, scans,
signs and deploys cannot be reused; three small ones can.

Names are part of the interface. Job and artifact names are stable across
repos (build, test, sbom, container-image), so a dashboard, a
notification template or a status check can rely on them.

Secrets are declared, never invented. Every template lists the secrets it
reads at the top of the file. A template that silently expects NPM_TOKEN is a
template that fails at 2 a.m. in someone else's repository.

Cache keys include the lockfile hash. The trick is that the cache changes
exactly when the dependencies do. actions/setup-node does it for you with
cache: npm (it hashes the lockfile internally); when you cache something
else, write the key yourself:
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}.
Without the hash you either ship stale node_modules or never hit the cache.

GitHub Actions

The pull request check

Matrix over Node versions, dependency cache, and a single job that must pass
before anything else happens:

name: pr-check
on:
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node: ['20', '22']
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
          cache: npm
      - run: npm ci
      - run: npm run lint
      - run: npm test -- --ci
Enter fullscreen mode Exit fullscreen mode

fail-fast: false is deliberate: on a matrix, one green run tells you more than
"the first failure cancelled the others".

Release on a tag

name: release
on:
  push:
    tags: ['v*']

jobs:
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - run: npm ci && npm run build
      - run: npm test
      - uses: softprops/action-gh-release@v2
        with:
          files: dist/**
          generate_release_notes: true
Enter fullscreen mode Exit fullscreen mode

fetch-depth: 0 is required: the release notes generator and any
git describe-based versioning need the full history, and a shallow clone
breaks them in a way that only shows up on the release tag.

Dependabot, CodeQL, staging deploy

dependabot.yml is five lines and opens a pull request whenever a dependency
has a newer release — it is the boring half of staying current:

version: 2
updates:
  - package-ecosystem: npm
    directory: /
    schedule:
      interval: weekly
Enter fullscreen mode Exit fullscreen mode

CodeQL runs as its own job with security-events: write permission — a
separate workflow, on a schedule, so a code-scanning finding never blocks an
unrelated pull request.

The staging deploy is the one that needs care, because it is the only template
that touches an environment:

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run build
      - run: ./scripts/migrate.sh --dry-run
      - run: ./scripts/deploy.sh
        env:
          DEPLOY_TOKEN: ${{ secrets.STAGING_DEPLOY_TOKEN }}
Enter fullscreen mode Exit fullscreen mode

Two things are deliberate. The migration runs dry first — a deploy that
migrates and then deploys is a deploy that can leave the database in a state no
code expects. And the secret comes from env:, never interpolated into the
run: string, so it cannot end up in a shell trace.

GitLab CI

The full pipeline

stages: [build, test, security, package, deploy]

build:
  stage: build
  image: node:22
  script:
    - npm ci
    - npm run build
  artifacts:
    paths: [dist/]
    expire_in: 1 week

test:
  stage: test
  image: node:22
  script:
    - npm ci
    - npm run lint
    - npm test -- --ci
Enter fullscreen mode Exit fullscreen mode

The artifact is produced once in build and reused downstream. Re-building in
every stage is both slow and a source of "it passed in one stage and failed in
another".

Container scan and SAST, and an SBOM

Security stages usually rot, because nobody wants to be the one who blocks a
merge. Keep them narrow and explicit about what fails the job:

container-scan:
  stage: security
  image: aquasec/trivy:latest
  script:
    - trivy image --severity HIGH,CRITICAL --exit-code 1 $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA

sbom:
  stage: security
  image: cyclonedx/cyclonedx-node
  script:
    - npx @cyclonedx/cyclonedx-npm --output-format json --output sbom.json
  artifacts:
    paths: [sbom.json]
Enter fullscreen mode Exit fullscreen mode

--exit-code 1 is the part people leave out: without it, the scanner reports
and the job stays green.

A CycloneDX SBOM is a small file with a long half-life. It answers "which
version of this library is in the image I am running?" — a question that, six
months later, nobody can answer from memory.

n8n workflows

The same logic applies to glue code. Four workflows cover the cases that come up
constantly:

RSS to Slack, with deduplication. The important detail is not the fetch, it
is the "already sent" check, otherwise a feed that publishes twice a day
becomes a wall of duplicate messages:

const seen = $('Get seen items').first().json.seen;
for (const item of $input.all()) {
  if (seen.includes(item.json.guid)) continue;
  // post to Slack, then record the guid
}
Enter fullscreen mode Exit fullscreen mode

Webhook to Google Sheets. A POST trigger, a field-mapping step, and an
append. The mapping is the configuration; keeping it in one node means changing
a column name does not mean editing a script.

GitHub pull request to Discord. The webhook payload carries the PR title,
author and status — three messages, one per event type, each mentioning the
right role. The trap is announcing "PR merged" on the opened event.

RSS to Discord digest. One message per day instead of one per item: fetch,
group by day, sort, emit. Deferring the aggregation to a scheduled trigger is
what makes it a digest rather than a firehose.

Drop them in, adapt, ship

That is the whole set: 5 GitHub Actions workflows, 5 GitLab CI pipelines, 4 n8n
workflows, and the conventions file they all follow. Each template lists the
secrets it needs, the placeholders you replace (REPLACE_*), and the exact
conventions it assumes, so adapting one is a diff rather than a rewrite.

The full set is published as a single MIT-licensed ZIP here:
CI/CD & Automation Templates

It is worth being precise about what this is and is not. It is 14 configuration
files with the comments, the secret lists and the naming conventions already
consistent — no magic, no black box, no service to sign up for. What it will
not do is tell you which pipeline your project needs, or replace the judgment
of someone who has operated your system for five years. Take the ones that
match, rename them to your conventions, and delete the rest.


Disclosure: this article was written with the help of AI and reviewed before publication.

Top comments (0)