Skip to content
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

Merged
merged 1 commit into from
May 23, 2024

Conversation

tinygrasshopper
Copy link
Collaborator

@tinygrasshopper tinygrasshopper commented May 16, 2024

  • 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

@tinygrasshopper tinygrasshopper requested a review from a team as a code owner May 16, 2024 07:43
@tinygrasshopper tinygrasshopper force-pushed the chore/docs-action branch 11 times, most recently from 5e9b091 to 4d7d596 Compare May 16, 2024 08:44
@tinygrasshopper tinygrasshopper requested a review from jgresty May 16, 2024 12:15
Copy link
Member

@jgresty jgresty left a 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

.github/workflows/sync-api-docs.yml Outdated Show resolved Hide resolved
.github/workflows/sync-api-docs.yml Outdated Show resolved Hide resolved
.github/workflows/sync-api-docs.yml Outdated Show resolved Hide resolved
tools/api-docs-generator/spec_fetcher_test.go Outdated Show resolved Hide resolved

func main() {
if len(os.Args) != 3 {
log.Fatal("usage: api-docs <config-file> <docs-dir>")
Copy link
Member

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

tools/api-docs-generator/reference_docs.go Outdated Show resolved Hide resolved
tools/api-docs-generator/reference_docs.go Outdated Show resolved Hide resolved
tools/api-docs-generator/reference_docs.go Outdated Show resolved Hide resolved
tools/api-docs-generator/reference_docs.go Outdated Show resolved Hide resolved
tools/api-docs-generator/main.go Show resolved Hide resolved
@jgresty
Copy link
Member

jgresty commented May 16, 2024

Oh and alerting, how will we know if this fails?

@tinygrasshopper tinygrasshopper changed the title Add github action to sync api docs to the user docs site [wip] Add github action to sync api docs to the user docs site May 21, 2024
@tinygrasshopper tinygrasshopper force-pushed the chore/docs-action branch 11 times, most recently from c958691 to 43e14cb Compare May 22, 2024 10:33
@tinygrasshopper tinygrasshopper changed the title [wip] Add github action to sync api docs to the user docs site Add github action to sync api docs to the user docs site May 22, 2024
@tinygrasshopper tinygrasshopper requested a review from jgresty May 22, 2024 11:55
Copy link
Member

@jgresty jgresty left a 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?

steps:
- uses: actions/checkout@v4
with:
#TODO: Remove before merge
Copy link
Member

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
Copy link
Member

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

Copy link
Collaborator Author

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

Copy link
Member

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

?

Copy link
Member

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

Copy link
Collaborator Author

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

steps:
- uses: actions/checkout@v4
with:
#TODO: Remove before merge
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another todo

Comment on lines +1 to +14
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
Copy link
Member

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
Copy link
Member

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

Copy link
Collaborator Author

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, "", " ")
Copy link
Member

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

Copy link
Collaborator Author

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, "~") {
Copy link
Member

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

Copy link
Collaborator Author

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)
Copy link
Member

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 }}
Copy link
Member

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.

@tinygrasshopper
Copy link
Collaborator Author

tinygrasshopper commented May 22, 2024

I can see there were a lot of notes that were previously on Apiary that have been lost on the new V1 docs.

Yep, will add that feature as a followup PR

I'm still concerned what will happen if this script runs before a previous pull request is merged

The default behaviour of the PR action is to merge it into the previous PR

Copy link
Collaborator

@mikeromard mikeromard left a 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.

@tinygrasshopper tinygrasshopper merged commit e9ca07b into main May 23, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants