Reusable GitHub Actions workflows for CI/CD pipelines, designed to streamline automation across multiple projects and promote consistency.
Each workflow lives in .github/workflows/ and is triggered with workflow_call, so other repositories can call it with a few lines of YAML instead of copying the whole pipeline.
Referencing a workflow @main always runs its latest version. If you prefer to decide when to pick up changes, pin a tag or a commit SHA instead.
Builds a Docker image from the repository root, scans it for vulnerabilities and publishes it to a container registry.
It runs these steps:
- Checks out the repository.
- Logs into the container registry.
- Generates the image tags and labels with docker/metadata-action, using its default rules (the Git tag on tag pushes,
pr-<number>on pull requests, the branch name on manual runs). - Sets up a BuildKit builder with docker/setup-buildx-action, which the layer cache needs.
- Builds the image with docker/build-push-action, reusing and saving layers in the GitHub Actions cache (
type=gha,mode=max). - Scans the image with Grype, through anchore/scan-action.
- Uploads the scan results in SARIF format to the repository's code scanning alerts.
- Pull requests only build the image. It is loaded into the runner's Docker daemon and scanned there, and nothing is pushed to the registry.
- Pull requests from forks get no secrets and a read-only token from GitHub, so they also skip the registry login and the upload of the scan results. The scan report is still printed in the job log.
- Any other event (a tag push or a manual run, for example) builds the image, pushes it to the registry and scans the published image. Its scan results are reported against the default branch, so they show up in the repository's main Security view.
The scan never fails the build (fail-build: false) and only reports vulnerabilities that already have a fix (only-fixed: true). Findings are meant to be reviewed in the Security tab, not to block a release because of an unfixable issue in a base image.
| Name | Required | Description |
|---|---|---|
container-registry |
yes | Registry host, e.g. docker.io or ghcr.io |
image-name |
yes | Image name without the registry, e.g. myuser/myimage |
| Name | Required | Description |
|---|---|---|
registry-username |
yes | User to log into the registry |
registry-access-token |
yes | Access token (or password) for that user |
The job requests contents: read, packages: write and security-events: write. A called workflow can't get more permissions than the caller allows, so if your repository restricts the default GITHUB_TOKEN permissions, grant them in the calling job (see the example below).
name: Docker image build and push
on:
workflow_dispatch:
push:
tags:
- '*'
pull_request:
branches:
- main
jobs:
build-and-push:
uses: mablanco/shared-github-workflows/.github/workflows/docker-build-push.yml@main
# Only needed if the repository restricts the default GITHUB_TOKEN permissions
permissions:
contents: read
packages: write
security-events: write
with:
container-registry: docker.io
image-name: myuser/myimage
secrets:
registry-username: ${{ secrets.DOCKERHUB_USERNAME }}
registry-access-token: ${{ secrets.DOCKERHUB_TOKEN }}Lints an Ansible role and tests it with Molecule.
It runs two jobs:
- lint: installs the role's
requirements-dev.txtand runs ansible-lint, once. - molecule: runs
molecule testonce for each entry ofmolecule-matrix, in parallel. A failing run doesn't cancel the others.
The tools come from the role's requirements-dev.txt, so each role pins its own versions of ansible-core, ansible-lint and Molecule, and uses the same ones locally. ansible-lint and Molecule read their usual configuration from the role (.ansible-lint, .yamllint, molecule/).
| Name | Required | Default | Description |
|---|---|---|---|
python-version |
no | 3.14 |
Python version for the tools |
molecule-matrix |
no | [{"name": "default"}] |
JSON list of Molecule runs (see below) |
Each entry of molecule-matrix has:
name: shown in the job name,Molecule (<name>).scenario(optional): the Molecule scenario to run. Defaults todefault.env(optional): environment variables for the run, asKEY=valuelines, for roles whose scenario reads them.
A role with only the default scenario:
name: CI
on:
push:
branches: [main]
pull_request:
# Weekly, to catch changes in the distributions' packages
schedule:
- cron: '0 6 * * 1'
workflow_dispatch:
jobs:
ci:
uses: mablanco/shared-github-workflows/.github/workflows/ansible-role-ci.yml@mainA role with several scenarios, or one scenario run with different variables:
jobs:
ci:
uses: mablanco/shared-github-workflows/.github/workflows/ansible-role-ci.yml@main
with:
molecule-matrix: >-
[{"name": "default"},
{"name": "upgrade", "scenario": "upgrade"},
{"name": "git", "env": "DEPLOY_METHOD=git"}]Dependabot checks the actions used by the workflows every week, so updates are reviewed and merged once here instead of in every repository that uses them.