Fix GitHub Actions Steps with Both Uses and Run

Resumo

Pixel’s announcement explains why GitHub Actions rejects a step containing both uses and run, and why the error quotes whichever key appears second. It covers common causes such as missing YAML dashes, replacing a command with an action, and pasting an example into an existing step.

DEV Community

GitHub Actions step cannot have both uses and run, and what you get

A GitHub Actions step cannot have both uses and run, and that sentence was once the message you got, but the parser that ships today does not contain it anywhere. What it produces instead names one of the two keys as unexpected, which is a different sentence and a more precise one once you know how the reader arrives at it. The reader narrows as it reads. The first of the two keys chooses a shape, and the second has nowhere to go inside it. What this error means The workflow stops running and the commit carries an invalid file annotation with a line, a column and a quoted key. The quoted key is one of the two you wrote, and which one it is depends on the order you wrote them in rather than on which one is wrong. If you came here from an older answer expecting a sentence about both keys, the thing to check is whether your annotation says that at all, because a message that quotes a single key is telling you something the older sentence did not. ```Reconstructed from the key branch of TemplateReader and the UnexpectedValue format string in actions/runner Invalid workflow file: .github/workflows/ci.yml#L9 (Line: 9, Col: 9): Unexpected value 'run'

Common causes

Indentation merged two steps into one item

The commonest cause and the hardest to see. A missing dash turns what should be a new sequence item into another key of the previous one, and the file stays valid YAML throughout.

A command was replaced by an action in place

Somebody swapped the middle of a step, putting an action reference where a command was, and left the other key behind. The diff touches one line, which is why review passes over it.

An example was pasted inside an existing step

Documentation examples begin with a dash and assume they are being added as a new item. Pasted into the body of an existing step they become extra keys of it.

The step was meant to do two things

Occasionally the intent really was to run an action and then a command. In our experience this is rarer than the accidental cases, and the answer is the same: two steps.

How to fix it

Read which key the annotation names

  1. Open the annotation and note the quoted key and the column.
  2. The quoted key is the second one in your file, not necessarily the wrong one.
  3. Go to that line and look at whether it should have started a new sequence item.

Split into two steps

Give each of the two a dash of its own at the same indentation as the other items in the sequence. Name them if the job has several steps, since the default name of a run step is the command text.

```.github/workflows/ci.yml
steps:
- name: Check out
uses: actions/checkout@v5
- name: Install
run: npm ci
Check the whole sequence, not just the reported line An indentation slip that merged one pair often merged another further down, and the reader stops recording after it has enough to reject the file. Read every item in the sequence once before pushing again. Validate before pushing The same schema is available to editor tooling, so a file that will be rejected can be rejected locally. This is the only one of these fixes that prevents the next occurrence rather than resolving this one. How to prevent it Keep one action or one command per step, and treat that as a review rule. Watch for a missing dash whenever a step gains a key it did not have. Paste documentation examples after a step, never inside one. Validate workflow files in the editor against the published schema. What the reader does with the second key In the published schema an item in a step sequence is a choice between two mapping shapes. One requires the run key and additionally allows a working directory and a shell. The other requires the uses key and additionally allows with. Everything else the shapes accept, env among it, is on both. Neither shape lists the other required key, and neither permits loose keys. The reader does not collect your keys and judge them at the end. It narrows while it reads. Each key ...
Fix GitHub Actions Steps with Both Uses and Run
Powered by Readybot.io

As últimas novidades de Pixel

Fix GitHub Pages: Missing Artifact Error

Pixel's announcement explains why the GitHub Pages deploy action reports that no github-pages artifact was found. It covers skipped or failed build jobs, missing uploads, …

Rotate DB and Redis Passwords Without Downtime

Pixel shares a practical guide to rotating exposed database and Redis passwords without interrupting application connections. The approach updates Secrets, changes service credentials, and gradually …

AI Agent Receipts Prove What Actually Executed

Pixel’s announcement examines how public Zambo receipts verify what an AI agent actually did. A BTC price fetch succeeded with a recomputable output hash, while …