Create Your First GitHub Actions CI Workflow
Start with one test
A reliable CI pipeline begins with a deterministic test that can run locally. The fixture contains notes.txt and scripts/check-note.sh. The expected bytes are Water every 3 days plus a newline. The check reports a nonzero status if the file is missing, different, or lacks the final newline; it never repairs the file silently.
#!/bin/bashset -euo pipefailcmp -s notes.txt <(printf 'Water every 3 days\n') || { printf '%s\n' 'Invalid watering note' >&2 exit 1}printf '%s\n' 'Note verified'Run the check before CI
In the practice project root, run the following commands. A good file returns 0 and prints Note verified. A bad file returns 1 and prints Invalid watering note on stderr. The automated fixture creates both versions and a missing-file case; do not overwrite real project files to reproduce the example. Bash is explicitly selected because the test uses process substitution.
Define the workflow
The example belongs in .github/workflows/ci.yml only after review in an authorized repository. push is filtered to main; pull_request is filtered by its base branch. The checkout action retrieves the revision selected by the event; for typical pull request runs this is the test merge revision, not necessarily the contributor head. The explicit read permission and disabled credential persistence reduce unnecessary access. The full SHA is the published v6.0.2 checkout commit, selected as a fixed teaching example, not a claim that it is the latest or universally compatible. Review the action and runner requirements before use.
name: Garden CIon: push: branches: [main] pull_request: branches: [main]permissions: contents: readjobs: verify: runs-on: ubuntu-latest steps: - name: Checkout source uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false - name: Check note shell: bash run: bash scripts/check-note.shFollow the failure
A runner needs the source before running a repository script. Checkout failure normally prevents later ordinary steps. If the checkout succeeds but the check returns 1, the step fails; by default the job fails and subsequent ordinary steps are skipped. A passing job is evidence only for those checks on that revision. Review and required status checks must be configured separately. Do not add continue-on-error just to make the result green.
Practice safely
Run python3 lab-fixtures/chapter30.py from the extracted archive. It parses the YAML and checks that the test command matches the intended fixture script, then exercises valid and invalid inputs in temporary directories. It never downloads the action, installs a runner or pushes a workflow. An authorized hosted test and workflow-specific lint remain required before deployment.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Create Your First GitHub Actions CI Workflow — knowledge check
Reason about GitHub Actions workflow behavior and safety.
What should a test do when the watering unit is absent?
For pull_request branches: [main], which branch is filtered?
Why pin checkout to a full commit SHA?
What is needed before claiming actual hosted execution?
What happens normally when the check exits 1?