Skip to content

Commit 81bed05

Browse files
committed
describe action metadata checks in document
1 parent 07878d5 commit 81bed05

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed

docs/checks.md

+74
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ List of checks:
3838
- [Contexts and special functions availability](#ctx-spfunc-availability)
3939
- [Deprecated workflow commands](#check-deprecated-workflow-commands)
4040
- [Conditions always evaluated to true at `if:`](#if-cond-always-true)
41+
- [Action metadata syntax validation](#action-metadata-syntax)
4142

4243
Note that actionlint focuses on catching mistakes in workflow files. If you want some general code style checks, please consider
4344
using a general YAML checker like [yamllint][].
@@ -2657,6 +2658,78 @@ works as intended.
26572658
actionlint checks all `if:` conditions in workflow and reports error when some condition is always evaluated to true due to extra
26582659
characters around `${{ }}`.
26592660

2661+
<a name="action-metadata-syntax"></a>
2662+
## Action metadata syntax validation
2663+
2664+
Example workflow input:
2665+
2666+
```yaml
2667+
on: push
2668+
2669+
jobs:
2670+
test:
2671+
runs-on: ubuntu-latest
2672+
steps:
2673+
# actionlint checks an action when it is actually used in a workflow
2674+
- uses: ./.github/actions/my-invalid-action
2675+
```
2676+
2677+
Example action metadata:
2678+
2679+
```yaml
2680+
# .github/actions/some-action/action.yml
2681+
2682+
name: 'My action'
2683+
author: '...'
2684+
# ERROR: 'description' section is required
2685+
2686+
runs:
2687+
# ERROR: Node.js runtime version is too old
2688+
using: 'node14'
2689+
# ERROR: The source file being run by this action does not exist
2690+
main: 'this-file-does-not-exist.js'
2691+
# ERROR: 'env' configuration is only allowed for Docker actions
2692+
env:
2693+
SOME_VAR: SOME_VALUE
2694+
```
2695+
2696+
Output:
2697+
2698+
```
2699+
test.yaml:8:15: description is required in metadata of "My action" action at "path/to/.github/actions/my-invalid-action/action.yml" [action]
2700+
|
2701+
8 | - uses: ./.github/actions/my-invalid-action
2702+
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2703+
test.yaml:8:15: "node14" runner at "runs.using" is unavailable since the Node.js version is too old (14 < 16) in local action "My action" defined at "path/to/.github/actions/my-invalid-action". see https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-javascript-actions [action]
2704+
|
2705+
8 | - uses: ./.github/actions/my-invalid-action
2706+
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2707+
test.yaml:8:15: file "this-file-does-not-exist.js" does not exist in "path/to/.github/actions/my-invalid-action". it is specified at "main" key in "runs" section in "My action" action [action]
2708+
|
2709+
8 | - uses: ./.github/actions/my-invalid-action
2710+
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2711+
test.yaml:8:15: "env" is not allowed in "runs" section because "My action" is a JavaScript action. the action is defined at "path/to/.github/actions/my-invalid-action" [action]
2712+
|
2713+
8 | - uses: ./.github/actions/my-invalid-action
2714+
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2715+
```
2716+
2717+
All actions require a metadata file `action.yml` or `aciton.yaml`. The syntax is defined in [the official document][action-metadata-doc].
2718+
2719+
actionlint checks metadata files used in workflows and reports errors when they are not following the syntax.
2720+
2721+
- `name:`, `description:`, `runs:` sections are required
2722+
- Runner name at `using:` is one of `composite`, `docker`, `node16`, `node20`
2723+
- Keys under `runs:` section are correct. Required/Valid keys are different depending on the type of action; Docker action or
2724+
Composite action or JavaScript action (e.g. `image:` is required for Docker action).
2725+
- Files specified in some keys under `runs` are existing. For example, JavaScript action defines a script file path for
2726+
entrypoint at `main:`.
2727+
2728+
actionlint checks action metadata files which are used by workflows. Currently it is not supported to specify `action.yml`
2729+
directly via command line arguments.
2730+
2731+
Note that `steps` in Composite action's metadata is not checked at this point. It will be supported in the future.
2732+
26602733
---
26612734

26622735
[Installation](install.md) | [Usage](usage.md) | [Configuration](config.md) | [Go API](api.md) | [References](reference.md)
@@ -2710,3 +2783,4 @@ characters around `${{ }}`.
27102783
[deprecate-set-output-save-state]: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
27112784
[deprecate-set-env-add-path]: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
27122785
[workflow-commands-doc]: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
2786+
[action-metadata-doc]: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# .github/actions/some-action/action.yml
2+
3+
name: 'My action'
4+
author: '...'
5+
# ERROR: 'description' section is required
6+
7+
runs:
8+
# ERROR: Node.js runtime version is too old
9+
using: 'node14'
10+
# ERROR: The source file being run by this action does not exist
11+
main: 'this-file-does-not-exist.js'
12+
# ERROR: 'env' configuration is only allowed for Docker actions
13+
env:
14+
SOME_VAR: SOME_VALUE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/test\.yaml:8:15: description is required in metadata of "My action" action at ".+(\\\\|/)my-invalid-action(\\\\|/)action\.yml" \[action\]/
2+
/test\.yaml:8:15: invalid runner name \"node14\" at runs\.using in \"My action\" action defined at \".+(\\\\|/)actions(\\\\|/)my-invalid-action\"\. valid runners are \"composite\", \"docker\", \"node16\", and \"node20\"\. see https://.+ \[action\]/
3+
/test\.yaml:8:15: file "this-file-does-not-exist\.js" does not exist in ".+(\\\\|/)my-invalid-action"\. it is specified at "main" key in "runs" section in "My action" action \[action\]/
4+
/test\.yaml:8:15: "env" is not allowed in "runs" section because "My action" is a JavaScript action\. the action is defined at ".+(\\\\|/)my-invalid-action" \[action\]/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
on: push
2+
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
steps:
7+
# actionlint checks an action when it is actually used in a workflow
8+
- uses: ./.github/actions/my-invalid-action

0 commit comments

Comments
 (0)