Top 15 GitHub Actions Workflows for Automation

15 GitHub Actions workflows with YAML: CI matrix, CodeQL, dependency review, image build, attestations, OIDC deploys, Terraform, releases and Pages.

Dec 10, 2025 - 14:48
Nov 7, 2026 - 05:16
 0  512
Top 15 GitHub Actions Workflows for Automation

The most useful GitHub Actions workflows cover pull request checks (tests, linting, dependency review, CodeQL), delivery (container builds, provenance attestations, OIDC cloud deploys, Terraform plan and apply, releases, Pages) and repository chores (Dependabot auto-merge, labels, stale issues, reusable workflows and manual runbooks). This guide gives working YAML for 15 of them.

Each example below uses current major versions of the official actions, checked on their release pages in November 2026, and syntax checked against docs.github.com. It is part of our CI/CD pipeline examples series. For promoting one build through dev, staging and production with approvals, see the companion guide on GitHub Actions for multi-environment continuous deployment.

Key takeaways

  • Set permissions explicitly in every workflow. Start from contents: read and add only what a job needs, such as packages: write or id-token: write.
  • Use OIDC (id-token: write) to reach AWS, Azure or Google Cloud instead of storing long-lived keys as secrets.
  • Add concurrency to pull request workflows so a new push cancels the outdated run, and to deploy workflows so two deploys never overlap.
  • Version tags such as @v7 are readable but mutable. For third-party actions, pin to a full commit SHA and let Dependabot update it.
  • Move repeated jobs into a reusable workflow (on: workflow_call) rather than copying YAML between repositories.
  • Be careful with pull_request_target. It runs with write access and secrets, so never check out and run code from a fork in that context.

The 15 workflows at a glance

#WorkflowTriggerMain actions or toolsPermissions it needs
1CI test matrix with cachingpull_request, pushcheckout, setup-nodecontents: read
2Fast lint with path filters and cancel-in-progresspull_requestconcurrency, pathscontents: read
3Dependency reviewpull_requestdependency-review-actioncontents: read
4CodeQL code scanningpull_request, push, schedulecodeql-actionsecurity-events: write
5Dependabot auto-merge for patch updatespull_request_targetdependabot/fetch-metadata, ghcontents: write, pull-requests: write
6Build and push a container imagepush, tagsdocker metadata, buildx, build-pushpackages: write
7Image scan and provenance attestationafter buildTrivy CLI, actions/attestid-token, attestations, packages: write
8Deploy to AWS with OIDCpush to mainconfigure-aws-credentialsid-token: write
9Terraform plan on PR, apply on mergepull_request, pushsetup-terraformpull-requests: write, id-token: write
10Reusable workflowworkflow_callinputs, secrets, outputsSet by caller
11Release on tagpush tagsupload/download-artifact, ghcontents: write
12Label pull requests by changed filespull_request_targetlabelerpull-requests: write
13Close stale issues and PRsschedulestaleissues: write, pull-requests: write
14Deploy a static site to GitHub Pagespushconfigure-pages, upload-pages-artifact, deploy-pagespages: write, id-token: write
15Manual runbook with inputsworkflow_dispatchchoice inputs, environmentsDepends on the task

Pull request checks

1. CI test matrix with caching

Run the test suite on several runtime versions and operating systems in parallel. setup-node caches the npm download cache keyed on the lock file, so repeat runs install faster.

name: ci
on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest]
        node: [22, 24]
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: ${{ matrix.node }}
          cache: npm
      - run: npm ci
      - run: npm test

Set fail-fast: false when you want to see every failing combination instead of stopping at the first. Make the matrix job a required status check in branch protection so a failing combination blocks the merge.

2. Fast lint with path filters and cancel-in-progress

Skip the workflow when only docs change, and cancel the previous run on the same pull request when a new commit arrives. The concurrency group uses github.head_ref, which exists only for pull request events, with a fallback to the run ID.

name: lint
on:
  pull_request:
    paths:
      - "src/**"
      - "package*.json"
      - ".github/workflows/lint.yml"

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  lint:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 24
          cache: npm
      - run: npm ci
      - run: npm run lint

