Github Actions by Example
  • GitHub Actions by Example
  • chap1-intro
    • Section 1 - Introducing GitHub Actions
    • Section 2 - Terminology and Core Concepts
    • Section 3 - Building a workflow
  • chap2-deployment-workflow
    • Section 1 - Workflow
    • Section 2 - The services
    • Section 3 - The test workflow job
    • Section 4 - The build and push workflow job
    • Section 5 - The deploy workflow job
  • Chap3-reusable-workflows
    • Section 1 - What is a reusable workflow
    • Section 2 - The test reusable workflow
    • Section 3 - The build and push reusable workflow
    • Section 4 - The deploy reusable workflow
    • Section 5 - Releasing the reusable workflow
  • Chap4-custom-actions
    • Section 1 - What is a custom action
    • Section 2 - Composite Custom Actions
    • Section 3 - Javascript Custom Actions
Powered by GitBook
On this page
  • Automation platform
  • Framework
  • Summary
  1. chap1-intro

Section 1 - Introducing GitHub Actions

GitHub Actions is an automation solution framework built within GitHub's ecosystem.

Automation platform

Automation is the process of using a system to perform tasks that would typically require human intervention. Within the sphere of GitHub Actions, this automation is intricately linked to a given GitHub repository.

To make this concept more relatable, let's take the well-known "Hello World" example. GitHub Actions allows you to configure the system such that every time you push a change or create a pull request in the repository, "Hello World" will run automatically.

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
          
    
jobs:
  hello-world:
    runs-on: ubuntu-latest
    steps:
      - name: Hello world
        run: echo "Hello world"

Framework

In computing, a framework is a set of tools that are used to develop, manage, or run a specific type of software solution. For GitHub Actions, the framework is the YAML syntax employed to define automation workflows. The framework also comprises a supportive community offering a wide range of ready-to-use actions that can be incorporated into your workflows.

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
      
permissions:
  pull-requests: write
      
jobs:
  hello-world:
    runs-on: ubuntu-latest
    steps:
      - name: Hello world
        id: hello-world
        run: |
          hello_world="Hello world"
          echo "value=${hello_world}" >> $GITHUB_OUTPUT
          echo $hello_world

      - name: Comment on PR
        if: ${{ github.event_name == 'pull_request' }}
        uses: peter-evans/create-or-update-comment@v3
        with:
          issue-number: ${{ github.event.pull_request.number }}
          body: |
            ${{ steps.hello-world.outputs.value }}

By using a community action, you can add the comment in a single step, bypassing the need to delve into API implementation details. This illustrates how the surrounding GitHub Actions framework is as crucial as the automation it enables.

Summary

In these examples, we touched on several concepts that might be new to you. Don't worry! We'll dive deeper into these subjects in subsequent sections. For now, just remember that GitHub Actions is an automation platform deeply ingrained in the GitHub environment, facilitating GitHub repository-specific tasks. The framework also provides a robust foundation that can significantly streamline your automation workflows.

Previouschap1-introNextSection 2 - Terminology and Core Concepts

Last updated 5 months ago

The complete source code for this example can be found in this repo, under:

For instance, imagine extending the previous "Hello World" example to include commenting "Hello World" on every pull request. While you could use the to create a bash step that adds this comment, it's easier and more efficient to use the community action. We can then extend the hello-world example by adding a step: Comment on PR that uses this action to comment "hello world" on the pull request.

.github/workflows/s1_1-hello-world.yaml
GitHub API
create or update comment