You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/actions/creating-actions/metadata-syntax-for-github-actions.md
+32-2Lines changed: 32 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -175,7 +175,8 @@ runs:
175
175
176
176
### `pre-if`
177
177
178
-
**Optional** Allows you to define conditions for the `pre:` action execution. The `pre:` action will only run if the conditions in `pre-if` are met. If not set, then `pre-if` defaults to `always()`.
178
+
**Optional** Allows you to define conditions for the `pre:` action execution. The `pre:` action will only run if the conditions in `pre-if` are met. If not set, then `pre-if` defaults to `always()`. In `pre-if`, status check functions evaluate against the job's status, not the action's own status.
179
+
179
180
Note that the `step` context is unavailable, as no steps have run yet.
180
181
181
182
In this example, `cleanup.js` only runs on Linux-based runners:
@@ -202,7 +203,7 @@ The `post:` action always runs by default but you can override this using `post-
202
203
203
204
### `post-if`
204
205
205
-
**Optional** Allows you to define conditions for the `post:` action execution. The `post:` action will only run if the conditions in `post-if` are met. If not set, then `post-if` defaults to `always()`.
206
+
**Optional** Allows you to define conditions for the `post:` action execution. The `post:` action will only run if the conditions in `post-if` are met. If not set, then `post-if` defaults to `always()`. In `post-if`, status check functions evaluate against the job's status, not the action's own status.
206
207
207
208
For example, this `cleanup.js` will only run on Linux-based runners:
208
209
@@ -265,6 +266,35 @@ For more information, see "[`github context`](/actions/reference/context-and-exp
265
266
**Required** The shell where you want to run the command. You can use any of the shells listed [here](/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsshell). Required if `run` is set.
266
267
{% endif %}
267
268
269
+
#### `runs.steps[*].if`
270
+
271
+
**Optional** You can use the `if` conditional to prevent a step from running unless a condition is met. You can use any supported context and expression to create a conditional.
272
+
273
+
{% data reusables.github-actions.expression-syntax-if %} For more information, see "[Expressions](/actions/learn-github-actions/expressions)."
274
+
275
+
**Example: Using contexts**
276
+
277
+
This step only runs when the event type is a `pull_request` and the event action is `unassigned`.
278
+
279
+
```yaml
280
+
steps:
281
+
- run: echo This event is a pull request that had an assignee removed.
The `my backup step` only runs when the previous step of a composite action fails. For more information, see "[Expressions](/actions/learn-github-actions/expressions#job-status-check-functions)."
You can use the following status check functions as expressions in `if` conditionals. A default status check of `success()` is applied unless you include one of these functions. For more information about `if` conditionals, see "[Workflow syntax for GitHub Actions](/articles/workflow-syntax-for-github-actions/#jobsjob_idif)."
271
+
You can use the following status check functions as expressions in `if` conditionals. A default status check of `success()` is applied unless you include one of these functions. For more information about `if` conditionals, see "[Workflow syntax for GitHub Actions](/articles/workflow-syntax-for-github-actions/#jobsjob_idif)" and "[Metadata syntax for GitHub Composite Actions](/actions/creating-actions/metadata-syntax-for-github-actions/#runsstepsif)".
272
272
273
273
### success
274
274
@@ -316,6 +316,32 @@ steps:
316
316
if: {% raw %}${{ failure() }}{% endraw %}
317
317
```
318
318
319
+
### Evaluate Status Explicitly
320
+
321
+
Instead of using one of the methods above, you can evaluate the status of the job or composite action that is executing the step directly:
322
+
323
+
#### Example for workflow step
324
+
325
+
```yaml
326
+
steps:
327
+
...
328
+
- name: The job has failed
329
+
if: {% raw %}${{ job.status == 'failure' }}{% endraw %}
330
+
```
331
+
332
+
This is the same as using `if: failure()` in a job step.
333
+
334
+
#### Example for composite action step
335
+
336
+
```yaml
337
+
steps:
338
+
...
339
+
- name: The composite action has failed
340
+
if: {% raw %}${{ github.action_status == 'failure' }}{% endraw %}
341
+
```
342
+
343
+
This is the same as using `if: failure()` in a composite action step.
344
+
319
345
## Object filters
320
346
321
347
You can use the `*` syntax to apply a filter and select matching items in a collection.
`action`|`string` | The action that was performed. Can be one of `opened`, `closed`, `reopened`, `assigned`, `unassigned`, `labeled`, or `unlabeled`.
3
+
`action`|`string` | The action that was performed. Can be one of `opened`, `edited`, `closed`, `reopened`, `assigned`, `unassigned`, `labeled`, or `unlabeled`.
`action`|`string` | The action that was performed. Can be one of `opened`, `closed`, `reopened`, `assigned`, `unassigned`, `review_requested`, `review_request_removed`, `labeled`, `unlabeled`, and `synchronize`.
3
+
`action`|`string` | The action that was performed. Can be one of `opened`, `edited`, `closed`, `reopened`, `assigned`, `unassigned`, `review_requested`, `review_request_removed`, `labeled`, `unlabeled`, and `synchronize`.
0 commit comments