A caution: if this workflow is a required status check and a pull request touches no matching path, the check never reports and the pull request waits. Either keep path filters off required checks or make the job always run and exit early.

3. Dependency review

Fail a pull request that adds a dependency with a known vulnerability at or above a chosen severity. The action compares the dependency manifests between the base and head of the pull request.

name: dependency-review
on: pull_request

permissions:
  contents: read

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/dependency-review-action@v5
        with:
          fail-on-severity: high

Dependency review needs the dependency graph, which is on by default for public repositories. Organization-owned private repositories need a GitHub Advanced Security license, according to the action README.

4. CodeQL code scanning

CodeQL finds security bugs in source code and posts results to the repository's Security tab and to the pull request. A weekly schedule catches issues found by new queries in old code.

name: codeql
on:
  pull_request:
  push:
    branches: [main]
  schedule:
    - cron: "30 3 * * 1"

permissions:
  contents: read
  security-events: write

jobs:
  analyze:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        language: [javascript-typescript, python]
    steps:
      - uses: actions/checkout@v7
      - uses: github/codeql-action/init@v4
        with:
          languages: ${{ matrix.language }}
          build-mode: none
      - uses: github/codeql-action/analyze@v4

Interpreted languages work with build-mode: none. For Java, C# or C/C++, use autobuild or manual and add your build steps. Many repositories can turn on CodeQL "default setup" in settings without any YAML; use a workflow when you need custom queries or build steps.

5. Dependabot auto-merge for patch updates

Let low-risk dependency patches merge themselves once CI passes. The workflow only turns on GitHub's auto-merge; branch protection still decides when the merge happens.

name: dependabot-auto-merge
on: pull_request_target

permissions:
  contents: write
  pull-requests: write

