1. Home
  2. /
  3. Github-actions
  4. /
  5. Simple GitHub Actions Workflow

Simple GitHub Actions Workflow - Github-actions Typing CST Test

Loading…

Simple GitHub Actions Workflow — Github-actions Code

A simple GitHub Actions workflow to build and test a Node.js application.

# .github/workflows/demo.yml
name: Node.js CI

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

jobs:
	build:
		runs-on: ubuntu-latest
		steps:
		- uses: actions/checkout@v3
		- name: Set up Node.js
		  uses: actions/setup-node@v3
		  with:
		node-version: '16'
		- name: Install dependencies
		  run: npm install
		- name: Run tests
		  run: npm test

Github-actions Language Guide

GitHub Actions is a CI/CD and automation platform integrated with GitHub that allows developers to automate workflows for building, testing, and deploying code directly from their repositories using YAML configuration files.

Primary Use Cases

  • ▸Continuous integration (build, test, lint)
  • ▸Continuous deployment to cloud or on-prem servers
  • ▸Automating code review tasks
  • ▸Scheduled maintenance tasks or cron jobs
  • ▸Workflow orchestration across multiple repositories

Notable Features

  • ▸YAML-based workflow definitions
  • ▸Triggers on multiple GitHub events
  • ▸Matrix builds for parallel testing
  • ▸Marketplace with reusable actions
  • ▸Integration with self-hosted or GitHub-hosted runners

Origin & Creator

Developed by GitHub to provide integrated CI/CD and automation within GitHub repositories, eliminating the need for external CI/CD services.

Industrial Note

GitHub Actions is widely used in open-source projects, DevOps automation, continuous deployment to cloud providers, and integration with microservices architectures.

Quick Explain

  • ▸GitHub Actions enables automation of development workflows within GitHub repositories.
  • ▸Workflows are defined in YAML files under `.github/workflows/`.
  • ▸Supports triggers like push, pull request, schedule, and manual dispatch.
  • ▸Integrates with GitHub ecosystem, third-party services, and self-hosted runners.
  • ▸Ideal for CI/CD pipelines, automated testing, code linting, and deployment tasks.

Core Features

  • ▸Workflow files in `.github/workflows/`
  • ▸Job and step orchestration
  • ▸Event-based triggers
  • ▸Secrets and environment management
  • ▸Artifact and cache management

Learning Path

  • ▸Learn GitHub repository basics
  • ▸Understand workflow YAML structure
  • ▸Create simple workflows for build/test
  • ▸Use actions from Marketplace
  • ▸Integrate workflows into CI/CD pipelines

Practical Examples

  • ▸Build and test a Node.js project on every push
  • ▸Deploy a static website to GitHub Pages automatically
  • ▸Run Python tests across multiple Python versions
  • ▸Trigger workflows between multiple repositories for CI/CD
  • ▸Automate Docker image build and push to Docker Hub

Comparisons

  • ▸GitHub Actions vs Jenkins - GitHub-native vs standalone CI server
  • ▸GitHub Actions vs Travis CI - tighter GitHub integration vs external service
  • ▸GitHub Actions vs CircleCI - integrated vs external SaaS
  • ▸GitHub Actions vs Azure Pipelines - GitHub-focused vs multi-platform
  • ▸GitHub Actions vs Docker Compose - Actions orchestrates CI/CD, Compose orchestrates containers

Strengths

  • ▸Native GitHub integration with repository events
  • ▸No external CI/CD infrastructure needed for GitHub-hosted runners
  • ▸Supports complex workflows with dependencies and conditions
  • ▸Matrix builds allow testing across multiple environments
  • ▸Extensive community and marketplace for reusable actions

Limitations

  • ▸Limited free minutes for private repositories on GitHub-hosted runners
  • ▸Complex workflows can become hard to manage
  • ▸Debugging failed workflows requires familiarity with logs
  • ▸Self-hosted runners require maintenance and security considerations
  • ▸Some advanced features may require external scripts or actions

When NOT to Use

  • ▸If your project is hosted outside GitHub and you prefer self-managed CI/CD
  • ▸When ultra-complex enterprise pipelines require Jenkins-style plugins
  • ▸For extremely high-volume workflows exceeding GitHub-hosted runner limits
  • ▸If your team requires advanced monitoring beyond GitHub UI
  • ▸When dependency on marketplace actions is a concern for security or stability

Cheat Sheet

  • ▸workflow_dispatch - manual trigger
  • ▸on: push/pull_request - event triggers
  • ▸jobs - define workflow jobs
  • ▸steps - define tasks inside jobs
  • ▸uses - reference an action from marketplace or repo

FAQ

  • ▸Can GitHub Actions deploy to cloud providers? -> Yes, via actions or custom scripts
  • ▸Is it free? -> Free minutes are included; private repos have limits
  • ▸Can workflows be scheduled? -> Yes, using cron syntax
  • ▸Does it support self-hosted runners? -> Yes, for custom environments
  • ▸Can actions be reused? -> Yes, marketplace or private reusable actions

30-Day Skill Plan

  • ▸Week 1: Simple workflow for build/test
  • ▸Week 2: Add environment variables and secrets
  • ▸Week 3: Matrix builds for multiple OS/languages
  • ▸Week 4: Deploy to staging/production
  • ▸Week 5: Multi-repo and enterprise-grade workflows

Final Summary

  • ▸GitHub Actions is an integrated automation and CI/CD platform within GitHub.
  • ▸Workflows are defined declaratively in YAML files with jobs and steps.
  • ▸Supports triggers on repository events, schedules, and manual dispatch.
  • ▸Integrates with marketplace actions, cloud providers, and self-hosted runners.
  • ▸Ideal for testing, building, and deploying code directly from GitHub repositories.

Project Structure

  • ▸.github/workflows/ - contains workflow YAML files
  • ▸Optional scripts/ folder for reusable shell scripts
  • ▸Secrets configured in repository settings
  • ▸Artifacts or cache directories defined in workflow
  • ▸README.md can reference workflow usage

Monetization

  • ▸Streamline CI/CD pipelines for commercial projects
  • ▸Automate deployments for SaaS platforms
  • ▸Reduce operational overhead for small teams
  • ▸Integration with paid cloud services
  • ▸Support enterprise DevOps consulting

Productivity Tips

  • ▸Use reusable actions to reduce workflow duplication
  • ▸Cache dependencies to speed up builds
  • ▸Use matrix builds for testing multiple environments
  • ▸Leverage `workflow_dispatch` for manual testing
  • ▸Monitor logs regularly to catch errors early

Basic Concepts

  • ▸Workflow - a YAML file defining automation tasks
  • ▸Job - a group of steps executed on a runner
  • ▸Step - an individual task within a job
  • ▸Action - reusable task or script
  • ▸Runner - environment executing jobs (hosted or self-hosted)

Official Docs

  • ▸https://docs.github.com/en/actions
  • ▸GitHub Actions Marketplace
  • ▸GitHub CLI documentation

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher