Use Cases (अपडेट: 3/6/2026)

Claude Code से GitHub Actions उन्नत करें: permissions, OIDC, cache और matrix CI

Claude Code से सुरक्षित GitHub Actions बनाएं: permissions, OIDC, cache, matrix और YAML examples।

Claude Code से GitHub Actions उन्नत करें: permissions, OIDC, cache और matrix CI

GitHub Actions में “push पर test चलाओ” बनाना आसान है। असली कठिनाई तब आती है जब team को कम से कम permissions, भरोसेमंद cache, कई environment में test, cloud deploy बिना long-lived key, और Claude Code review बिना secret leak के चाहिए।

इस guide में Claude Code को सिर्फ YAML generator नहीं, बल्कि workflow design partner की तरह इस्तेमाल किया गया है। नीचे दिए गए examples पूरे GitHub Actions workflows हैं। इन्हें copy करके repository के हिसाब से values बदल सकते हैं। लेकिन सबसे जरूरी बात यह है कि हर job बता सके कि उसे कौन सी permission क्यों चाहिए, कौन सा secret दिखेगा, और fork pull request पर क्या होगा।

इस लेख के लिए मैंने GitHub की official docs में workflow syntax, GITHUB_TOKEN permissions, AWS OIDC, dependency caching, concurrency, और Claude Code GitHub Actions को verify किया।

संरचना

Advanced GitHub Actions का मतलब ज्यादा automation नहीं है। अच्छा workflow failure को समझने लायक बनाता है, permissions narrow रखता है, पुराने runs cancel करता है, और production change में human approval बचाकर रखता है।

flowchart LR
  PR["Pull request"] --> Gate["matrix test and lint"]
  Gate --> Cache["lockfile cache"]
  Gate --> Claude["Claude Code review"]
  Gate --> Deploy["OIDC deploy"]
  Deploy --> Env["GitHub environment approval"]
  Env --> AWS["AWS role"]

कुछ terms पहले साफ कर लेते हैं। Matrix यानी combinations की table: जैसे Node.js 22 और 24 को Ubuntu और Windows पर चलाना। OIDC यानी OpenID Connect, जिससे GitHub Actions की short-lived identity को AWS जैसी cloud credential में बदला जा सकता है। इससे AWS access key लंबे समय के लिए GitHub Secrets में नहीं रखनी पड़ती। Concurrency एक जैसे workflows को साथ-साथ चलने से रोकती है। Permissions बताती हैं कि GITHUB_TOKEN क्या कर सकता है।

व्यावहारिक उपयोग के मामले

पहला use case pull request quality gate है। Lint, type-check और tests merge से पहले कई runtime पर चलते हैं। इससे Windows path issue, Node.js version difference और lockfile drift जल्दी दिख जाता है।

दूसरा use case staging deploy है। main green होने के बाद GitHub Actions OIDC से AWS IAM role assume करता है और static access key के बिना deploy करता है। Production के लिए GitHub Environment approval जोड़ना चाहिए।

तीसरा use case monorepo shared CI है। कई packages अगर वही Node setup, install और test दोहराते हैं, तो reusable workflow version drift रोकता है।

चौथा use case Claude Code PR review है। शुरुआत में Claude Code को diff पढ़ने और review comment लिखने तक सीमित रखें। Auto-fix या push permission बाद में दें, जब branch protection, required review और rollback process तय हो।

Claude Code को क्या prompt दें

पहले constraints लिखवाएं, फिर YAML लिखवाएं।

Design GitHub Actions for this repository.
The goals are pull request quality gates, staging deployment, and Claude Code review.

Constraints:
- Use least-privilege GITHUB_TOKEN permissions.
- Use OIDC for AWS. Do not store long-lived AWS access keys in Secrets.
- Include package-lock.json in dependency cache keys.
- Assume secrets are not available on forked pull requests.
- If pull_request_target is suggested, explain why PR head code is not checked out.
- Produce GitHub Actions YAML that is valid as written.

End with concrete failure cases and verification steps.

इस prompt से Claude Code को security decision explain करना पड़ता है। सिर्फ template भरना काफी नहीं रहता।

PR गुणवत्ता gate

यह workflow actions/checkout@v6 और actions/setup-node@v6 use करता है, जो जून 2026 में current major versions हैं। GitHub-hosted runners पर ये सामान्य रूप से चल जाते हैं। Self-hosted runner use करने वाली team पहले runner version check करे।

name: pr-quality-gate

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

permissions:
  contents: read

concurrency:
  group: pr-quality-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  test:
    name: node-${{ matrix.node }}-${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 15
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest]
        node: [22, 24]

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Setup Node
        uses: actions/setup-node@v6
        with:
          node-version: ${{ matrix.node }}
          cache: npm
          cache-dependency-path: package-lock.json

      - name: Install dependencies
        run: npm ci

      - name: Lint
        run: npm run lint

      - name: Type check
        run: npm run typecheck

      - name: Test
        run: npm test

यह job repository में write नहीं करता, इसलिए contents: read काफी है। concurrency उसी branch के पुराने runs cancel करता है। Cache package-lock.json से जुड़ा है। पूरे node_modules को cache करना अक्सर fragile होता है, क्योंकि native modules और OS differences build तोड़ सकते हैं।

OIDC से AWS deploy

