github / vscode-github-actions

GitHub Actions extension for VS Code
https://marketplace.visualstudio.com/items?itemName=GitHub.vscode-github-actions
MIT License
484 stars 79 forks source link

There is no formatter for 'github-actions-workflow' #195

Open asilverman opened 1 year ago

asilverman commented 1 year ago

Describe the bug A clear and concise description of what the bug is. image

Expected behavior I would expect formatting to 'just work' and also to have documentation about how to configure it

Extension Version v0.25.7

Additional context Add any other context about the problem here.

felipesu19 commented 1 year ago

I think a formatter would be great. I also think its a pretty big reach from where we are now. I think for there to be any chance of this card getting worked on, we need a much clearer idea of the scope of work. I'm going to leave it open for now while we mull it over, but its more likely to get traction if we had a better idea of what it would imply

sparr commented 1 year ago

Can we just call an installed YAML formatter until there's a specific formatter for actions workflows?

asilverman commented 1 year ago

@sparr that is a great idea and it's is how I am working around it, by switching betweeen the file type recognition in vscode. I would love to be able to configure the file association of a GitHub action file with a yaml formatter, that should be a heavy lift.

@felipesu19 what are your thought?

scott-doyland-burrows commented 1 year ago

I installed the redhat yaml extension and this uses various schemas from here: https://github.com/SchemaStore/schemastore

This gives formatting for GHA yaml files - I see this in the GHAs files (including for action.yaml files - see the second image).

image

image

This is using the following schemas:

https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-workflow.json https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/github-action.json

I do not use the "official" GitHub Actions extension anymore as it is quite buggy (ie, red underlined text showing issues when there are none) and has no formatter. And it does not work on action.yaml files.

However, I keep an eye on it to see if it has improved, as I do like the way it colours the text and the things that do work are great.

If the GitHub Actions extension could make use of https://github.com/SchemaStore/schemastore then it'd be much more useful.

BTW - I also have this set in my vscode settings:

"yaml.schemas": {

        "https://json.schemastore.org/github-workflow.json": [
            "*.github/workflows/*.yaml",
            "*.github/workflows/*.yml",
        ],
        "https://json.schemastore.org/github-action.json": [
            "action.yaml",
            "action.yml",
        ]
    }

I did try just setting that without installing the redhat yaml extension, but it didn't work from what I remember. I had to have the redhat yaml extension installed as well. The settings config is not strictly necessary, but I did find a few files were not picked up as GHA workflow files, but this settings config seems to make them all get picked up.

na-jakobs commented 1 year ago

Can we just call an installed YAML formatter until there's a specific formatter for actions workflows?

This. Is it not possible to call Prettier or the configured YAML formatter?

felipesu19 commented 1 year ago

This. Is it not possible to call Prettier or the configured YAML formatter?

We'd need to expose a configuration that allowed the user to point at a YAML formatter. Not impossible but does require some UI work and may run into issues depending on what formatter people want to use.

starball5 commented 1 year ago

Related on Stack Overflow: There is no formatter for 'github-actions-workflow' files installed.

@felipesu19, why doesn't is work to just honour something like this?:

"[github-actions-workflow]": {
    "editor.defaultFormatter": "redhat.vscode-yaml"
},
sparr commented 1 year ago

@felipesu19 Would you support a vscode feature request such that you could just name one or more fallback languages, so you only need to say "treat this file like yaml for features we don't provide"?

jsolly commented 6 months ago

My current workflow involves moving the workflow .yml files out of the workflows directory, formatting them, and returning them. This process is very painful.

sykhro commented 6 months ago

My current workflow involves moving the workflow .yml files out of the workflows directory, formatting them, and returning them. This process is very painful.

image

you can click on "GitHub Actions Workflow" in the bottom right to switch the language mode to yml, format, switch back

jsolly commented 5 months ago

My current workflow involves moving the workflow .yml files out of the workflows directory, formatting them, and returning them. This process is very painful.

image

you can click on "GitHub Actions Workflow" in the bottom right to switch the language mode to yml, format, switch back

Great workaround! Thanks