github3 min read

Curated summary

GitHub for Beginners: Getting started with GitHub Actions

Read original(opens in new tab)

GitHub Actions is GitHub’s built-in platform for automating CI/CD and repetitive repository tasks. Workflows are YAML files triggered by events such as pushes, pull requests, schedules, or newly opened issues, then executed as jobs on hosted or self-hosted runners. The post guides beginners through creating a workflow that automatically labels new issues.

What GitHub Actions Provides

  • GitHub Actions supports:
    • Continuous integration and delivery
    • Automated tests and vulnerability scans
    • Release creation
    • Team reminders and other repetitive tasks
  • Workflows are stored in the repository and run automatically when configured events occur.
  • Jobs execute in virtual machines called runners, provided by GitHub or managed by the user.

How Workflows Operate

  • Events trigger workflows, such as:
    • Pushing code
    • Opening or merging pull requests
    • Creating issues
    • Scheduled times
  • Runners are virtual machines that execute workflow jobs. GitHub offers Ubuntu, Windows, and macOS hosted runners, while teams can also use self-hosted runners.
  • Jobs contain groups of steps executed on the same runner.
  • Steps can either run shell commands or invoke reusable Marketplace actions.

Workflow Structure

Workflow files use YAML and live in .github/workflows.

The three main sections are:

  • name: Describes the workflow.
  • on: Specifies the event or events that trigger it.
  • jobs: Defines the work performed after triggering.

The post recommends descriptive filenames such as build-and-test.yml, security-scanner.yml, or label-new-issue.yml.

Creating an Issue-Labeling Workflow

The example workflow automatically adds a triage label whenever a new issue is opened.

  • It is named Label New Issues.

  • Its trigger is configured as:

    on:
      issues:
        types: [opened]
    
  • The label-issues job runs on ubuntu-latest.

  • Permissions are explicitly granted:

    • issues: write allows the workflow to add labels.
    • contents: read allows it to access repository content.

Using Actions and Shell Commands

The workflow contains two steps:

  • actions/checkout@v6 uses a prebuilt Marketplace action to check out the repository code.

  • A shell command uses the GitHub CLI to add the label:

    gh issue edit "$ISSUE_NUMBER" --add-label "$LABEL"
    

Environment variables provide the command with:

  • GITHUB_TOKEN for authentication
  • The issue number from github.event.issue.number
  • The label name, triage

The uses keyword invokes reusable actions, while run executes a shell command directly.

Start with a small workflow in .github/workflows, define its trigger and required permissions carefully, and build from reusable actions plus simple commands. The post also recommends practicing with GitHub’s “Hello GitHub Actions” exercise to become familiar with workflow creation.

Continue with another curated summary.