-
Notifications
You must be signed in to change notification settings - Fork 10
Design: Automated Headless api-docs upload #56
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aaf00e9
docs: headless api docs on CI
tuliomir 9d4de6e
chore: cleanup and rewording
tuliomir a336ca7
chore: property removal note
tuliomir a6d072b
chore: lessens restriction on workflow running
tuliomir 42b803d
chore: deployment only for release versions
tuliomir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Summary | ||
| This feature automates the process of uploading the updated API Docs for the Headless Wallet, while giving the developer a preview of the contents, error checking and linting. | ||
|
|
||
| A script is made available for the developer to make all the necessary checks locally and a GitHub Workflow is implemented to: | ||
| - Validate and lint the `api-docs.js` file on every PR to the `dev` branch | ||
| - Deploy the updated docs on every new successful release | ||
|
|
||
| # Motivation | ||
| Currently this upload is made manually by a team member, extracting data from the `src/api-docs.js` file and processing it to finally upload its contents to the [Headless Hathor Wallet API](https://wallet-headless.docs.hathor.network/) site. | ||
|
|
||
| # Guide-level explanation | ||
| ### JS to JSON conversion | ||
| The platform that manages the OpenAPI Documentation static website, [Redoc](https://github.com/Redocly/redoc), only interacts with `.json` files. So we need to convert our `src/api-docs.js` file into a `.json` one whenever we want to use this platform. | ||
|
|
||
| A script should be built to make this conversion on the `scripts` folder, that implements the following: | ||
| - Ensures the `default` property normally exported by the `JSON.stringify()` is not present on the output json | ||
| - Outputs the results to the `tmp/api-docs.json` folder. | ||
|
|
||
| This script will be referred to as `scripts/convert-docs.js` from now on. | ||
|
|
||
| > *Note*: The `securitySchemes` from the `components` property is no longer necessary and can be removed from the `js` file when this is implemented. | ||
|
|
||
| ### Linting and Preview | ||
| A developer should be able to run a `npm run docs` command with three outcomes: | ||
| - A validation check should be executed on the generated docs, alerting any errors found | ||
| - A lint should be executed on the generated docs, displaying its analysis results | ||
| - A local server should be fired, allowing the developer to visualize the results of the doc changes | ||
|
|
||
| This would be an automated version of manually executing the following commands: | ||
| ```sh | ||
| # Validation and conversion | ||
| node ./scripts/convert-docs.js | ||
|
|
||
| # Linting | ||
| npx @redocly/cli lint tmp/api-docs.json | ||
|
|
||
| # Local server for validating | ||
| npx @redocly/cli preview-docs tmp/api-docs.json | ||
| xdg-open http://127.0.0.1:8080 | ||
|
pedroferreira1 marked this conversation as resolved.
|
||
|
|
||
| # Cleanup after the server is closed | ||
| rm tmp/api-docs.json | ||
| ``` | ||
|
|
||
| > *Note:* The linter throws some errors on our current documentation. The first implementation of this script will certainly require a refactoring PR. | ||
|
|
||
| ### PR Validation | ||
| A GitHub Workflow, configured to run on every PR, should run the conversion script and linter to check for errors on the generated documentation. This should be part of the CI process. | ||
|
|
||
| ### Deployment | ||
| On the deployment pipeline, namely when there is a new `v*` label on the `master` branch, a new workflow should also upload the generated `json` file to the production documentation S3 bucket. This will update the website to the community. | ||
|
pedroferreira1 marked this conversation as resolved.
Outdated
|
||
|
|
||
| > *Note:* All connection data with the S3 should be implemented as secrets. Refer to the [`docker.yml`](https://github.com/HathorNetwork/hathor-wallet-headless/blob/master/.github/workflows/docker.yml) file for reference. | ||
|
|
||
| # Task breakdown | ||
|
|
||
| ### Milestone: Developer feedback - 0.5 dev days | ||
| - Write the conversion script - 0.2 dev days | ||
| - Implement the local validation environment - 0.3 dev days | ||
| - Write the `shell` command to convert and lint the api docs | ||
| - Also start the local server for manual conference. | ||
| - Associate it with the `docs` script on `package.json` | ||
| - Merge this on the `dev` branch | ||
|
|
||
| ### Milestone: CI workflow - 0.5 dev days | ||
| - Implement a workflow for validating and lint checking when merging to `dev` - 0.1 dev days | ||
| - Implement a workflow to deploy when making a new release - 0.1 dev days | ||
| - Test these new workflows on PR merges and releases - 0.3 dev days | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe we should make sure to remove the
tmp/api-docs.jsonfile at the end of the process.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 see no negative consequence of having this file lingering at the
tmpfolder:preview-docscommandHowever I think it's a good practice to remove the tmp files if we have no explicit reason to keep it. 👍
Changed it on 9d4de6e