This guide covers how to create and customize GitHub Actions workflow templates using DevOps-OS tooling. The GitHub Actions generator helps you create workflows that integrate with your development environment and deployment needs.
- Understanding the GitHub Actions Generator
- Basic Usage
- Workflow Types
- Customization Options
- Matrix Builds
- Kubernetes Integration
- Reusable Workflows
- Environment Variables
- Advanced Customization
- Examples
The GitHub Actions generator (github-actions-generator-improved.py) creates YAML workflow files that orchestrate continuous integration and deployment processes using GitHub's action system. The workflows leverage the DevOps-OS container to provide a consistent environment for building, testing, and deploying your applications.
To generate a basic GitHub Actions workflow:
python -m cli.scaffold_gha --name "My Workflow" --type completeThis generates a complete CI/CD workflow including build, test, and deploy stages.
Output: .github/workflows/my-workflow-complete.yml
The filename is built as <name-lowercased-and-hyphenated>-<type>.yml inside the output directory.
Change the output directory with --output <dir> (default: .github/workflows/).
The generator supports several types of workflows:
- Build Workflow (
--type build): Focuses on building and packaging your application. - Test Workflow (
--type test): Focuses on running tests and validating your application. - Deploy Workflow (
--type deploy): Focuses on deploying your application to the target environment. - Complete Workflow (
--type complete): Combines build, test, and deploy stages. - Reusable Workflow (
--type reusableor--reusable): Creates a reusable workflow that can be called from other workflows.
--name: The name of the workflow (e.g., "Backend CI/CD")--languages: Comma-separated list of languages to enable (e.g., "python,java,javascript,go")--output: Output directory for the generated workflow file
python -m cli.scaffold_gha --name "Python API" --languages python --output ./.github/workflowsOutput: .github/workflows/python-api-complete.yml
Matrix builds allow you to run your workflows across multiple configurations, such as different operating systems or language versions:
python -m cli.scaffold_gha --matrixOutput: .github/workflows/devops-os-complete.yml
This creates a workflow with a matrix strategy that runs on multiple platforms.
For more advanced matrix configurations, you can provide a custom values file:
{
"matrix": {
"os": ["ubuntu-latest", "windows-latest", "macos-latest"],
"python-version": ["3.8", "3.9", "3.10", "3.11"],
"exclude": [
{
"os": "windows-latest",
"python-version": "3.11"
}
]
}
}python -m cli.scaffold_gha --custom-values matrix-config.jsonTo include Kubernetes deployment steps in your workflow:
python -m cli.scaffold_gha --kubernetes --k8s-method kubectlFour Kubernetes deployment methods are supported:
- kubectl (
--k8s-method kubectl): Direct deployment using kubectl commands. - kustomize (
--k8s-method kustomize): Deployment using Kustomize for environment-specific configurations. - argocd (
--k8s-method argocd): GitOps deployment using ArgoCD. - flux (
--k8s-method flux): GitOps deployment using Flux CD.
Reusable workflows can be called from other workflows, making them ideal for creating standardized CI/CD templates:
python -m cli.scaffold_gha --type reusableOutput: .github/workflows/devops-os-reusable.yml
The generated reusable workflow can be called from another workflow:
jobs:
call-devops-os-workflow:
uses: ./.github/workflows/devops-os-reusable.yml
with:
languages: '{"python": true, "java": true}'
deploy_environment: 'production'All options can be set using environment variables prefixed with DEVOPS_OS_GHA_:
export DEVOPS_OS_GHA_NAME="API Service"
export DEVOPS_OS_GHA_TYPE="complete"
export DEVOPS_OS_GHA_LANGUAGES="python,go"
export DEVOPS_OS_GHA_KUBERNETES="true"
export DEVOPS_OS_GHA_K8S_METHOD="kustomize"
export DEVOPS_OS_GHA_MATRIX="true"
python -m cli.scaffold_gha
# Output: .github/workflows/api-service-complete.ymlFor advanced customization, create a custom values JSON file:
{
"build": {
"cache": true,
"timeout_minutes": 30,
"artifact_paths": ["dist/**", "build/**"]
},
"test": {
"coverage": true,
"junit_reports": true,
"parallel": 4,
"timeout_minutes": 20
},
"deploy": {
"environments": ["dev", "staging", "prod"],
"approval_required": true,
"rollback_enabled": true
},
"notifications": {
"slack": {
"channel": "deployments",
"success": true,
"failure": true
},
"email": {
"recipients": ["team@example.com"],
"on_failure_only": true
}
}
}python -m cli.scaffold_gha --custom-values advanced-config.jsonThe generator integrates with the DevOps-OS devcontainer.env.json file to ensure consistency between your development environment and CI/CD workflows:
python -m cli.scaffold_gha --env-file ./devcontainer.env.jsonpython -m cli.scaffold_gha --name "Python App" --languages python --type complete
# Output: .github/workflows/python-app-complete.ymlpython -m cli.scaffold_gha --name "Java Service" --languages java --custom-values maven-config.json
# Output: .github/workflows/java-service-complete.ymlpython -m cli.scaffold_gha --name "Microservices" --languages python,javascript,go --kubernetes --k8s-method kustomize
# Output: .github/workflows/microservices-complete.ymlpython -m cli.scaffold_gha --name "Node.js App" --languages javascript --matrix --custom-values node-matrix.json
# Output: .github/workflows/node-js-app-complete.ymlpython -m cli.scaffold_gha --name "Container Deploy" --languages go --kubernetes --k8s-method argocd --registry ghcr.io
# Output: .github/workflows/container-deploy-complete.ymlThe generated GitHub Actions workflow includes:
- Triggers: Configures when the workflow runs (push, pull request, workflow dispatch).
- Jobs: Defines the jobs to run (build, test, deploy).
- Steps: Details the steps within each job.
- Environment: Sets up the execution environment using the DevOps-OS container.
- Artifacts: Configures artifact handling for sharing between jobs.
- Deployments: Includes deployment steps if Kubernetes is enabled.
name: My CI/CD
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
environment:
description: Environment to deploy to
required: true
default: dev
type: choice
options: [dev, test, staging, prod]
jobs:
build:
runs-on: ubuntu-latest
container:
image: ghcr.io/yourorg/devops-os:latest
steps:
# Build steps here
test:
needs: build
runs-on: ubuntu-latest
container:
image: ghcr.io/yourorg/devops-os:latest
steps:
# Test steps here
deploy:
needs: test
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
container:
image: ghcr.io/yourorg/devops-os:latest
steps:
# Deploy steps here- Start Simple: Begin with a basic workflow and add complexity as needed.
- Use Environment Variables: Use environment variables for secrets and configuration.
- Leverage Matrix Builds: Use matrix builds for testing across multiple configurations.
- Use Reusable Workflows: Create reusable workflows for common patterns.
- Custom Values: Use custom values files for advanced configuration.
- Integration with DevOps-OS: Integrate with your DevOps-OS configuration for consistency.
- Explore the Jenkins Pipeline Generator for creating Jenkins pipelines.
- Learn about Kubernetes deployments for deploying your applications.
- Implement CI/CD pipelines for technology stacks specific to your project.