To build a code pipeline with GitHub, you connect a repository to GitHub Actions through a YAML workflow file stored in .github/workflows/, define the events that trigger it (pushes, pull requests, tags), and list the jobs and steps that install dependencies, run tests, build artifacts, and deploy. The one condition that matters most: every credential a pipeline needs should live in GitHub Secrets or an environment, never in the repository. This guide walks through that sequence end to end, from your first workflow file to protected deployments, with checks you can run at each stage to confirm the pipeline is working as intended.

GitHub Actions is GitHub's built-in automation service, generally available since 2019, and it's what most teams mean by "a code pipeline with GitHub." The alternative is running a third-party CI system such as Jenkins, CircleCI, or GitLab CI against your GitHub repository, but that adds an external service and its own credentials. For a pipeline that lives next to the code, Actions is the natural starting point, and everything below assumes it.

What a Code Pipeline Actually Does

A code pipeline is a chain of automated stages that take a code change from commit to running software. The canonical stages are: checkout, dependency installation, linting, testing, building an artifact, and deploying. Some pipelines add security scanning, container image publishing, or documentation builds. The point isn't the specific stages but the gate structure—each stage either passes and hands off to the next, or fails and stops the line.

GitHub Actions implements that structure with four nested concepts:

Workflow: a YAML file in .github/workflows/ that defines the whole pipeline. Event: what triggers the workflow, such as a push to main, a pull request, a schedule, or a manual dispatch. Job: a set of steps that run on one runner; jobs run in parallel unless you declare dependencies with needs. Step: a single command or a reusable action, such as actions/checkout or npm test.

The mental model that prevents most early mistakes: each job gets a fresh virtual machine (the runner), so files written in one job don't exist in another unless you upload and download them as artifacts. A single job runs steps sequentially on the same machine, so build output persists across its steps.

Runners come in GitHub-hosted flavors (Ubuntu, Windows, macOS) and self-hosted flavors. GitHub-hosted runners are billed by compute time, with free monthly allowances on personal and organization plans; the exact minute quotas and per-minute rates depend on your plan and change over time, so check your account's billing settings for current figures. Private repositories consume the allowance faster than public ones, which get generous free minutes.

Prerequisites Before You Write the First Workflow

Before touching YAML, confirm four things, because each one causes a specific class of confusing failure later.

1: A GitHub repository with code and a working local build. If npm install && npm test or mvn verify fails on your laptop, it will fail on the runner too, and you'll be debugging two problems at once. Get the local commands green first. 2: A pinned runtime version. Record the language version your project needs (for example Node 20, Python 3.12, Java 21). The runner's default version may differ, and that mismatch is a classic first-run failure. 3: A lockfile committed to the repo. package-lock.json, poetry.lock, Gemfile.lock, go.sum, or equivalent. Pipelines should install from the lockfile so the runner builds the same dependency graph you tested locally. 4: Write access to Actions settings. Repository admins control whether workflows can run and which actions are permitted. If you're not the admin, find out who is before you start.

You'll also need to decide where the pipeline sends its output. A pipeline that only runs tests and then stops is a useful first milestone; deployment is a second, separate decision that brings in secrets and environment protection.

Step 1: Create the Workflow File and Run Your First Job

Action: In your repository, create the directory .github/workflows/ and add a file such as ci.yml. The most stripped-down workflow that proves the plumbing works looks like this in structure: a name, an on block listing triggers, and a jobs block with one job that checks out the code and prints a message.

In practice, the file starts with:

Commit and push to a branch, open the Actions tab in the GitHub UI, and find the run listed under the workflow name.

Expected result: A green checkmark next to the run, and a log expandable to the echo output.

Success check: The run shows your commit SHA, the job lists each step, and the echo line appears in the log. If the Actions tab is empty, the most common causes are that workflows are disabled for the organization, the file isn't in .github/workflows/ exactly (directory name is case-sensitive and must be plural), or the YAML has a syntax error, which GitHub reports as a failed run with a validation message rather than silently ignoring the file.

Failure mode worth knowing now: If on: gets parsed as the boolean value true because your editor reformatted it, the workflow triggers on nothing expected. Quote it as "on": if you see odd behavior. This is a YAML quirk, not a GitHub bug.

Step 2: Add the Real Stages—Install, Lint, Test, Build

Action: Expand the job with steps that mirror your local commands. A Node example in shape (not a literal file) runs install with a frozen lockfile, then lint, then test, then build, each as its own step:

The pattern generalizes: use a setup action for your language (setup-python, setup-java, setup-go, setup-dotnet, ruby/setup-ruby) to pin the version, then run your normal commands.

