Sub topic 8
When the workflow file itself is invalid
This chapter assumes you can find a failed run and read a step log, which earlier chapters cover. It deals with a different kind of failure. Sometimes no step fails because GitHub could not turn the file into a runnable workflow. There is no step log to read, so you need other clues.
Two kinds of "workflow failed"
A workflow file passes through two stages before your commands run.
- Parsing and validation. GitHub reads the YAML and checks it against the workflow schema. If this fails, no job is created.
- Execution. A runner picks up each job and runs its steps. Step logs exist only from this stage on.
A file error is therefore easy to mistake for a missing run. Check which stage failed before you open any logs.
Where the error shows up
File errors appear in a few places:
- The run page. The run is marked failed and often shows a banner such as "This run likely failed because of a workflow file issue." The graph contains no jobs, and an annotation names the file and line.
- The workflow list. In the Actions sidebar, an invalid file may show its file path instead of its
name:, because GitHub could not read the name. - The commit and pull request checks. The failed run still appears as a red check, but it opens to the empty run page described above.
- The editor. The web editor for files under
.github/workflows/validates as you type. This is the fastest feedback loop you have.
The annotation text varies, so treat the messages below as typical examples. Always use the line number it gives, but keep in mind that YAML parsers often report the line where they noticed the problem, which can be a line or two after the real mistake.
Category 1: YAML syntax errors
These make the file unparseable as YAML. Nothing else can be checked until you fix them.
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: npm testHere run: sits at the same indentation as the -, so it is no longer part of the step. The parser reports a syntax error near that line. The fix is to indent run: to line up with name:.
Common syntax traps:
- Tabs. YAML forbids tabs for indentation. Use spaces only.
- A colon followed by a space inside an unquoted value.
run: echo Step: oneis read as a nested mapping. Quote the value or use a block scalar (run: |). - A value that starts with a YAML indicator.
if: !cancelled()fails because!starts a YAML tag. Writeif: ${{ !cancelled() }}. Likewise, quote glob patterns that start with*, as in'**', because a bare*starts an alias. - Unbalanced quotes in a long one-line
run:command. A block scalar avoids most of these.
Category 2: Schema errors
Here the YAML is valid, but the content does not match what a workflow allows. Typical causes are a misspelled key, a key in the wrong place, or a value of the wrong type.
name: CI
on: push
jobs:
build:
runs_on: ubuntu-latest
steps:
- run: echo build
deploy:
needs: biuld
runs-on: ubuntu-latest
steps:
- run: echo deployThis file has two separate mistakes:
runs_onshould beruns-on. Expect a message about an unexpected valueruns_onor a missing requiredruns-on.needs: biuldnames a job that does not exist. The message says the job depends on an unknown job.
A parsed file can still fail validation for other reasons. A job needs runs-on (or a uses: that calls a reusable workflow), and it needs steps. The on: key must contain at least one valid event. A uses: value must have the right shape, such as owner/repo@ref or ./path.
Category 3: Expression errors
Expressions are written as ${{ ... }} and are checked when the file is validated. Two mistakes cause most of the trouble:
# Wrong: string literals in expressions use single quotes
if: ${{ github.ref == "refs/heads/main" }}
# Right
if: ${{ github.ref == 'refs/heads/main' }}The other mistake is using a context in a place where it is not available. For example, the env context cannot be used in jobs.<id>.runs-on. The error names the context and the key. The GitHub documentation has a table of which contexts each key accepts.
Category 4: The file is valid but never runs
A syntactically perfect file can still produce no run. In this case no error appears at all, which makes it harder to find.
| Symptom | Likely cause | Fix |
|---|---|---|
| No run, no workflow in sidebar | File is not in `.github/workflows/` or does not end in `.yml` or `.yaml` | Move or rename the file |
| Workflow listed, no run on push | `branches` or `paths` filter excludes the change | Compare the filter with the pushed branch and files |
| No run on a pull request | The event is `push` only, or the PR has merge conflicts | Add `pull_request`; resolve conflicts |
| "Run workflow" button missing | `workflow_dispatch` is not in `on:`, or the file is not on the default branch | Add the trigger and merge to the default branch |
| Scheduled run never starts | `schedule` runs only from the default branch's version | Merge the file to the default branch |
| Run fails at "Set up job" with "Unable to resolve action" | Typo in the action name or a nonexistent version tag | Fix the `uses:` value, for example `@v4` instead of `@v44` |
The last row is a runtime error, not a file error. GitHub accepts the uses: shape, but the runner cannot download the action. The log for "Set up job" tells you exactly which reference failed.
Checking the file before you push
You can catch most file errors locally. actionlint is a widely used linter for workflow files. It checks YAML syntax, schema, expressions, and needs references.
# macOS or Linux with Homebrew
brew install actionlint
# Or with Go installed
go install github.com/rhysd/actionlint/cmd/actionlint@latest
# Run from the repository root; it finds .github/workflows/*.yml
actionlintA typical result for the schema example above is a line such as .github/workflows/ci.yml:6:5: unexpected key "runs_on" for "job" section, followed by a similar message for needs. You can then fix both problems in one pass instead of pushing twice.
The gh CLI also helps you see how GitHub itself views your workflows:
# List workflows GitHub knows about, including disabled ones
gh workflow list --all
# Show the details of one workflow by file name
gh workflow view ci.ymlIf your workflow is missing from this list, GitHub has not accepted the file, and the cause is in the path, the branch, or the syntax.
Fixing and verifying
Here is the corrected version of the two broken files from earlier, combined into one valid workflow:
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: npm test
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- run: echo deployVerification differs from a normal step fix. After you push, the first thing to confirm is that the run now has jobs. Open the run page and check that the graph shows build and deploy. Only after that does it make sense to read step logs for runtime failures.
A good habit for any workflow edit:
- Run
actionlintlocally. - Push to a branch, not the default branch.
- Confirm the run appears with the expected jobs.
- Read the first failing step, if any, using the methods from earlier chapters.
Summary of the diagnostic order
- Does a run exist? If not, check the path, triggers, and filters.
- Does the run have jobs? If not, read the annotation and fix syntax, schema, or expression errors.
- Did "Set up job" fail? Check the
uses:references and runner labels. - Otherwise, read the step logs for the first real error.
Exercise
A pull request shows a red check, but the run page has no jobs and no step logs. The annotation says "You have an error in your yaml syntax on line 12." Line 11 is - name: Install and line 12 is run: npm ci, with run: indented two spaces less than name:. What is wrong, and what should you check after pushing the fix?
Show answer
The run: key is not indented to line up with name:, so it is not part of the step and the YAML is invalid. Indent run: to match name:. After pushing, first confirm that the run now shows its jobs, then read step logs for any runtime failure.
Exercise
You add workflow_dispatch: to on: in a feature branch, but the "Run workflow" button does not appear in the Actions tab. The file passes actionlint. Why, and what is the fix?
Show answer
The manual trigger button appears only for workflows whose file is on the default branch. The file is valid, so there is no syntax error to find. Merge the change to the default branch, and the button will appear.