DevOps Intermediate
GitHub Actions — Advanced Workflows¶
GitHub ActionsCI/CDAutomation 6 min read
Advanced GitHub Actions techniques: matrix builds, reusable workflows, composite actions and self-hosted runners.
Matrix Builds¶
The matrix strategy enables parallel test runs across versions and platforms.
jobs:
test:
strategy:
matrix:
node: [18, 20, 22]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci && npm test
Reusable Workflows¶
Sharing workflows across repositories eliminates duplication. Define a workflow in a central repo and call it via workflow_call.
on:
workflow_call:
inputs:
environment:
required: true
type: string
secrets:
DEPLOY_KEY:
required: true
jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v4
- run: ./deploy.sh
env:
KEY: ${{ secrets.DEPLOY_KEY }}
Composite Actions¶
Composite actions combine multiple steps into a single reusable action with custom inputs and outputs.
name: Build and Push
inputs:
image:
required: true
runs:
using: composite
steps:
- run: docker build -t ${{ inputs.image }} .
shell: bash
- run: docker push ${{ inputs.image }}
shell: bash
Self-hosted Runners¶
For specific hardware requirements or private networks, deploy your own runner. Use actions-runner-controller for Kubernetes-native scaling.
apiVersion: actions.summerwind.dev/v1alpha1
kind: RunnerDeployment
metadata:
name: k8s-runners
spec:
replicas: 3
template:
spec:
repository: org/repo
labels:
- self-hosted
- linux
Summary¶
GitHub Actions is an extremely flexible CI/CD platform. Matrix builds, reusable workflows and composite actions dramatically reduce duplication and speed up the feedback loop.
Need Help with Implementation?¶
Our team has experience designing and implementing modern architectures. We’re happy to help.