Skip to content

Latest commit

 

History

History
85 lines (57 loc) · 4.44 KB

DEVELOPMENT.md

File metadata and controls

85 lines (57 loc) · 4.44 KB

Development Guide

This document is intended to help developers get started with the project. It will cover the repository structure, how to run the code, and how to run the tests.

Getting Started

The Action is written in Typescript and uses Yarn as a package manager. It's required to have installed Node.js and yarn on your machine.

To get started, clone the repository and run yarn to install the dependencies.

Repository Structure

The repository is structured as follows:

path description
src/ The source code of the Action
tests/ The tests of the Action
dist/ The compiled code of the Action. Don't edit files in this folder directly. It's generated by the package script from package.json
action.yml The Action configuration file. It contains the metadata, inputs, and outputs of the Action
package.json The main configuration file. It contains the dependencies, scripts, and other metadata
tsconfig.json The Typescript configuration file. It contains the compiler options
yarn.lock The lock file of the npm dependencies

Code

The source code of the Action is located in the src/ folder. It's written in TypeScript and compiled into Javascript. The compiled code is located in the dist/ folder.

The code is structured as follows:

path description
src/main.ts Entry point of the Action
src/action.ts The file containing the main action() function
src/pull-request.ts File containing Pull Request metadata and methods for interaction with Pull Requests
src/schema/ The directory that contains Zod schemas used for input parsing and input transformation

To compile the code, run yarn build. It will compile the Typescript code from the src/ folder and output the compiled code in the dist/ folder.

Important

Always make sure that your local dependencies from node_modules/ are up to date. If you have problems with the compilation, try to run yarn to update the dependencies.

Linting and Formatting

To maintain a consistent code style, we use Prettier. It uses the configuration from .prettierrc.yml and .prettierignore.

To format the code, run yarn format. It will format all TypeScript files in the src/ and tests/ folders.

Tip

You can run yarn run format-check to check if the code is formatted correctly.

We also use ESLint to lint the code. It uses the configuration from .eslintrc.json and .eslintignore.

To lint the code, run yarn lint.

Testing

The tests are located in the tests/ folder. They are written in TypeScript and use Vitest to run the tests. We don't call any API endpoints in the tests. Instead, we use mocks to simulate the API responses.

To execute the tests, run the yarn test. It will also generate a code coverage report in the coverage/ folder.

Tip

When updating tests cause a change of desired output matched by snapshots, run yarn run update-snapshots to update the snapshots.

Contributing

When contributing always make sure that your commits also contain the compiled code by running yarn run all. Because it's the dist/index.js file that is executed by GitHub Actions in the end. We have a GitHub workflow Check dist/ that checks if the compiled code is up to date with the source code.

Note

The ncc package is used to compile the code into a single file dist/index.js. It's configured in the package.json file.

Links and Resources

  • Typescript language - link
  • Yarn package manager - link
  • Vitest testing framework - link
  • Octokit - library for communication with GitHub API and many more - link
  • Actions Toolkit - library for development of JS/TS GitHub Actions - link
  • Testing Farm library - JS library for communication with Testing Farm API - link
  • Zod - library for validation of input data - link
  • Official template for GitHub Actions written in Typescript - link