Building Custom GitHub Actions for Infrastructure Automation
Create reusable GitHub Actions to automate infrastructure tasks like Terraform deployments, secret rotation, and environment provisioning.
February 14, 2026 · 5 min · 984 words · Rob Washington
Table of Contents
GitHub Actions has become the de facto CI/CD platform for many teams, but most only scratch the surface with pre-built actions from the marketplace. Building custom actions tailored to your infrastructure needs can dramatically reduce boilerplate and enforce consistency across repositories.
// index.js
constcore=require('@actions/core');constgithub=require('@actions/github');asyncfunctionrun(){try{constenvironment=core.getInput('environment');constoctokit=github.getOctokit(process.env.GITHUB_TOKEN);// Create a deployment
constdeployment=awaitoctokit.rest.repos.createDeployment({owner:github.context.repo.owner,repo:github.context.repo.repo,ref:github.context.sha,environment:environment,auto_merge:false,required_contexts:[]});core.setOutput('deployment-id',deployment.data.id);core.info(`Created deployment ${deployment.data.id} for ${environment}`);}catch(error){core.setFailed(error.message);}}run();
With the corresponding action.yml:
1
2
3
4
5
6
7
8
9
10
11
name:'Create Deployment'description:'Create a GitHub deployment for environment tracking'inputs:environment:required:trueoutputs:deployment-id:description:'The created deployment ID'runs:using:'node20'main:'index.js'
git tag -a v1.0.0 -m "Initial release"git push origin v1.0.0
# Create a major version tag that moves with releasesgit tag -fa v1 -m "Update v1 to latest"git push origin v1 --force
Consumers reference @v1 for automatic minor/patch updates, or pin to @v1.0.0 for stability.
Custom GitHub Actions transform repetitive infrastructure tasks into maintainable, versioned code. Start with composite actions for simple orchestration, graduate to JavaScript for complex logic. Your future self (and teammates) will thank you when updating a deployment process means changing one file instead of fifty.
The real power emerges when you build an internal library of actions that encode your organization’s best practices — security policies, naming conventions, compliance checks — all enforced automatically on every commit.
📬 Get the Newsletter
Weekly insights on DevOps, automation, and CLI mastery. No spam, unsubscribe anytime.