| ← Workshop Setup | Next: Securing the Development Pipeline → |
|---|
GitHub Actions is an automation platform built into GitHub that lets you build, test, and deploy your code directly from your repository. While it's most commonly used for CI/CD, it can automate just about any task in your development workflow — from labeling issues to resizing images.
Before diving in, here are the key terms you'll encounter:
- Workflow: An automated process defined in a YAML file, stored in
.github/workflows/. - Event: A trigger that starts a workflow, such as a
push,pull_request, orworkflow_dispatch. - Job: A set of steps that run on the same runner. Jobs run in parallel by default.
- Step: An individual task within a job — either a shell command (
run) or a reusable action (uses). - Runner: The virtual machine that executes your jobs (e.g.,
ubuntu-latest). - Action: A reusable unit of code that performs a specific task, published on the Actions Marketplace.
The shelter has built its application — a Flask API and Astro frontend — and the team is ready to start automating their development workflow. Before diving into CI/CD, let's start with the basics: creating a simple workflow, triggering it manually, and understanding the logs.
A workflow file is written in YAML and lives in the .github/workflows/ directory. Here are the core sections you'll work with:
name: A human-readable name for the workflow, displayed in the Actions tab.on: Defines the events that trigger the workflow (e.g.,push,pull_request,workflow_dispatch).jobs: Contains one or more jobs, each with a unique identifier.runs-on: Specifies the runner environment (e.g.,ubuntu-latest).steps: An ordered list of tasks the job performs.uses: References a reusable action (e.g.,actions/checkout@v4).run: Executes a shell command.
Let's start with the classic "Hello World" — a workflow you can trigger manually from the GitHub UI.
-
In your codespace, create the folder
.github/workflows/if it doesn't already exist. -
Create a new file named
.github/workflows/hello.yml. -
Add the following content:
name: Hello World on: workflow_dispatch: jobs: greet: runs-on: ubuntu-latest steps: - name: Say hello run: echo "Hello, GitHub Actions!" - name: Show environment info run: | echo "Runner OS: $RUNNER_OS" echo "Repository: $GITHUB_REPOSITORY" echo "Triggered by: $GITHUB_ACTOR"
-
Save the file.
Note
The workflow_dispatch event lets you trigger the workflow manually from the Actions tab. This is useful for testing workflows without needing to push code changes every time.
Now let's push the workflow and trigger it by hand.
-
Open the terminal in your codespace by pressing Ctl+`.
-
Stage and commit your changes:
git add .github/workflows/hello.yml git commit -m "Add hello world workflow" -
Push to your repository:
git push
-
Navigate to your repository on GitHub and select the Actions tab.
-
In the left sidebar, select the Hello World workflow.
-
Select the Run workflow button, keep the default branch, and select Run workflow again to confirm.
Once the run completes, let's explore what happened.
- Select the workflow run that just completed.
- Select the greet job to expand it.
- Explore the logs for each step:
- Say hello — you'll see the
echooutput. - Show environment info — notice the environment variables that GitHub Actions provides automatically (
RUNNER_OS,GITHUB_REPOSITORY,GITHUB_ACTOR).
- Say hello — you'll see the
- Also look at the Set up job and Complete job steps that Actions adds automatically — these show the runner setup and cleanup.
Tip
You can search within the logs using the search box at the top of the log viewer, and expand or collapse individual steps. This becomes very useful as workflows grow more complex.
Congratulations! You've created and run your first GitHub Actions workflow. You've learned how to define a workflow in YAML, trigger it manually with workflow_dispatch, and navigate the logs in the Actions UI.
Next, we'll put this knowledge to work by securing the development pipeline with code scanning, Dependabot, and secret scanning.
- GitHub Actions documentation
- Workflow syntax for GitHub Actions
- Events that trigger workflows
- Understanding GitHub Actions
| ← Workshop Setup | Next: Securing the Development Pipeline → |
|---|