GitHub Actions Advanced Skill
Expert guidance for designing, writing, debugging, and securing production-grade GitHub Actions workflows.
Detailed Guide
Read the detailed guide before executing this skill. It retains the complete procedure and reference material. Treat its safety, prerequisites, and validation requirements as mandatory. For focused work, load the relevant sections; for end-to-end work, read the guide completely.
When to Use This Skill
- User mentions GitHub Actions,
.github/workflows, CI/CD pipelines, runners, jobs, steps, or actions
- User wants to automate builds, tests, deployments, or releases via GitHub
- User asks about matrix builds, reusable workflows, composite actions, or self-hosted runners
- User needs help with OIDC authentication, caching strategies, or secrets management
- User says "my GitHub pipeline is failing" or "set up CI for my repo"
- User asks about workflow security, hardening, or environment protection rules
When NOT to Use This Skill
- The user is working with GitLab CI/CD → recommend
gitlab-ci-patterns
- The user is working with CircleCI, Jenkins, or other CI platforms
- The task is purely about Docker image building without GitHub context → recommend
docker-expert
- The task is about Kubernetes deployment configuration → recommend
kubernetes-architect
Security Hardening
1. Always Declare Permissions (Least Privilege)
# Workflow-level default — restrict everything
permissions:
contents: read
jobs:
publish:
# Job-level override — only expand what's needed
permissions:
contents: write # Only for release/publish jobs
packages: write # Only for container push jobs
pull-requests: write # Only for PR comment jobs
id-token: write # Only for OIDC auth jobs
2. Pin Third-Party Actions to Full Commit SHA
# ❌ UNSAFE — tag can be mutated or hijacked
- uses: actions/checkout@v4
# ✅ SAFE — commit SHA is immutable
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
# Tool to automate SHA pinning:
# npx pin-github-action .github/workflows/*.yml
# or: pip install ratchet && ratchet pin .github/workflows/
3. Prevent Script Injection
# ❌ UNSAFE — attacker controls PR title, which gets expanded in shell
- run: echo "${{ github.event.pull_request.title }}"
# ✅ SAFE — pass through environment variable (shell doesn't evaluate it)
- env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: echo "$PR_TITLE"
# ✅ SAFE — expressions in if: conditions are evaluated by Actions, not shell
- if: github.event.pull_request.draft == false
run: echo "Not a draft"
Never place ${{ ... }} directly inside run: when the value can come from
PR metadata, workflow inputs, repository files, matrix JSON, or earlier job
outputs. Put it in env: first, validate allowlisted values where possible, and
reference the shell variable with quotes.
4. Restrict pull_request_target Usage
# Only run when a maintainer adds a specific label — prevents untrusted execution
on:
pull_request_target:
types: [labeled]
jobs:
validate:
# Double-guard: check label name AND author_association
if: |
github.event.label.name == 'safe-to-test' &&
(github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.author_association == 'OWNER')
5. Harden with StepSecurity
# Add to every workflow — hardens runner, monitors outbound traffic
- uses: step-security/harden-runner@4d991eb9995541a0b71d1b66f1f98a5f1bef422c # v2.11.0
with:
egress-policy: audit # Start with 'audit', move to 'block' after confirming allowlist
allowed-endpoints: >
api.github.com:443
registry.npmjs.org:443
objects.githubusercontent.com:443
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Always test reusable workflows in a feature branch before merging to main.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
1---2name: github-actions-advanced3description: >4 Design, debug, and harden GitHub Actions CI/CD workflows, including reusable5 workflows, matrix builds, self-hosted runners, OIDC authentication, caching,6 environments, secrets, and release automation.7category: devops8risk: safe9source: community10date_added: "2026-05-30"11metadata:12 source: https://skillmd.com/skills/francostino/github-actions-advanced13---1415# GitHub Actions Advanced Skill1617Expert guidance for designing, writing, debugging, and securing **production-grade** GitHub Actions workflows.1819---2021## Detailed Guide2223Read [the detailed guide](references/detailed-guide.md) before executing this skill. It retains the complete procedure and reference material. Treat its safety, prerequisites, and validation requirements as mandatory. For focused work, load the relevant sections; for end-to-end work, read the guide completely.2425## When to Use This Skill2627- User mentions GitHub Actions, `.github/workflows`, CI/CD pipelines, runners, jobs, steps, or actions28- User wants to automate builds, tests, deployments, or releases via GitHub29- User asks about matrix builds, reusable workflows, composite actions, or self-hosted runners30- User needs help with OIDC authentication, caching strategies, or secrets management31- User says "my GitHub pipeline is failing" or "set up CI for my repo"32- User asks about workflow security, hardening, or environment protection rules3334## When NOT to Use This Skill3536- The user is working with GitLab CI/CD → recommend `gitlab-ci-patterns`37- The user is working with CircleCI, Jenkins, or other CI platforms38- The task is purely about Docker image building without GitHub context → recommend `docker-expert`39- The task is about Kubernetes deployment configuration → recommend `kubernetes-architect`4041---4243## Security Hardening4445### 1. Always Declare Permissions (Least Privilege)4647```yaml48# Workflow-level default — restrict everything49permissions:50 contents: read5152jobs:53 publish:54 # Job-level override — only expand what's needed55 permissions:56 contents: write # Only for release/publish jobs57 packages: write # Only for container push jobs58 pull-requests: write # Only for PR comment jobs59 id-token: write # Only for OIDC auth jobs60```6162### 2. Pin Third-Party Actions to Full Commit SHA6364```yaml65# ❌ UNSAFE — tag can be mutated or hijacked66- uses: actions/checkout@v46768# ✅ SAFE — commit SHA is immutable69- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.27071# Tool to automate SHA pinning:72# npx pin-github-action .github/workflows/*.yml73# or: pip install ratchet && ratchet pin .github/workflows/74```7576### 3. Prevent Script Injection7778```yaml79# ❌ UNSAFE — attacker controls PR title, which gets expanded in shell80- run: echo "${{ github.event.pull_request.title }}"8182# ✅ SAFE — pass through environment variable (shell doesn't evaluate it)83- env:84 PR_TITLE: ${{ github.event.pull_request.title }}85 run: echo "$PR_TITLE"8687# ✅ SAFE — expressions in if: conditions are evaluated by Actions, not shell88- if: github.event.pull_request.draft == false89 run: echo "Not a draft"90```9192Never place `${{ ... }}` directly inside `run:` when the value can come from93PR metadata, workflow inputs, repository files, matrix JSON, or earlier job94outputs. Put it in `env:` first, validate allowlisted values where possible, and95reference the shell variable with quotes.9697### 4. Restrict `pull_request_target` Usage9899```yaml100# Only run when a maintainer adds a specific label — prevents untrusted execution101on:102 pull_request_target:103 types: [labeled]104105jobs:106 validate:107 # Double-guard: check label name AND author_association108 if: |109 github.event.label.name == 'safe-to-test' &&110 (github.event.pull_request.author_association == 'COLLABORATOR' ||111 github.event.pull_request.author_association == 'MEMBER' ||112 github.event.pull_request.author_association == 'OWNER')113```114115### 5. Harden with StepSecurity116117```yaml118# Add to every workflow — hardens runner, monitors outbound traffic119- uses: step-security/harden-runner@4d991eb9995541a0b71d1b66f1f98a5f1bef422c # v2.11.0120 with:121 egress-policy: audit # Start with 'audit', move to 'block' after confirming allowlist122 allowed-endpoints: >123 api.github.com:443124 registry.npmjs.org:443125 objects.githubusercontent.com:443126```127128---129130## Limitations131132- Use this skill only when the task clearly matches the scope described above.133- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.134- Always test reusable workflows in a feature branch before merging to main.135- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.