Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

GitHub Actions: Terminology

Here’s a table that summarizes key GitHub Actions terminology, providing a clear and concise explanation of each term:

TermDefinition
WorkflowA configurable automated process made up of one or more jobs. Defined in YAML files in .github/workflows/.
JobA set of steps executed sequentially. Multiple jobs can run in parallel or sequentially.
StepA single task that runs as part of a job. It can be a shell command or an action.
ActionA reusable command or script that can be shared and used in workflows. Defined in public repositories or locally.
RunnerA server that runs jobs. It can be GitHub-hosted (runs on GitHub servers) or self-hosted (runs on your own infrastructure).
EventTriggers that start a workflow, such as push, pull_request, schedule, or workflow_dispatch.
TriggerThe event or condition that initiates a workflow run.
Job MatrixA way to run a job in multiple configurations (e.g., different OS, environments, or parameters) in parallel.
EnvironmentA collection of settings and resources (like secrets) that control how a workflow interacts with environments such as production, development, or staging.
ArtifactFiles generated by jobs, such as build outputs or test results, that can be shared across jobs.
SecretEncrypted variables used in workflows to store sensitive data like API keys, tokens, or passwords.
ContextInformation available to workflows during runtime, such as GitHub metadata, environment variables, or the repository.
Service ContainerContainers that can run alongside a job, typically used for databases or other services needed for the job.
Workflow RunAn instance of a workflow being executed as a result of a trigger or manual dispatch.
Expression SyntaxSpecial syntax (${{ }}) used in workflows to evaluate conditions, access context variables, or make decisions.
CacheMechanism to store dependencies or build outputs that can be reused in future workflow runs to improve performance.
PermissionsThe level of access given to the GitHub Actions runner for a job, such as read or write permissions for repositories or secrets.
Status BadgeA badge that shows the current status of a workflow (e.g., success, failure) that can be embedded in a README.
TimeoutThe maximum duration a job or workflow is allowed to run before it is automatically stopped.
CheckoutAn action (actions/checkout) that fetches the repository’s code in a workflow so that subsequent steps can work with it.
Cache ActionAn action (actions/cache) used to cache dependencies or output between workflow runs.
Matrix StrategyA feature allowing you to run the same job multiple times with different inputs (e.g., various operating systems, programming languages).
Approval WorkflowA manual action that requires approval from a human (typically used in deployment workflows).
FilterMechanism used to conditionally run workflows or jobs based on file changes, branches, or other criteria (e.g., paths, branches, tags).

Example


name: CI Pipeline

# Define the triggers (events) for this workflow
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
  workflow_dispatch: # Allows manually triggering the workflow

# Define the jobs in the workflow
jobs:
  # A job for building the project using a matrix strategy
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [12.x, 14.x, 16.x] # Run the job for different versions of Node.js
        os: [ubuntu-latest, windows-latest] # Run on different operating systems
    steps:
      - name: Checkout code
        uses: actions/checkout@v3 # Action to checkout the code

      - name: Set up Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}

      - name: Cache node modules
        uses: actions/cache@v3 # Cache dependencies
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - name: Install Dependencies
        run: npm install

      - name: Run Unit Tests
        run: npm test

      - name: Upload Test Results as Artifacts
        if: always() # Upload artifacts even if the tests fail
        uses: actions/upload-artifact@v3
        with:
          name: test-results
          path: test-results.xml

  # A job for deploying the application, running only when building on main
  deploy:
    runs-on: ubuntu-latest
    needs: build # This job will only run if the build job succeeds
    environment: production # Specifies the environment (can be 'production', 'staging', etc.)
    if: github.ref == 'refs/heads/main' # Deploy only on pushes to main
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Node.js 16.x
        uses: actions/setup-node@v3
        with:
          node-version: 16.x

      - name: Install Dependencies
        run: npm install

      - name: Deploy to Production Server
        env:
          SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} # Using a secret for authentication
        run: |
          ssh -i $SSH_PRIVATE_KEY user@yourserver.com "cd /var/www/app && git pull && npm install && pm2 restart app"
        
      - name: Notify on Success
        if: success()
        run: echo "Deployment successful!"

      - name: Notify on Failure
        if: failure()
        run: echo "Deployment failed!"

Explanation of Key Terminology in the Workflow

TermExplanation
WorkflowThe entire .yml file defines a workflow. This example has two jobs: build and deploy.
JobA collection of steps, running in a virtual machine environment. The jobs are build and deploy.
StepIndividual tasks within a job. For example, checking out the code, installing dependencies, and running tests.
ActionReusable commands from the GitHub Marketplace. In this example, actions/checkout@v3, actions/setup-node@v3, etc.
MatrixAllows running the build job in parallel for different versions of Node.js and operating systems.
RunnerThe server that runs the jobs (ubuntu-latest or windows-latest).
Event/TriggerThe workflow is triggered by events like push, pull_request, and workflow_dispatch.
EnvironmentSpecifies the environment (in this case, production) for deployment.
ArtifactThe test results are uploaded as artifacts using actions/upload-artifact@v3.
CacheDependencies are cached to speed up future builds (actions/cache@v3 caches the ~/.npm directory).
SecretA secure environment variable (SSH_PRIVATE_KEY) is used to authenticate the deployment server.
ifConditional logic to control when certain steps or jobs are executed (e.g., if: success() or if: github.ref == 'refs/heads/main').
ContextThe expression syntax ${{ }} allows accessing GitHub contexts such as matrix, secrets, and github.ref.
needsSpecifies that the deploy job depends on the build job, meaning it will only run if build is successful.
ArtifactTest results are stored using artifacts, which can be used in later jobs or downloaded after the workflow finishes.

Main Features Demonstrated

  1. Triggers: The workflow triggers on push and pull_request to the main branch, and can also be manually triggered via workflow_dispatch.
  2. Matrix: The build job uses a matrix to run multiple combinations of Node.js versions (12.x, 14.x, 16.x) and operating systems (ubuntu-latest, windows-latest).
  3. Secrets: The deploy job uses a secret (SSH_PRIVATE_KEY) to securely authenticate the deployment process.
  4. Conditional Execution:
    • The deploy job only runs on the main branch.
    • The steps Notify on Success and Notify on Failure use if: success() and if: failure() to conditionally run based on the outcome of previous steps.
  5. Artifacts: Test results are uploaded as an artifact so that they can be accessed after the workflow completes.
  6. Caching: Caching is used for npm dependencies to improve performance on subsequent runs.

Conclusion:

This workflow showcases a wide variety of GitHub Actions terminologies, demonstrating how to set up a matrix build, conditionally run jobs, use secrets, cache dependencies, upload artifacts, and trigger workflows with various events.

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x