jobs:
  automerge:
    runs-on: ubuntu-latest
    if: github.event.pull_request.user.login == 'dependabot[bot]'
    steps:
      - id: meta
        uses: dependabot/fetch-metadata@v3
      - if: steps.meta.outputs.update-type == 'version-update:semver-patch'
        run: gh pr merge --auto --squash "$PR_URL"
        env:
          PR_URL: ${{ github.event.pull_request.html_url }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

This uses pull_request_target because Dependabot pull requests get a read-only token under pull_request. The job never checks out the pull request code, which is what keeps it safe. Auto-merge must be enabled in the repository settings. Pair it with a .github/dependabot.yml that includes the github-actions ecosystem so your action pins stay current too.

Build and deliver

6. Build and push a container image

Build a multi-platform image, tag it from Git metadata (branch, semver tag, short SHA) and push it to GitHub Container Registry.

name: image
on:
  push:
    branches: [main]
    tags: ["v*.*.*"]

permissions:
  contents: read
  packages: write

jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      digest: ${{ steps.push.outputs.digest }}
    steps:
      - uses: actions/checkout@v7
      - uses: docker/setup-qemu-action@v4
      - uses: docker/setup-buildx-action@v4
      - uses: docker/login-action@v4
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - id: meta
        uses: docker/metadata-action@v6
        with:
          images: ghcr.io/${{ github.repository }}
          tags: |
            type=ref,event=branch
            type=semver,pattern={{version}}
            type=sha
      - id: push
        uses: docker/build-push-action@v7
        with:
          platforms: linux/amd64,linux/arm64
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

The digest output identifies the exact image that was pushed, which the next workflow uses for scanning and attestation. Dockerfile patterns for this step are in our Dockerfile examples.

7. Image scan and provenance attestation

Scan the pushed image and record signed build provenance so anyone can verify where it was built. This job continues the workflow above.

  scan-and-attest:
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
      id-token: write
      attestations: write
    env:
      IMAGE: ghcr.io/${{ github.repository }}
    steps:
      - uses: docker/login-action@v4
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Scan with Trivy
        run: |
          docker run --rm aquasec/trivy:0.76.2 image \
            --exit-code 1 --severity CRITICAL --ignore-unfixed \
            "$IMAGE@${{ needs.build.outputs.digest }}"
      - uses: actions/attest@v4
        with:
          subject-name: ${{ env.IMAGE }}
          subject-digest: ${{ needs.build.outputs.digest }}
          push-to-registry: true

Verify later with gh attestation verify oci://ghcr.io/OWNER/REPO@sha256:... --owner OWNER. On Free, Pro and Team plans, artifact attestations work only in public repositories; private repositories need GitHub Enterprise Cloud. As of version 4, actions/attest-build-provenance is a wrapper around actions/attest, so new workflows should call actions/attest directly. The scan above runs the Trivy image directly; a private registry may need credentials passed to the container.

Why pin versions so carefully: in March 2026 an attacker force-pushed most version tags of aquasecurity/trivy-action to malicious commits (CVE-2026-33634, GHSA-69fq-xp46-6x23). Workflows pinned to a full commit SHA kept running the code they had reviewed. Check the advisory for the affected and fixed versions before you pick a Trivy release.

8. Deploy to AWS with OIDC

GitHub issues a short-lived OIDC token, AWS exchanges it for temporary role credentials, and no access key is stored anywhere. The IAM role's trust policy should check the audience sts.amazonaws.com and a subject such as repo:OWNER/REPO:environment:production.

name: deploy
on:
  push:
    branches: [main]

permissions:
  contents: read
  id-token: write

concurrency:
  group: deploy-production
  cancel-in-progress: false

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    steps:
      - uses: actions/checkout@v7
      - uses: aws-actions/configure-aws-credentials@v6
        with:
          role-to-assume: arn:aws:iam::123456789012:role/github-deploy
          aws-region: ap-south-1
      - run: aws ecs update-service --cluster app --service web --force-new-deployment

Because the job references an environment, the token's subject claim uses the environment:production form rather than the branch form. That lets the role trust only jobs that passed the environment's protection rules. Azure (azure/login@v3) and Google Cloud (google-github-actions/auth@v3) follow the same pattern.

9. Terraform plan on pull request, apply on merge

Reviewers see the plan in the pull request; only main applies, behind an environment.

name: terraform
on:
  pull_request:
    paths: ["infra/**"]
  push:
    branches: [main]
    paths: ["infra/**"]

permissions:
  contents: read
  id-token: write
  pull-requests: write

defaults:
  run:
    working-directory: infra

jobs:
  plan:
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: aws-actions/configure-aws-credentials@v6
        with:
          role-to-assume: arn:aws:iam::123456789012:role/terraform-plan
          aws-region: ap-south-1
      - uses: hashicorp/setup-terraform@v4
        with:
          terraform_wrapper: false
      - run: terraform init -input=false
      - run: terraform fmt -check
      - run: terraform validate
      - run: terraform plan -input=false -no-color > plan.txt
      - run: |
          { echo '```text'; cat plan.txt; echo '```'; } > comment.md
          gh pr comment "${{ github.event.pull_request.number }}" --body-file comment.md
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  apply:
    if: github.event_name == 'push'
    runs-on: ubuntu-latest
    environment: infra-production
    concurrency:
      group: terraform-production
      cancel-in-progress: false
    steps:
      - uses: actions/checkout@v7
      - uses: aws-actions/configure-aws-credentials@v6
        with:
          role-to-assume: arn:aws:iam::123456789012:role/terraform-apply
          aws-region: ap-south-1
      - uses: hashicorp/setup-terraform@v4
      - run: terraform init -input=false
      - run: terraform apply -input=false -auto-approve

Use a read-only role for plan and a separate role for apply, and give the infra-production environment required reviewers so a person approves before apply runs. Very large plans can exceed the comment size limit; in that case upload the plan as an artifact and post a summary.

10. Reusable workflow

Write a job once and call it from many workflows or repositories. The called file declares on: workflow_call with typed inputs, secrets and outputs.

# .github/workflows/node-ci.yml (the reusable workflow)
name: node-ci
on:
  workflow_call:
    inputs:
      node-version:
        type: string
        default: "24"
    outputs:
      version:
        value: ${{ jobs.build.outputs.version }}

jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.v.outputs.version }}
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: ${{ inputs.node-version }}
          cache: npm
      - run: npm ci && npm test
      - id: v
        run: echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
