Examples
Real pipelines you can drop into a repo and adapt. Every example on this page is checked in CI: it must parse against the real schema, and every with: key must be a parameter the task actually accepts.
resource_class at the top level is the default for every job; a job can override it with its own resource_class (see the schema reference). Every step needs a name.
A with: key that isn't a parameter of the task is silently dropped: no error, the build just doesn't do what you meant. Every task's exact parameters are in the catalog.
Node.js test + Docker publish
version: '1'
name: nodejs-build-and-publish
resource_class: medium
on:
push:
branches: [main]
jobs:
test:
steps:
- name: Checkout
uses: loha/git-clone@v1
- name: Install
run: npm ci
- name: Test
run: npm test
publish:
needs: [test]
steps:
- name: Checkout
uses: loha/git-clone@v1
- name: Build and push image
uses: loha/buildah-build@v1
with:
IMAGE: registry.example.com/acme/web:${COMMIT_SHA}
buildah-build takes the whole image reference in IMAGE, tag included. There is no separate TAG parameter. ${COMMIT_SHA} is one of the three context tokens Loha substitutes into with: values.
Python lint + test on pull request
version: '1'
on:
pull_request:
branches: [main]
jobs:
lint:
steps:
- name: Checkout
uses: loha/git-clone@v1
- name: Install ruff
run: pip install ruff
- name: Lint
run: ruff check .
test:
needs: [lint]
steps:
- name: Checkout
uses: loha/git-clone@v1
- name: Install dependencies
run: pip install -r requirements.txt
- name: Test
run: pytest
Build and deploy to Kubernetes
version: '1'
resource_class: medium
on:
push:
branches: [main]
jobs:
build:
steps:
- name: Checkout
uses: loha/git-clone@v1
- name: Build and push image
uses: loha/buildah-build@v1
with:
IMAGE: registry.example.com/acme/api:${COMMIT_SHA}
deploy:
needs: [build]
steps:
- name: Checkout
uses: loha/git-clone@v1
- name: Update manifest
uses: loha/git-update-manifest@v1
with:
GIT_REPOSITORY: https://git.example.com/acme/infra.git
IMAGE_NAME: registry.example.com/acme/api
IMAGE_TAG: ${COMMIT_SHA}
secrets:
- GITOPS_TOKEN
git-update-manifest commits the new image reference to your GitOps repository; your GitOps tool rolls it out. To deploy to VMs, use a deploy target.
Inside one config, a job can choose by branch or event with if:, for example if: event == 'tag' on a production deploy job. To keep staging and production in separate configs instead, create two triggers with different branch/tag filters, each pointing at its own config. Whether a build starts at all is decided by the trigger, not inside the pipeline.
Cached install
cache writes to storage Loha manages — there is no bucket, endpoint or credential to configure. Caching is a restore step before the install and a save step after; the key is derived from hashing KEY_FILES, so it invalidates itself when your lockfile changes.
version: '1'
on:
push:
branches: [main]
jobs:
build:
steps:
- name: Checkout
uses: loha/git-clone@v1
- name: Restore cache
uses: loha/cache@v2
with:
ACTION: restore
PATHS: node_modules,.npm
KEY_FILES: package-lock.json
CACHE_PREFIX: web
- name: Install
run: npm ci
- name: Build
run: npm run build
- name: Save cache
uses: loha/cache@v2
with:
ACTION: save
PATHS: node_modules,.npm
KEY_FILES: package-lock.json
CACHE_PREFIX: web
Caching needs no credentials: storage is provided, and the build asks Loha for a URL rather than holding a key. See the caching guide for how the per-branch scoping decides when you get a hit.
See also
- Schema: every field explained
- Errors: what to do when validation fails
- Caching: the cache task in depth
- Official tasks: every
uses:reference, with parameters