Git GitHub Actions Introduction
In this page:
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?
# .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
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
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
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
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- workflow file को
.github/workflows/के बाहर रखना, ताकि GitHub Actions इसे कभी न चलाए। - YAML में tabs या गलत indentation इस्तेमाल करना, जो workflow को invalid बना देता है।
on:के तहत trigger भूल जाना, याbranches: [main]इस्तेमाल करना जब repository की default branch का नाम अलग हो।
Chapter Quiz — Complete all 5 topics to unlock
0/5 topics done
Complete these topics first: