-
-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add action typing #198
Add action typing #198
Conversation
Thank you for your contribution! We don't feel comfortable promoting non-standard tooling. |
Totally understandable, but thanks for considering, and thanks for the awesome action, saved my ass a couple of times already. :-) |
# See https://github.com/typesafegithub/github-actions-typing/ | ||
inputs: | ||
sudo: | ||
type: boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this is not correct. The default is auto
, which is not a Boolean value.
This actually points out a direction that I could get behind: using input types in the action.yml
file. For example, the sudo
input, which is currently declared thusly:
sudo:
description: 'If apt should be executed with sudo or without'
required: false
default: 'auto'
we could add the type
and options
attributes to define it like this instead:
sudo:
description: 'If apt should be executed with sudo or without'
required: false
default: 'auto'
type: choice
options:
- auto
- false
- true
This would likely achieve at least most of what typesafegithub
seems to aim for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, on second glance, it looks as if this is only for workflow_dispatch
workflows, not for GitHub Actions' action.yml
files (whose syntax appears to be limited to description
, required
, default
and deprecationMessage
, something that would appear unlikely to change).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, we could model it as an enum, github-actions-typing supports it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, on second glance, it looks as if this is only for workflow_dispatch workflows, not for GitHub Actions' action.yml files
Exactly, it was requested in https://github.com/orgs/community/discussions/32054 that they add native typing information, but for the time being there is no definition or support for it.
The 3rd party typing information could of course also be stored within the action file, but it was considered a better idea to have it in a separate file in case GitHub makes up their mind and supports native typing which likely would then be in the action file so that there will not be a clash of the tow approaches.
This would likely achieve at least most of what typesafegithub seems to aim for?
This could also be achieved with gat as @krzema12 said, using
sudo:
type: enum
allowed-values:
- auto
- true
- false
if you like.
I just interpreted the situation as a three-sate boolean.
Not having anything set behaves either like true
or false
depending on context.
That is what you call auto
.
I thought if you set a value, you will set either true
or false
but never explicitly auto
.
But I could of course change this to enum
if you like.
tmate-server-rsa-fingerprint: | ||
type: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where I would wish for a much more powerful type declaration. RSA fingerprints have a very specific format that could totally be automatically type-checked statically, but simply saying string
won't help that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github-actions-typing supports just primitive types for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who knows, maybe in the future there will be some support for validations, like min and max values for numbers like tmate-server-port
, or regexes for strings like tmate-server-rsa-fingerprint
.
This is just not defined yet.
But actually it might be a good idea, so I created a feature request for it at typesafegithub/github-actions-typing#205 :-)
I would like to see your action first-class supported by https://github.com/typesafegithub/github-workflows-kt, a Kotlin DSL to write GitHub Action workflows.
The project came up with ways to reduce operational load when keeping the library's action wrappers in sync with actions' inputs and outputs.
The solutions include onboarding https://github.com/typesafegithub/github-actions-typing.
It is as easy as adding an extra YAML file to your repository root, and (optionally) adding a simple GitHub workflow that validates this new file.
Thanks to this, the code generator in the Kotlin DSL can fetch typing info provided by you instead of them, which has a number of benefits.
It has no negative effects on current action consumers, they continue to use the action via regular GitHub API, as if the file was not there.
In this pull request, I would like to ask you if you are open to introduce such typings in your action and also provide the current state as far as I could determine it.
You would not be the first, there are already other actions using it, like e.g. my https://github.com/Vampire/setup-wsl or also Microsoft's https://github.com/microsoft/setup-msbuild.
Also "regular" users can benefit from this clear and formalized typing definition, seeing exactly what values are valid.
And as the typings are made independent from the Kotlin DSL library, also other DSL or similar consumers could use these typings in the future.
When accepting this PR and in the future maintaining the typing yourself,
please keep in mind that API are generated from these typing information.
So if you for example recognize that a type is wrong and want to change it for example from
string
tointeger
,this would be a breaking change for such consumers and should therefore be done with a major version bump.
Backwards compatible changes like new enum options, or new inputs or outputs can of course be released in a minor version as usual.
After hopefully merging this PR it would be nice if you could cut a release soon,
so that the shiny new typings can be used right away.