← Back to Git Course | Chapter 9: CI/CD & DevOps | Lesson 1 of 5

Git GitHub Actions Introduction

GitHub Actions GitHub के अंदर रहने वाले एक helpful robot जैसा है जो आपके project में कुछ भी होने पर आपके लिए chores करता है, जैसे आपका code test करना।
Syntax
bash
name: workflow_name
on:
  event_name:
    branches: [branch_name]
jobs:
  job_name:
    runs-on: runner_name
    steps:
      - uses: action_name

GitHub Actions क्या है?

GitHub Actions सीधे GitHub में built एक automation platform है। यह आपको testing, building, और आपके code deploy करने जैसे software development workflows automate करने देता है। हर workflow एक event से trigger होता है, जैसे आपकी repository में नया code push करना।

उदाहरण: What is GitHub Actions?

bash
# .github/workflows/ci.yml
name: CI
on: push

एक Workflow File Define करना

Workflows .github/workflows/ के अंदर YAML files की तरह लिखे जाते हैं, और हर एक एक name plus एक on: key declare करता है जो specify करती है कि कौन सा event इसे trigger करता है। GitHub उस directory में किसी भी correctly formatted file को automatically पकड़ लेता है — कोई अलग registration step नहीं चाहिए।

उदाहरण: Defining a Workflow File

bash
name: CI
on:
  push:
    branches: [main]

Events को समझना

Events वे हैं जो एक workflow run शुरू करते हैं — push, pull_request, schedule (timed runs के लिए cron syntax), और workflow_dispatch (एक manual trigger button) सबसे common हैं। एक workflow एक साथ कई event types सुन सकता है और branch या file path से भी filter कर सकता है।

उदाहरण: Understanding Events

bash
on:
  push:
  pull_request:
  schedule:
    - cron: "0 0 * * *"
  workflow_dispatch:

Jobs और Steps

एक workflow एक या ज़्यादा jobs से बनता है, और default रूप से GitHub उन सबको अलग virtual machines पर parallel में चलाता है — एक job को दूसरी का wait करवाने के लिए आप needs: इस्तेमाल करते हैं। एक job के अंदर, steps sequentially, top to bottom, same machine पर चलते हैं।

उदाहरण: Jobs and Steps

bash
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: npm test
  deploy:
    needs: test
    runs-on: ubuntu-latest

Pre-built Actions इस्तेमाल करना

आपको scratch से सभी commands लिखने की ज़रूरत नहीं। आप अपना code checkout करने या environments set up करने जैसे complex tasks handle करने के लिए uses keyword इस्तेमाल करके pre-built, community-maintained actions import कर सकते हैं।

उदाहरण: Using Pre-built Actions

bash
steps:
  - uses: actions/checkout@v4
  - uses: actions/setup-node@v4
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. workflow file को .github/workflows/ के बाहर रखना, ताकि GitHub Actions इसे कभी न चलाए।
  2. YAML में tabs या गलत indentation इस्तेमाल करना, जो workflow को invalid बना देता है।
  3. on: के तहत trigger भूल जाना, या branches: [main] इस्तेमाल करना जब repository की default branch का नाम अलग हो।
🔒

Chapter Quiz — Complete all 5 topics to unlock

0/5 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.