Skip to content

project rulesDevOps and cloudgithub-actions

GitHub Actions Rules

Project rules for GitHub Actions workflows: pinned actions, minimal token permissions, caching, reusable workflows and safe secret handling.

npx workspacetemplates add github-actions-rules --tool claude-code

Writes 1 file to your project root

CLAUDE.mdadd to your file21 lines · 1.4 KBFile
# Project rules: GitHub Actions

## Workflow layout
- One workflow per concern: `ci.yml`, `release.yml`, `deploy.yml`. Name jobs and steps in plain words so the checks list reads clearly.
- Pull shared logic into reusable workflows (`workflow_call`) or composite actions in `.github/actions`. Never paste the same ten steps twice.

## Security
- Declare `permissions:` at the top of every workflow as `contents: read`, then raise it per job only where needed.
- Pin third-party actions to a full commit SHA with the version in a trailing comment. First-party `actions/*` may use a major tag.
- Never interpolate `github.event.*` text (titles, branch names) into a `run:` script. Pass it through `env:` and quote the variable.
- Secrets come from `secrets.*` or OIDC federation to the cloud provider. Do not echo them, and do not use `pull_request_target` to run code from forks.

## Speed and reliability
- Set `concurrency` with `cancel-in-progress: true` for pull request runs, never for deploys.
- Cache dependencies with the setup action's built-in cache option, keyed on the lockfile.
- Set `timeout-minutes` on every job. Use a `matrix` for versions, with `fail-fast: false` when results are independent.
- Gate deploys with `environments` and required reviewers.

## Before finishing
- Lint the files with `actionlint`. Run the same build and test commands locally that the workflow runs.
- Explain any permission you raised in the pull request description.

What it does

These rules shape how an agent writes and edits workflow files under .github/workflows. They push every job toward the same safe defaults, so a generated pipeline does not start with broad permissions or floating action versions.

They also cover speed and reuse: dependency caching, concurrency groups and shared workflows, so CI stays fast and a fix lands in one place.

Example

you › Add a workflow that tests the Node app on pull requests

agent › The agent creates ci.yml with read-only permissions, a pinned setup-node step with lockfile caching, a concurrency group, a job timeout and a matrix over two Node versions, then runs actionlint.

Questions

Why pin to a commit SHA?
A tag can be moved after you review it. A full SHA fixes the exact code your pipeline runs, which blocks a hijacked release from reaching your secrets.
Does this work for GitLab CI?
No. The syntax and security model are specific to GitHub Actions, so keep a separate rules file for other CI systems.
  • AWS CDK Rules

    Project rulesaws

    Free
  • Docker Rules

    Project rulesdocker

    Free
  • Kubernetes Rules

    Project ruleskubernetes

    Free
  • Serverless Lambda Rules

    Project rulesaws

    Free