Expected result: Each step appears as a separately logged, separately timed block; a failure stops the job at that step and marks the rest skipped.

Success check: On a clean commit, all steps pass and total duration is recorded. Now deliberately break something—add a failing assertion to one test, push, and confirm the job goes red at the test step and later steps are skipped. That red run is proof the gate works.

Three decisions here shape how useful the pipeline becomes:

Separate steps vs. one step. Separate steps give you per-step logs and timing; a single npm run ci step is simpler but hides which phase failed. For a new pipeline, separate steps are worth the extra lines. Fail fast ordering. Put cheap checks (lint, type check) before expensive ones (full test suite) so a typo costs 30 seconds, not 10 minutes. Caching. Setup actions can cache package downloads keyed on your lockfile. This typically turns multi-minute installs into seconds on repeat runs. The cache invalidates automatically when the lockfile changes, which is what you want.

You may also see the phrase "build a code pipeline" used to mean assembling reusable action steps from the GitHub Marketplace rather than writing shell commands. Marketplace actions are convenient—actions/checkout and the setup actions are themselves marketplace actions—but pin them to a version tag or, for stricter supply-chain control, a commit SHA. A floating @main reference means someone else's push changes your pipeline.

Step 3: Split Into Jobs and Pass Artifacts Between Them

Action: When install-plus-test takes too long, or when you want different stages to report independently, split the work into multiple jobs with needs to enforce order. The shape:

Use actions/upload-artifact in the build job and actions/download-artifact in any job that consumes the output. Give the artifact a name (dist, coverage-report, app.jar) and a path; without both, uploads fail with a clear message about no files matching.

Expected result: Jobs run as a directed graph. With test and build and build needing test, the build job waits; without needs, they run concurrently on separate machines.

Success check: In the run summary, each job shows its own status block and the dependency arrows are visible in the graph view. Deliberately fail the test job and confirm build is skipped rather than run.

The trade-offs here are real. Splitting jobs increases total wall-clock time because each job re-checks out the code and re-installs dependencies—a job that shares nothing with its predecessor pays the setup cost twice. Splitting only pays off when a stage is slow enough to parallelize against another, or when you need distinct permissions (for example, a deployment job that should hold secrets no test job can see). For a small project, one job with ordered steps is often faster and simpler than three jobs.

Matrix builds are the other splitting tool: a strategy: matrix block runs the same job across combinations of versions or operating systems, such as testing on Python 3.10, 3.11, and 3.12. That's three parallel jobs from one definition, and it's how you verify version compatibility without writing three copies of the YAML.

Step 4: Store Secrets and Configure Deployment

Action: Add credentials under Settings → Secrets and variables → Actions. Repository secrets are available to all workflows; environment secrets belong to a named environment and are only readable by jobs that declare that environment. Reference them in YAML as ${{ secrets.DEPLOY_TOKEN }} and never echo them—GitHub masks secret values in logs, but a transformed value such as a base64-encoded token will print plainly, since masking matches the literal string.

A deployment job in outline:

Expected result: The deploy job only runs after build succeeds, and the token is injected as an environment variable for that step only.

