GitHub Actions: Your First Workflow

Learn how to automate development tasks with GitHub Actions, setting up your first workflow to automatically label new issues.

2 min read
Screenshot of a GitHub Actions workflow configuration file in a code editor.
Image credit: Github Blog

GitHub's integrated CI/CD platform, GitHub Actions, allows developers to automate workflows directly within their repositories. This feature, often referred to as "action workflows," streamlines processes like testing, code scanning, and deployments.

Workflows are initiated by specific repository events, such as code pushes or pull requests. These events trigger jobs that execute on virtual machines called runners, which can be hosted by GitHub or self-managed. Each job consists of steps, defined as either shell commands or pre-built actions sourced from the GitHub Marketplace.

Understanding Workflow Components

To effectively build automated processes, understanding core terminology is crucial. An event is the specific activity that kicks off a workflow, like opening an issue. Hosted runners are the virtual environments where these workflows run. Finally, jobs are collections of steps that execute sequentially on a single runner.

The power of GitHub Actions lies in its event-driven automation. Developers define triggers, and GitHub orchestrates the execution of predefined jobs and steps without manual intervention.

Building Your First Workflow

To grasp the practical application, consider automating the labeling of new issues. This involves creating a YAML file, typically named descriptively (e.g., label-new-issue.yml), within the .github/workflows directory of your repository.

The workflow definition starts with a Name field, followed by the on section, which specifies the triggering event. For issue automation, this would be on: issues: types: [opened].

The jobs section details the actual work. A job, named here label-issues, is assigned a runner (e.g., runs-on: ubuntu-latest) and requires specific permissions, such as writing to issues and reading repository contents.

Steps within a job define the actions to be performed. The uses keyword pulls in pre-built actions from the Marketplace, such as actions/checkout@v6 for code checkout. The run keyword executes shell commands or scripts. Environment variables, defined in the env section, are essential for providing necessary credentials, like the GITHUB_TOKEN, to scripts that interact with the repository.