This repository implements the new VTEX Developers Portal with better navigability, content centralization and search facility to improve developers experience as they consult our applications documentation, guides and API references.
As the Developer Portal provides VTEX documentation to users, some of its main features are:
OpenAPI documentations rendering
The OpenAPI specification was chosen by VTEX to generate its API references guides since it defines a standard interface to describe RESTful APIs, as well as it can be easily understood, consumed and rendered by tools like ReadMe (used in the initial Developers Portal).
Markdown files rendering
Markdown is a very popular markup language that helps making plaintext documents more semantic by adding formatting elements defined in its syntax. VTEX developers and many tech writers reccur to Markdown to write documentation, including those served by the Developers Portal.
The versioning process of this repository was built to automate version releases and standardize its contributions. The following goals are currently implemented:
Standardize the repository history by adopting a commit messaging convention that makes commits more semantic
Commitlint is a tool that lints commit messages according to Conventional Commits. Conventional Commits, on the other hand, is based on the SemVer (Semantic-Versioning) standard.
Automate CHANGELOG.md
and package.json
version updates based on semantic commit messages, as well as the creation of new version tags
Standard Version provides a release script that results in a release commit containing a new version in package.json
and updates in CHANGELOG.md
, all based on the changes introduced by the latest semantic commits. It also creates a new version tag.
Automate new version releases when Pull Requests (PR) are merged into the main
branch
A GitHub action named Release Version Workflow is triggered whenever a PR is merged into the main
branch. The action's workflow is represented by the diagram below, its steps identify whether the PR should release a new version - and of what type - to run the release script, push its results and generate a new GitHub Release corresponding to the new version tag. The type of the new version may be automatically deducted from the semantic commits or determined by the user as a PATCH, MINOR or MAJOR.
flowchart TB
startState(PR is merged into main) --> setReleaseEnvVar(1. Extract release type from PR labels)
setReleaseEnvVar(Extract release type from PR labels) --If PR has 'release-auto', 'release-patch', 'release-minor' or 'release-major' label--> releaseVersionScript(Run release script)
setReleaseEnvVar(Extract release type from PR labels) --If PR has no release label--> setDefaultAutoRelease(Set default auto release)
setDefaultAutoRelease(Set default auto release) --> releaseVersionScript(Run release script)
setReleaseEnvVar(Extract release type from PR labels) --If PR has 'release-no' label--> endState(Finish workflow)
releaseVersionScript(Run release script) --> |Commit changes to CHANGELOG.md and package.json with the new version and create a new version tag| pushReleaseVersionScriptResult(Push script results to the remote repository)
pushReleaseVersionScriptResult(Push script results to the remote repository) --> createRelease(Create new GitHub Release)
createRelease(Create new GitHub Release) --> endState(Finish workflow)
Performance tests on desktop and mobile devices
Lighthouse is a tool that analyzes web apps and web pages to collect performance metrics and insights on developer best practices. To avoid significant performance drops introduced by Pull Requests, a pair of GitHub actions using Lighthouse CI are running against PRs to collect the performance metrics of the code with the proposed changes at desktop and mobile devices (a report containing the results is hosted on a URL that is availaible at the end of the actions log).
Automated tests
Cypress is an automated testing tool that was added to the repository so pre-defined E2E or unitary tests (inside cypress directory) will be executed whenever a PR is opened.
Clone this repo, access the command line at its root directory and install all dependencies:
yarn install
To start the application development server, run:
yarn dev
Open http://localhost:3000 with your browser to see the result.
The Developers Portal is a Next.js app based on React and Typescript.
The diagram below represents the base structure defined to organize the files and folders of the repository, where all file names must follow the kebab-case convention.
flowchart TB
devportal --> src & public
src --> messages & components & pages & styles & posts & utils & tests
messages --> msgJson{{messages.json}}
components --> some-component --> stylesCompCss{{styles.component.css}} & compOther{{functions/other.ts}} & compIndex{{indext.tsx}} & compStyle{{styles.ts}}
pages --> search & pagesLanding{{landing-page}} & docs
search --> searchSearchPage{{search-page}}
docs --> VTEX-IO & API & etc...
API --> apiIndex{{index}}
VTEX-IO --> vtexIoIndex{{index}}
styles --> stylesGlobal{{global.css}}
posts --> postsPost{{post.md/mdx}}
utils --> utilsChildren{{Global functions, types and constants}}
tests --> testsChildren{{tests files}}
ESLint is used to lint code and identify errors based on a pre-defined ruleset (.eslintrc.json
file)
Before any change is committed, a pre-commit hook will run the ESLint on JavaScript and TypeScript files located at pre-defined paths (such as src/pages
, src/components
etc) to fix their errors (ignored paths are described in .eslintignore
).
Prettier is used to standardize the code formatting based on a pre-defined ruleset (.prettierrc
file)
Before any change is committed, a pre-commit hook will run Prettier and correct errors found in the appropriate files (ignored paths are included in .prettierignore
).
You might want to configure ESLint and Prettier in your code editor to see errors and correction suggestions at development time.
By simplicity, we have three types of commits:
git merge <branch> --no-ff
(it is also generated when merging a Pull Request without squashing)release commits: commits using Standard Version tool
Standard Version is a tool that simplifies the versioning process of a project. It has a release script that generates a new version tag and creates a release commit containing: a new version in package.json
and updates in CHANGELOG.md
based on changes introduced by the latest commits.
git add <filenames>
Step 2. Commit your staged files:
git commit
, run the command below and follow the instructions that will appear:
yarn cz-commit
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
If there are any breaking changes introduced by your changes, follow one of the options:
- Append a `!` after `<type>[optional scope]`
Currently, we have one fixed branch: main
.
The main
branch must reflect exactly what is deployed in production, it should be treated as the single source of truth. It is from main
where every development branch is created.
Important note: Only merge commits should be made by developers on
main
branch.
You must create a branch based on main
to start a feature, improvement, or fix. This branch is called a feature branch. It must have the following structure name: <type>/<description>
Choose the type
that best summarizes your contribution at the Commit Types Table.
The feature branch description must be short and written with kebab-case. It should give a basic understanding of what is being developed on the branch.
E.g.: git checkout -b feature/landing-page
.
Important note: Only commits should be made in a feature branch. None release or merge commits should be made.
Step 1. Create a feature branch based on main
(follow the naming pattern defined at Feature Branches section).
git checkout main
git checkout -b feature/nice-new-thing
Step 2. Develop the contribution in your feature branch by making commits (see How to make a commit section).
git add <filenames>
git commit -m "feat: add nice new thing"
Step 3. Push your feature branch to the remote repository (in the following example represented by the origin alias)
git push origin feature/nice-new-thing
Step 4. Open a Pull Request (PR), select its reviewers and add it one of the release labels:
Release Labels | Description | Release Type |
---|---|---|
release-no |
When no new version should be released when the PR is merged into the main branch |
None |
release-auto |
When the new version to be released should be deducted automatically based on the PR semantic commits when it is merged | [PATCH, MINOR, MAJOR] |
release-patch |
When the new version should be released as a patch | PATCH |
release-minor |
When the new version should be released as a minor | MINOR |
release-major |
When the new version should be released as a major | MAJOR |
Important note: If none of the labels are added, a version release corresponding to
release-auto
will be triggered.
Step 5. Verify if your Pull Request passed all checks that run against opened Pull Requests. In case any of them fails, look for a solution and update your feature branch.
Important note: If your branch has been updated with new commits, you should request new reviews to your PR.
Step 6. When your PR has been approved by reviewers, make sure your feature branch is still rebased on the main
branch. If it needs to be rebased, run:
# Bring to local main branch the remote main latest updates
git checkout main
git pull origin main
# Checkout your feature branch and rebase it onto main (solve possible conflicts)
git checkout feature/new-nice-thing
git rebase main
# Force push your rebased feature branch
git push --force origin feature/new-nice-thing
Go back to Step 5.
Important note: If your rebase process generated conflicts, new reviews must be requested.
Step 7. After your PR has been rebased onto main
, passed all checks and been approved by reviewers, click on Merge Pull Request option (the one that generates a merge commit). This way all commits from the feature branch will be added to the base branch and their semantic messages will be considered to update CHANGELOG.md
when releasing a new version.
Step 8. The merged PR, if set to release a new version in Step 4, will trigger a GitHub action that results in a new commit chore(release): v*.*.*
, a new version tag and its corresponding GitHub Release (see Versioning section for more details) - you can verify those changes in the repository initial page after the workflow has finished. Wait for the build in Netlify to end and your released version will be deployed.
Step 9. Celebrate! You have just finished your contribution to the VTEX Developers Portal repository.
main
branch and I'm developing something on my feature branchMake rebase of your feature branch on main
:
# Bring to local main branch the remote main latest updates
git checkout main
git pull origin main
# Checkout your feature branch and rebase it onto main (solve possible conflicts)
git checkout feature/new-nice-thing
git rebase main
# Force push your rebased feature branch
git push --force origin feature/new-nice-thing
Important note: Always maintain your feature branch rebased on
main
.