Success check: Add a temporary step that prints ${#API_TOKEN} (the character count) rather than the value itself, confirm the count is nonzero, then delete it. More important, trigger the deploy job from a pull request and confirm it does not run with production secrets.

That last check reflects a design rule, not a formality. Pull requests from forks do not receive repository secrets by default; this is deliberate, because otherwise anyone could open a PR that exfiltrates your credentials. If a workflow needs secrets on fork PRs, GitHub offers an approval mechanism for first-time contributors, but the safer path is to keep deployment off pull requests entirely.

For deployments, use environments with protection rules. Name an environment production, require a reviewer, and restrict it to your default branch. Now a deploy job pauses for human approval and can't be triggered from an arbitrary branch. Pair that with a tag trigger (on: push: tags: ['v*']) so releases deploy only from tagged commits, and your pipeline gets a release gate for free.

Cloud platforms typically document a preferred GitHub integration (for example, OIDC-based short-lived credentials to AWS, or a service principal for Azure). Those mechanisms avoid long-lived secrets entirely. The principle that survives version changes: prefer short-lived, scoped credentials over static tokens, and re-read your cloud provider's current documentation because the exact setup steps and role configurations do change.

Step 5: Add a Branch Protection Gate So the Pipeline Actually Blocks Bad Code

Action: A pipeline that runs but doesn't gate merges is advisory. Turn it into a gate: in Settings → Branches, add a branch protection rule (or repository ruleset) for main that requires status checks to pass before merging, and select your workflow's job names as the required checks.

Expected result: Pull requests targeting main show a "Some checks haven't completed yet" or "All checks have passed" state, and the merge button is disabled while a required check is failing or pending.

Success check: Open a PR with a deliberately failing test; verify the merge button is blocked. Then fix the test and watch the check turn green and the merge button enable. Also confirm which checks appear in the dropdown—job names must match exactly, and renaming a job later silently breaks the requirement unless you update the rule.

This is the step most tutorials skip and the one that changes the pipeline's value. Up to Step 4, you have automation that reports. From Step 5 onward, you have automation that prevents. The required-check list also documents your standards: anyone reading the branch settings can see which jobs must pass.

Step 6: Protect the Pipeline Itself

A working pipeline is now a security surface, and the failure stories here are blunter than elsewhere. A malicious or compromised third-party action can read the runner's environment, including secrets passed to it. Practical defenses:

Pin third-party actions to a commit SHA, not a tag. Tags can be moved; SHAs can't. Grant least privilege on the token. Declare permissions: in the workflow, for example contents: read for a test job. The default token may have write access to your repo, and a compromised step with that token can push. Restricting permissions is a few lines that shrink the blast radius. Keep secrets out of fork PRs by design, as covered above, and never run untrusted code in a job that has deployment secrets. Review Dependabot PRs that bump action versions rather than auto-merging them; a version bump is a code change from a third party.

If you use self-hosted runners, do not run them on public repositories accepting fork PRs—a fork PR executing on a self-hosted runner is a known path to host compromise. GitHub's own documentation states this clearly; treat it as a hard rule rather than a preference.

Troubleshooting the Pipeline: Symptoms, Causes, Reversible Checks

When a run fails, read the failing step's log before changing anything. The most frequent failures and their usual causes:

"Dependencies lock file is not found." The setup action's cache expects a lockfile at the repository root. Check the filename matches your package manager (for example npm-shrinkwrap.json vs package-lock.json) and that it's committed. Works locally, fails on the runner. Almost always a version mismatch or an uncommitted file. Compare the runner's runtime version in the setup step log against your local version; then check git status for files you forgot to commit. Test passes for one job, fails in another. Jobs don't share files. If the second job lacks the built output, you need an artifact upload/download pair, not a repeated build. "Permission denied" on a script. Executable bits aren't preserved when files are copied via artifacts in some configurations, or the runner's user differs. chmod +x in a step, or invoke via the interpreter (bash script.sh), resolves it. Workflow won't trigger. Check four things in order: the file is under .github/workflows/, the YAML parses (GitHub shows an error for malformed files), the on: block matches the event you performed, and the workflow isn't disabled in the Actions tab.

Start with reversible checks: re-run the failed job, inspect the setup step's printed versions, and compare the run's commit against your local HEAD. If a failure persists after those three, and the failing step is inside a third-party action you didn't write, that's a reasonable stop condition—open an issue with the action's maintainers or replace the step with your own shell command rather than patching around it blind. For anything touching deployment credentials, have a second person review the change; a misconfigured deploy step that fails open is worse than one that fails.

How the Pieces Fit in Practice

The complete shape of a mature pipeline built this way is: a ci workflow on every push and PR that installs from the lockfile, lints, tests across a version matrix, and uploads build output; branch protection on main requiring those checks; a separate deploy workflow triggered by version tags, using a protected environment with required reviewers and environment-scoped secrets; and a small permissions block plus SHA-pinned actions keeping the whole thing from becoming a liability. The pipeline's YAML files live in the repository alongside the code, so changes to the pipeline get reviewed like changes to the code—which is the property that makes this approach worth the setup.

Start with Steps 1 and 2, get a green run and then a deliberately red one, and only then add jobs, secrets, and gates. Each step above has a check that tells you whether it worked, so you never have to guess whether the pipeline is doing what you think.

FAQ

Do I need a separate CI service if I already use GitHub Actions? No for most projects. GitHub Actions covers install, test, build, and deploy, and third-party services buy you specific features or integrations rather than a fundamentally different model. The exception is an organization already standardized on another system for compliance or caching reasons.

Can I build a pipeline without writing YAML? The GitHub web UI offers starter workflows that generate files for you, and the Marketplace has prebuilt steps, but the file in .github/workflows/ is still the source of truth. The UI is a scaffold, not an alternative.

How do I run a workflow manually? Add on: workflow_dispatch, then use the "Run workflow" button in the Actions tab. Add inputs: under workflow_dispatch to accept parameters such as an environment name.

What's the difference between an artifact and a cache? Artifacts are outputs you want after the run (builds, reports) and persist for a retention period you set. Caches are inputs you want to reuse to speed up future runs (dependency downloads) and are keyed by a hash, typically of your lockfile.