-
Notifications
You must be signed in to change notification settings - Fork 196
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 github action to sync api docs to the user docs site #276
Conversation
5e9b091
to
4d7d596
Compare
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.
Couple of things:
- There is no linting or build step so we wont know if anything is broken until we try to run it next
- Documentation could be far better. Even a basic what this does and why in a readme would be appreciated
- There is a lot of behaviour here that is untested. I would not be comfortable updating dependencies etc
tools/api-docs-generator/main.go
Outdated
|
||
func main() { | ||
if len(os.Args) != 3 { | ||
log.Fatal("usage: api-docs <config-file> <docs-dir>") |
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.
Perhaps consider https://github.com/spf13/viper , although this is fine for now
Oh and alerting, how will we know if this fails? |
4d7d596
to
302d6a1
Compare
c958691
to
43e14cb
Compare
43e14cb
to
fda4cac
Compare
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 looking good!
I'm still concerned what will happen if this script runs before a previous pull request is merged, looks like it is using the same branch name every time so will it error? Stack empty commits? No-op? (hopefully the last one)
I can see there were a lot of notes that were previously on Apiary that have been lost on the new V1 docs. Eg: https://snyk.docs.apiary.io/#reference/import-projects . Some of those notes may be redundant but we are losing information in this new system. However the one for licenses is present: https://snyk.docs.apiary.io/#reference/licenses . Was that one manually added? Will this script overwrite it?
.github/workflows/sync-api-docs.yml
Outdated
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
#TODO: Remove before merge |
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.
Need to do this
make run | tee /tmp/run.log | ||
result_code=${PIPESTATUS[0]} | ||
echo 'MENU<<EOF' >> $GITHUB_OUTPUT | ||
cat /tmp/run.log >> $GITHUB_OUTPUT | ||
echo 'EOF' >> $GITHUB_OUTPUT | ||
exit $result_code |
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.
Can't you write to $GITHUB_OUTPUT
directly? I don't see why /tmp/run.log
is necessary
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.
echo 'MENU<<EOF' >> $GITHUB_OUTPUT
make run >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
Looses the exit status of the run; it will return the exit status of echo
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.
echo MENU >> $GITHUB_OUTPUT
make run >> $GITHUB_OUTPUT
?
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.
Or
set -o pipefail
echo MENU >> $GITHUB_OUTPUT
make run | tee -a $GITHUB_OUTPUT
if you want to preserve stdout
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.
The way multi line strings work in GHA needs the closing delimiter: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
.github/workflows/test-generator.yml
Outdated
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
#TODO: Remove before merge |
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.
Another todo
test: tidy lint | ||
go test ./... | ||
|
||
run: | ||
@go run . config.yml ../.. | ||
|
||
lint: tidy | ||
go run github.com/golangci/golangci-lint/cmd/golangci-lint run | ||
|
||
format: tidy | ||
go run golang.org/x/tools/cmd/goimports -w -local=github.com/snyk/user-docs/tools/api-docs-generator . | ||
|
||
tidy: | ||
go mod tidy |
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.
nit: all of these should be marked .PHONY
as they do not output the target
@go run . config.yml ../.. | ||
|
||
lint: tidy | ||
go run github.com/golangci/golangci-lint/cmd/golangci-lint run |
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.
Please pin the version, there are occasionally breaking changes
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.
version is pinned in the go.mod file
} | ||
|
||
formattedSpec := bytes.NewBufferString("") | ||
err = json.Indent(formattedSpec, jsonSpec, "", " ") |
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.
json keys are unordered, I'm not sure if vervet generation is stable if content is the same but something else changes that is unrelated to the current spec - eg a new version is published
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.
interesting point, have not seen this occur yet, keep on eye on the PR if these PRs are generated
func getLatestGAVersion(versions []string) string { | ||
gaVersions := []string{} | ||
for _, version := range versions { | ||
if !strings.Contains(version, "~") { |
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.
~ga
is an optional valid suffix for ga versions
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.
the suffix is used for version resolution right? When listing the versions, I dont see us rendering ~ga at the end of versions
gaVersions = append(gaVersions, version) | ||
} | ||
} | ||
sort.Strings(gaVersions) |
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.
You're already iterating over the entire list above, seems very inefficient to do that and then sort them after to select one element when you can select the largest element in one pass
body: | | ||
This PR was automatically generated by the API docs synchronization action. Please review the changes and merge if they look good. | ||
``` | ||
${{ steps.generate.outputs.MENU }} |
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.
I think we need to have a bit more explanation about what to do with this menu in the pull request. At the moment it is tribal knowledge that can easily be misunderstood.
Yep, will add that feature as a followup PR
The default behaviour of the PR action is to merge it into the previous PR |
fda4cac
to
3f75aef
Compare
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.
Approving on behalf of docs team.
Currently this generates references docs, based on the tags supplied in the open api docs
Will add altering if the job fails as a separate PR