-
-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathfmt_check.py
More file actions
106 lines (92 loc) · 4.45 KB
/
Copy pathfmt_check.py
File metadata and controls
106 lines (92 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import dataclasses
from action import Action, OpenTofu
from environment_variables.GITHUB_DOT_COM_TOKEN import GITHUB_DOT_COM_TOKEN
from environment_variables.TERRAFORM_CLOUD_TOKENS import TERRAFORM_CLOUD_TOKENS
from inputs.backend_config import backend_config
from inputs.backend_config_file import backend_config_file
from inputs.path import path
from inputs.var_file import var_file
from inputs.variables import variables
from inputs.workspace import workspace
from outputs.failure_reason import failure_reason
fmt_check = Action(
'fmt-check',
'''
This action uses the `$ToolName fmt` command to check that all files in a $ProductName configuration directory are in the canonical format.
This can be used to check that files are properly formatted before merging.
If any files are not correctly formatted a failing GitHub check will be added for the file, and the job failed.
''',
meta_description='Check that OpenTofu configuration files are in canonical format',
inputs=[
dataclasses.replace(path, description='The path containing $ProductName files to check the formatting of.'),
dataclasses.replace(workspace, description='''
$ProductName workspace to inspect when discovering the $ProductName version to use, if the version is not otherwise specified.
See [dflook/$ToolName-version](https://github.com/dflook/terraform-github-actions/tree/main/$ToolName-version#$ToolName-version-action) for details.
'''),
dataclasses.replace(variables, available_in=[OpenTofu], description='''
Variables to set when initializing $ProductName. This should be valid $ProductName syntax - like a [variable definition file]($VariableDefinitionUrl).
Variables set here override any given in `var_file`s.
'''),
dataclasses.replace(var_file, available_in=[OpenTofu]),
dataclasses.replace(backend_config, description='''
List of $ProductName backend config values, one per line. This is used for discovering the $ProductName version to use, if the version is not otherwise specified.
See [dflook/$ToolName-version](https://github.com/dflook/terraform-github-actions/tree/main/$ToolName-version#$ToolName-version-action) for details.
'''),
dataclasses.replace(backend_config_file, description='''
List of $ProductName backend config files to use, one per line. This is used for discovering the $ProductName version to use, if the version is not otherwise specified.
See [dflook/$ToolName-version](https://github.com/dflook/terraform-github-actions/tree/main/$ToolName-version#$ToolName-version-action) for details.
Paths should be relative to the GitHub Actions workspace
''')
],
outputs=[
dataclasses.replace(failure_reason, description='''
When the job outcome is `failure` because the format check failed, this will be set to 'check-failed'.
If the job fails for any other reason this will not be set.
This can be used with the Actions expression syntax to conditionally run a step when the format check fails.
''')
],
environment_variables=[
GITHUB_DOT_COM_TOKEN,
dataclasses.replace(TERRAFORM_CLOUD_TOKENS, description='For the purpose of detecting the $ProductName version to use from a cloud backend.' + TERRAFORM_CLOUD_TOKENS.description),
],
extra='''
## Example usage
This example workflow runs on every push and fails if any of the
$ProductName files are not formatted correctly.
```yaml
name: Check file formatting
on: [push]
jobs:
check_format:
runs-on: ubuntu-latest
name: Check $ProductName file are formatted correctly
steps:
- name: Checkout
uses: actions/checkout@v4
- name: $ToolName fmt
uses: dflook/$ToolName-fmt-check@v2
with:
path: my-$ToolName-config
```
This example executes a run step only if the format check failed.
```yaml
name: Check file formatting
on: [push]
jobs:
check_format:
runs-on: ubuntu-latest
name: Check $ProductName file are formatted correctly
steps:
- name: Checkout
uses: actions/checkout@v4
- name: $ToolName fmt
uses: dflook/$ToolName-fmt-check@v2
id: fmt-check
with:
path: my-$ToolName-config
- name: Wrong formatting found
if: ${{ failure() && steps.fmt-check.outputs.failure-reason == 'check-failed' }}
run: echo "formatting check failed"
```
'''
)