-
Notifications
You must be signed in to change notification settings - Fork 936
chore: generate countries.tsx from Go code #15274
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
Conversation
@johnstcn @dannykopping please do have a look |
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.
Looks good from my end, some linter issues.
Could you add an exaple prompt comand (see cli/prompts.go
)?
This will let us validate country selection more easily (e.g. go run ./cmd/coder exp prompt-example country
)
cc @BrunoQuaresma for FE review
scripts/apitypings/main_test.go
Outdated
@@ -51,3 +52,36 @@ func TestGeneration(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
|||
func TestGenerateSliceOfObjectsTypeScript(t *testing.T) { | |||
|
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.
t.Parallel() |
scripts/apitypings/main.go
Outdated
|
||
countriesTS, err := generateSliceOfObjectsTypeScript("countries", codersdk.Countries) | ||
if err != nil { | ||
log.Fatal(ctx, fmt.Sprintf("generate countries typeScript: %s", err.Error())) | ||
} | ||
_, _ = fmt.Print("// The code below is generated from codersdk/countries.go.\n") | ||
_, _ = fmt.Print(countriesTS, "\n") | ||
|
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.
To do this correctly, we should not have to specify codersdk.Countries
. We should implement it here:
coder/scripts/apitypings/main.go
Lines 458 to 459 in afacb07
case *types.Var: | |
// TODO: Are any enums var declarations? This is also codersdk.Me. |
I feel a bit apprehensive to import codersdk
into this tool.
We could make it a new generator (:cry:) or actually auto-gen vars from the codersdk package (like codersdk.Me
).
If we do the vars
, we might want to have some opt-in comment. Idk how many var declarations we have
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.
We should really have a general autogen tool and pattern for these. When the types are in Go and no package AST parsing is necessary.
rbacgen
is an example.
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.
got it, will implement a general autogen tool. As suggested, I'm thinking of doing it similar to how rbacgen
is done.
So the autogen tool will be under scripts/valuegen
which contains main.go
which is the script itself and typescript.tstmpl
which will be the TS template to which we will convert the countries.go
Line 3 in 1702c64
var Countries = []Country{ |
If similar types conversion needs are needed in the future for other types in Go, it can be handled in the script to use the same typescriptconst.tstmpl
template or a different one based on the need.
does that make sense? wdyt?
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.
@joobisb That all sounds reasonable. It'll probably throw into a different .ts
file.
It would be awesome if rbacgen
and valuegen
could be merged into 1 😄
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.
@Emyrk I have updated the scripts and have merged both into a single typegen
script, please do have a look
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.
Perfect 👍
Head branch was pushed to by a user without write access
@matifali could you please help to run the CI again and merge, I've fixed a formatting error |
I am unsure why that premium e2e is failing. I'll take a quick look |
@Emyrk Because PRs from forks do not have access to secrets. |
This could be solved by using, on:
pull_request_target: The only downside is that the workflows are run from the target branch, but the code is checked out from the PR branch. |
@joobisb Thanks for the reminder. I will try something like the one below and let you know if it works.
|
Closes #15074
We have a hard-coded list of countries at https://github.com/coder/coder/blob/main/site/src/pages/SetupPage/countries.tsx. This means Go code in coder/coder doesn't have an easy way of utilizing it.
Solution
Generate countries.tsx from Go code. Generated by
scripts/apitypings