# .github/workflows/ci.yml (the caller)
name: ci
on: [pull_request]
permissions:
  contents: read
jobs:
  call:
    uses: my-org/shared-workflows/.github/workflows/node-ci.yml@v1
    with:
      node-version: "22"
    secrets: inherit
  report:
    needs: call
    runs-on: ubuntu-latest
    steps:
      - run: echo "Built version ${{ needs.call.outputs.version }}"

Rules from the docs worth remembering: a calling job cannot use environment (set it inside the reusable workflow instead), you can nest up to ten levels of workflows in total, and secrets: inherit works only within the same organization or enterprise. Reference a local file as ./.github/workflows/node-ci.yml, or a remote one with owner/repo/.github/workflows/file.yml@ref, where a commit SHA is the safest ref.

11. Release on tag

Pushing a tag such as v1.4.0 builds artifacts and publishes a GitHub release with generated notes, using the preinstalled GitHub CLI instead of a third-party action.

name: release
on:
  push:
    tags: ["v*.*.*"]

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-go@v7
        with:
          go-version: stable
      - run: |
          GOOS=linux GOARCH=amd64 go build -o dist/app-linux-amd64 ./cmd/app
          GOOS=darwin GOARCH=arm64 go build -o dist/app-darwin-arm64 ./cmd/app
      - uses: actions/upload-artifact@v7
        with:
          name: binaries
          path: dist/

  publish:
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/download-artifact@v8
        with:
          name: binaries
          path: dist
      - run: gh release create "$GITHUB_REF_NAME" dist/* --generate-notes --repo "$GITHUB_REPOSITORY"
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Only the publish job gets contents: write. The build job, which runs your code and its dependencies, stays read-only.

Repository automation

12. Label pull requests by changed files

Apply labels such as infra or docs based on the paths a pull request touches. Rules live in .github/labeler.yml.

# .github/labeler.yml
infra:
  - changed-files:
      - any-glob-to-any-file: ["infra/**", "charts/**"]
docs:
  - changed-files:
      - any-glob-to-any-file: "docs/**"
# .github/workflows/labeler.yml
name: labeler
on: pull_request_target

permissions:
  contents: read
  pull-requests: write

jobs:
  label:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/labeler@v7

The labeler reads only file names from the pull request and never runs its code, which is why pull_request_target is acceptable here. Do not add a checkout of the pull request head to this workflow.

13. Close stale issues and pull requests

Mark inactive issues and pull requests as stale and close them if nobody responds.

name: stale
on:
  schedule:
    - cron: "15 2 * * *"
  workflow_dispatch:

permissions:
  issues: write
  pull-requests: write

jobs:
  stale:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/stale@v11
        with:
          days-before-stale: 45
          days-before-close: 14
          stale-issue-message: "No activity for 45 days. Comment to keep this open."
          stale-pr-message: "No activity for 45 days. Push a commit or comment to keep this open."
          exempt-issue-labels: "pinned,security"

Scheduled workflows run on the default branch. GitHub disables them in public repositories after 60 days without repository activity, so check the Actions tab if a quiet repository stops closing issues.

14. Deploy a static site to GitHub Pages

Build documentation or a static site and publish it with the official Pages actions. Set the Pages source to "GitHub Actions" in repository settings first.

name: pages
on:
  push:
    branches: [main]

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: pages
  cancel-in-progress: false

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/configure-pages@v6
      - uses: actions/setup-node@v7
        with:
          node-version: 24
          cache: npm
      - run: npm ci && npm run build
      - uses: actions/upload-pages-artifact@v5
        with:
          path: ./build

  deploy:
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - id: deployment
        uses: actions/deploy-pages@v5

15. Manual runbook with inputs

Turn a routine operation, such as restarting a service or running a database migration, into a button in the Actions tab with typed inputs and an audit trail.

name: runbook
on:
  workflow_dispatch:
    inputs:
      environment:
        type: environment
        required: true
      action:
        type: choice
        options: [restart, migrate, scale-up]
        required: true
      dry_run:
        type: boolean
        default: true

permissions:
  contents: read
  id-token: write

jobs:
  run:
    runs-on: ubuntu-latest
    environment: ${{ inputs.environment }}
    concurrency:
      group: runbook-${{ inputs.environment }}
      cancel-in-progress: false
    steps:
      - uses: actions/checkout@v7
      - run: ./ops/${{ inputs.action }}.sh
        env:
          DRY_RUN: ${{ inputs.dry_run }}

The environment input type shows a drop-down of the repository's environments, and referencing it in the job applies that environment's reviewers and secrets. Anyone with write access can trigger a workflow_dispatch run, so put production behind required reviewers.

Hardening checklist for every workflow

ControlHowWhy
Least-privilege tokenTop-level permissions: contents: read, widen per jobLimits damage if a step is compromised
Pin third-party actionsFull commit SHA plus a version comment; Dependabot for updatesTags can be moved, as the 2026 trivy-action incident showed
No long-lived cloud keysOIDC with subject conditions per environmentNothing to leak or rotate
Safe triggersUse pull_request for running untrusted code; keep pull_request_target free of PR checkoutsPrevents forks from reaching secrets
No script injectionPass ${{ github.event.* }} values through env instead of inline in runTitles and branch names are attacker-controlled
Timeoutstimeout-minutes on jobsStops hung jobs from burning minutes
Protected deploysEnvironments with required reviewers and branch rulesA person approves production changes

To compare GitHub Actions with other engines, read our CI/CD tools comparison and Jenkins versus GitHub Actions. For quality gates you can add to workflow 1, see CI/CD quality gates, and for a DAST stage, our OWASP ZAP pipeline guide.

Learning GitHub Actions with labs

Writing these workflows against a real repository is the fastest way to learn them. Our DevOps training in Pune includes CI/CD labs with GitHub Actions and Jenkins, container builds and Kubernetes deployments, in the Kharadi classroom or live online across India. If you work mainly in Microsoft tooling, AZ-400 training covers GitHub and Azure Pipelines together.

Frequently asked questions

What is the difference between a GitHub Actions workflow and an action?

A workflow is a YAML file in .github/workflows that defines triggers, jobs and steps. An action is a reusable step, such as actions/checkout, that a workflow calls with uses. A reusable workflow is a whole workflow called by another one.

Which GitHub Actions workflow should every repository have?

At minimum a CI workflow that runs tests on pull requests, with explicit read-only permissions, plus dependency review or Dependabot. Add CodeQL for code you ship, and a deploy workflow with environments once you deliver from GitHub.

Should I pin actions to a version tag or a commit SHA?

GitHub's security guidance says a full-length commit SHA is the only immutable reference. Tags are fine for actions you fully trust, such as GitHub's own, but pin third-party actions to SHAs and let Dependabot propose updates.

How do I stop duplicate workflow runs on the same pull request?

Add a concurrency block with a group based on the workflow and github.head_ref, and set cancel-in-progress: true. For deploys, set it to false so a running deployment is never cut off.

Is pull_request_target safe to use?

It is safe for jobs that only read pull request metadata, such as labeling or Dependabot auto-merge. It is unsafe if the job checks out and runs code from the pull request, because that code would run with write permissions and access to secrets.

How do I deploy to AWS from GitHub Actions without access keys?

Create an IAM OIDC identity provider for token.actions.githubusercontent.com, a role whose trust policy checks the audience and subject, grant the workflow id-token: write and call aws-actions/configure-aws-credentials with role-to-assume.

When should I use a reusable workflow instead of a composite action?

Use a reusable workflow to share whole jobs, including runners, environments and multiple jobs. Use a composite action to share a few steps inside a job. Reusable workflows also show each job separately in the run log.

Why did my scheduled workflow stop running?

In public repositories, GitHub disables scheduled workflows after 60 days with no repository activity. Re-enable the workflow from the Actions tab. Scheduled runs also use the workflow file on the default branch only.

References

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.