Safe pattern यह है कि AWS में GitHub OIDC provider register करें, narrow IAM role बनाएं, और trust policy को repository, branch या environment से restrict करें। Workflow में id-token: write जरूरी है, क्योंकि इसी से OIDC token request हो सकता है।

name: deploy-staging

on:
  workflow_dispatch:
  push:
    branches: [main]

permissions:
  contents: read
  id-token: write

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

jobs:
  deploy:
    runs-on: ubuntu-latest
    timeout-minutes: 20
    environment: staging

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v6
        with:
          role-to-assume: arn:aws:iam::123456789012:role/claude-code-github-actions-staging
          aws-region: ap-northeast-1

      - name: Verify caller identity
        run: aws sts get-caller-identity

      - name: Deploy
        run: |
          npm ci
          npm run build
          echo "Deploy command goes here"

Role ARN, region और deploy command बदलें। Production के लिए अलग environment और required reviewers रखें।

पुन: उपयोग योग्य workflow

एक जैसी Node checks कई workflows में दोहर रही हों तो reusable workflow बेहतर है। यह common function जैसा है, लेकिन secrets अपने-आप सारे pass नहीं होते।

# .github/workflows/reusable-node-check.yml
name: reusable-node-check

on:
  workflow_call:
    inputs:
      node-version:
        required: false
        type: string
        default: "24"

permissions:
  contents: read

jobs:
  check:
    runs-on: ubuntu-latest
    timeout-minutes: 15

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Setup Node
        uses: actions/setup-node@v6
        with:
          node-version: ${{ inputs.node-version }}
          cache: npm
          cache-dependency-path: package-lock.json

      - name: Install
        run: npm ci

      - name: Check
        run: |
          npm run lint
          npm run typecheck
          npm test

Caller workflow:

# .github/workflows/ci.yml
name: ci

on:
  pull_request:
    branches: [main]

permissions:
  contents: read

jobs:
  node-check:
    uses: ./.github/workflows/reusable-node-check.yml
    with:
      node-version: "24"

अगर हर package के install या test commands अलग हैं, तो सब कुछ एक बड़े reusable workflow में न भरें। Claude Code से common setup और package-specific steps अलग करवाएं।

Claude Code PR review

Claude Code Action v1 में anthropics/claude-code-action@v1, prompt और claude_args use होते हैं। पुराने @beta या direct_prompt examples copy न करें।

name: claude-pr-review

on:
  pull_request:
    types: [opened, synchronize, reopened]

permissions:
  contents: read
  pull-requests: write
  issues: write

jobs:
  review:
    if: github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest
    timeout-minutes: 20

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Claude Code review
        uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          prompt: |
            Review this pull request as a senior engineer.
            Focus on security, broken tests, unnecessary permissions, and missing verification.
            Do not modify files. Leave concise review comments only.
          claude_args: |
            --max-turns 5

यह workflow fork PR skip करता है, क्योंकि repository secrets आम तौर पर वहाँ उपलब्ध नहीं होते। Fork support चाहिए तो secrets के बिना low-trust path बनाएं।

आम विफलताएं

सबसे खतरनाक गलती है pull_request_target में PR head checkout करना। यह event base repository की permissions के करीब हो सकता है। External fork का code high permission में चलाना secret leak करा सकता है।

दूसरी गलती debug के लिए secrets print करना है। GitHub कई exact values mask करता है, लेकिन derived string, JSON, base64 और third-party debug logs हमेशा सुरक्षित नहीं होते। Claude Code को secret names और purpose दें, values नहीं।

तीसरी गलती broad cache key है। key: node-cache lockfile बदलने के बाद भी पुरानी dependency restore कर सकता है। cache-dependency-path या hashFiles('**/package-lock.json') use करें।

चौथी गलती matrix explosion है। दो OS और दो Node versions ठीक हैं; तीन OS, चार runtimes और आठ packages से 96 jobs बन जाएंगे। PR में छोटी matrix चलाएं और nightly में wide coverage रखें।

पांचवीं गलती action major updates ignore करना है। 2026 में कई official actions नए Node runtime पर हैं। Self-hosted runner वाले setup में workflow update से पहले runner update check करें।

कमाई की दिशा

Safe CI revenue pages को भी बचाता है: landing page, paid templates, checkout flow, lead form और course content छोटे PR में safely ship हो सकते हैं। Solo शुरुआत के लिए free Claude Code cheatsheet देखें। Team को real repository पर permissions, OIDC, Claude Code review, branch protection और monorepo CI design करना हो तो Claude Code training और consultation मदद कर सकता है।

Related guides: CI/CD pipeline setup, Git workflow, testing strategy, और security best practices

व्यावहारिक परिणाम

इस लेख में MDX के fenced YAML examples निकालकर YAML parser से syntax check किया गया। Examples on, permissions, concurrency, matrix, reusable workflow, OIDC deployment और Claude Code Action v1 को valid YAML structure में cover करते हैं। असली repository में चलाने से पहले AWS role ARN, npm scripts, environment name और ANTHROPIC_API_KEY secret बदलें।

#Claude Code #GitHub Actions #CI/CD #automation #DevOps
मुफ़्त

मुफ़्त PDF: Claude Code cheatsheet

Email डालें और commands, review habits तथा safe workflow वाली एक-page PDF पाएँ.

हम आपका data सुरक्षित रखते हैं और spam नहीं भेजते.

Masa

लेखक के बारे में

Masa

Claude Code workflow और team adoption पर काम करने वाला engineer.