CI/CD & GitHub Actions (50 Qs)•Part 1: CI/CD Fundamentals & GitHub Actions Core (Junior / Entry-Level)
Explain the fundamental components of a GitHub Actions workflow.
junior LevelMost AskedCode ExampleComponentsState ManagementCI/CD & DevOps
In Simple Words:
GitHub Actions automation is defined in YAML files located inside .github/workflows/.
Core Building Blocks:
- Workflows: Configured automated processes made of one or more jobs (e.g.,
ci.yml). - Events / Triggers (
on): Specific activities that trigger the workflow (e.g.,push,pull_request,schedule). - Jobs: A set of steps executed on the same runner. Jobs run in parallel by default, unless sequenced with
needs: [job_id]. - Runners: Virtual machines or containers executing the jobs (e.g.,
runs-on: ubuntu-latest). - Steps: Individual tasks within a job. Can run shell commands (
run:) or actions (uses:). - Actions: Standalone reusable commands packaged as open-source or custom scripts (e.g.,
actions/checkout@v4).
yaml
# .github/workflows/ci.yml
name: Continuous Integration
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
name: Run Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install & Test
run: |
npm ci
npm test