Skip to content

Commit

Permalink
Add pre-commit support
Browse files Browse the repository at this point in the history
  • Loading branch information
alnoki committed Apr 11, 2024
1 parent 388bae0 commit 37bf226
Show file tree
Hide file tree
Showing 29 changed files with 1,522 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- markdownlint-disable-file MD025 -->

# Description

Delete this line and add a description that explains what changes you have done
and why they were necessary.

# Testing

Delete this line and provide a description of how to test the changes in this
PR.

# Checklist

- [ ] Did you update relevant documentation?
- [ ] Did you add tests to cover new code or a fixed issue?
- [ ] Did you update the changelog?
- [ ] Did you check off all checkboxes from the linked Linear task? (Ignore if
you are not a member of Econia Labs)

> If a task does not apply to your PR, strike it through and mark it complete:
```md
- [x] ~Did you update the changelog?~
```
30 changes: 30 additions & 0 deletions .github/workflows/close-stale-issues.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
jobs:
stale:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/stale@v9'
with:
days-before-close: '15'
days-before-stale: '45'
delete-branch: 'true'
exempt-issue-labels: 'stale-exempt'
exempt-pr-labels: 'stale-exempt'
operations-per-run: '50' # This is to avoid Github API rate limiting.
stale-issue-message: >
This issue is stale because it has been open 45 days with no activity.
Remove the `stale` label or comment -
otherwise this will be closed in 15 days.
stale-pr-message: >
This issue is stale because it has been open 45 days with no activity.
Remove the `stale` label, comment or push a commit -
otherwise this will be closed in 15 days.
name: 'Close stale issues and PRs'
'on':
schedule:
- cron: '0 0 * * *' # Cron scheduler syntax.
permissions:
contents: 'write'
issues: 'write'
pull-requests: 'write'
...
46 changes: 46 additions & 0 deletions .github/workflows/link-checker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# cspell:words lycheeverse, micalevisk
---
jobs:
linkChecker:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v3'
- env:
GITHUB_TOKEN: '${{secrets.GITHUB_TOKEN}}'
id: 'lychee'
name: 'Link Checker'
uses: 'lycheeverse/lychee-action@v1'
- id: 'last-issue'
name: 'Find the last open report issue'
uses: 'micalevisk/last-issue-action@v2'
with:
labels: |
report
automated issue
link checker
state: 'open'
- if: >-
steps.last-issue.outputs.has-found == 'true' ||
env.lychee_exit_code != '0'
name: 'Update last updated report issue'
uses: 'peter-evans/create-issue-from-file@v5'
with:
assignees: 'xbtmatt'
content-filepath: './lychee/out.md'
# Update an existing issue if one was found (issue-number),
# otherwise an empty value creates a new issue.
issue-number: '${{ steps.last-issue.outputs.issue-number }}'
labels: |
report
automated issue
link checker
title: 'Link Checker Report'
name: 'Link Checker'
'on':
schedule:
- cron: '0 0 * * *'
workflow_dispatch: null
permissions:
issues: 'write'
pull-requests: 'write'
...
51 changes: 51 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# cspell:words snok, virtualenvs, pydeps, venv, Pylint, pylint
---
env:
POETRY_VERSION: '1.8.2'
PYTHON_VERSION: '3.9'
jobs:
pre-commit:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v3'
- uses: 'actions/setup-python@v3'
with:
python-version: '${{ env.PYTHON_VERSION }}'
- name: 'Cache Poetry Install'
uses: 'actions/cache@v3'
with:
key: 'poetry-${{ env.POETRY_VERSION }}'
path: '${{ runner.home }}/.local/src/python/hooks'
- name: 'Install Poetry'
uses: 'snok/[email protected]'
with:
installer-parallel: true
version: '${{ env.POETRY_VERSION }}'
virtualenvs-create: true
virtualenvs-in-project: true
- id: 'restore-deps'
uses: 'actions/cache/restore@v3'
with:
key: |
pydeps-${{ hashFiles('./src/python/hooks/poetry.lock') }}
path: './src/python/hooks/.venv'
- if: |
steps.restore-deps.outputs.cache-hit != 'true'
name: 'Install Dependencies'
run: |
cd ./src/python/hooks
poetry install --no-interaction --no-root
- id: 'save-deps'
uses: 'actions/cache/save@v3'
with:
key: |
pydeps-${{ hashFiles('./src/python/hooks/poetry.lock') }}
path: './src/python/hooks/.venv'
- uses: 'pre-commit/[email protected]'
with:
extra_args: '--all-files --config cfg/pre-commit-config.yaml --verbose'
name: 'pre-commit'
'on':
pull_request: null
workflow_dispatch: null
...
124 changes: 124 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!--- cspell:words wxyz -->

# Contribution Guidelines

The key words `MUST`, `MUST NOT`, `REQUIRED`, `SHALL`, `SHALL NOT`, `SHOULD`,
`SHOULD NOT`, `RECOMMENDED`, `MAY`, and `OPTIONAL` in this document are to be
interpreted as described in [RFC 2119].

These keywords `SHALL` be in `monospace` for ease of identification.

## Continuous integration and development

### `pre-commit`

This repository uses [`pre-commit`]. If you add a new filetype, you `SHOULD` add
a new [hook][pre-commit hook]. See [adding new hooks] for additional info.

In the `cfg/` directory are all of the `pre-commit` configuration files for
various hooks.

To set up your local workspace to use `pre-commit` or change any of the hook
configurations, please see the [pre-commit configuration README].

If you'd like to run our Python formatter locally to pass `pre-commit` checks,
you can [run our Python format script].

### GitHub actions

This repository uses [GitHub actions] to perform assorted status checks. If you
submit a pull request but do not [run `pre-commit`] then your pull request might
get blocked.

## Pull requests

This repository handles pull requests (PRs) using the [squash and merge method].

The Econia Labs team uses [Linear] for project management, such that PRs titles
start with tags of the form `[ECO-WXYZ]`. All PRs `MUST` include a tag, so if
you are submitting a PR as a community contributor, an Econia Labs member
`SHALL` change your PR title to include an auto-generated tag for internal
tracking purposes.

Pull requests `MUST` include a description written using imperative form that
"tells the repository what to do".

Pull request titles `MUST` also use imperative form, with the first letter after
the tag capitalized. For example `[ECO-WXYZ] Update something in the repo`.

Commit titles `SHOULD` use a similar format, but without a leading tag.

Resolution of a review comment `SHALL` be reserved for the reviewer who made the
comment, except for the case of suggestion acceptance, which automatically
results in the comment being marked as resolved.

## Move design phases

### Preliminary

1. During preliminary design phases, design `SHALL` emphasize abstraction and
ease of testing, with optimizations in mind, for example, to reduce borrows.
1. Asserts `SHALL` be wrapped in helper functions to reduce failure tests.
1. Inlining `SHALL` only be used for functions that pass up a reference to a
borrow out of global storage.

### Optimization

1. Function call paths `SHALL` be analyzed to minimize bytecode instructions in
key operations of placing/cancelling limit orders, and swapping.

## Style

### General

1. Incorrect comments are worse than no comments.
1. Minimize maintainability dependencies.
1. Prefer compact code blocks, delimited by section comments rather than
whitespace.
1. Titles `SHALL` use `Title Case` while headers `SHALL` use `Sentence case`.
1. Comments `SHALL` start with a capital letter and end with a period `.`, even
if they are a single line.

### Markdown

1. [Reference links] are `REQUIRED` where possible, for readability and for ease
of linting.
1. LaTeX display equations `SHALL` be delimited via a `math` fenced code block
(note that you can render these locally using the `gitlab` delimiter for the
[VS Code Markdown+Math extension]).

### Move

1. [Reference][move references] variable names `MUST` end in either `_ref` or
`_ref_mut`, depending on mutability, unless they refer to
[signers][move signer].
1. [Doc comments] `MUST` use Markdown syntax.
1. Variable names `SHOULD` be descriptive, with minor exceptions for scenarios
like math utility functions.
1. Error code names `MUST` start with `E_`, for example `E_NOT_ENOUGH_BASE`.
1. Where possible, functions of the form `ensure_property_x()`, which ensure
that some property holds, `SHALL` be favored over functions of the form
`assert_property_x()`, which abort if a property does not hold.
1. Until a formatter or linter is available, lines `SHALL` break at 100
characters per the [Move formatting guidelines][move format].
1. Events `SHALL` be titled in the form `Something`, as opposed to
`SomethingEvent`, and `SHALL` be emitted v2-style, consistent with
the [Aptos Framework v2 event refactors].

[adding new hooks]: ./cfg/README.md#adding-new-hooks
[aptos framework v2 event refactors]: https://github.com/aptos-foundation/AIPs/issues/367
[doc comments]: https://move-language.github.io/move/coding-conventions.html?#comments
[github actions]: https://docs.github.com/en/actions
[linear]: https://pre-commit.com/hooks.html
[move format]: https://move-language.github.io/move/coding-conventions.html#formatting
[move references]: https://move-language.github.io/move/references.html
[move signer]: https://move-language.github.io/move/signer.html
[pre-commit configuration readme]: ./cfg/README.md#running-pre-commit-hooks-locally
[pre-commit hook]: https://pre-commit.com/hooks.html
[reference links]: https://mdformat.readthedocs.io/en/stable/users/style.html#reference-links
[rfc 2119]: https://www.ietf.org/rfc/rfc2119.txt
[run our python format script]: ./src/python/hooks/README.md#run-our-formatting-script
[run `pre-commit`]: #pre-commit
[squash and merge method]: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/about-merge-methods-on-github
[vs code markdown+math extension]: https://marketplace.visualstudio.com/items?itemName=goessner.mdmath
[`pre-commit`]: https://github.com/pre-commit/pre-commit
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Emojicoin dot fun

[![pre-commit shield]][pre-commit repo]

[pre-commit repo]: https://github.com/pre-commit/pre-commit
[pre-commit shield]: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit
96 changes: 96 additions & 0 deletions cfg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Overview

This directory contains all of the configuration files for the various
`pre-commit` hooks, linters, formatters, and workspace actions that this
repository uses.

This repository uses [`pre-commit`] hooks to perform various formatter and
linter verifications upon PR submission. In order to merge a PR, all hooks
must complete successfully.

## Adding new hooks

If you need to add a new hook to the list of `pre-commit` hooks, you can do so
by adding it into the `pre-commit-config.yaml` configuration file.

You can add a new hook either by [adding an existing plugin] or [creating a new
custom hook entirely][creating a new custom hook entirely].

## Running `pre-commit` hooks locally

To avoid your PR contributions failing the CI pipeline checks, you can install
the `pre-commit` hooks locally so that they automatically run right before you
add a new commit.

### Installing the required tools

To properly install the full `pre-commit` environment for this repository,
you'll need the following command-line tools:

- `git`, `python`, and `pip` (if you're not using `brew`)
- `poetry` and `pre-commit`

You can install all of these tools with your preferred package manager.
If you have `python` and `pip` installed already, you might use:

- `pip install poetry`
- `pip install pre-commit`

If you use `brew` on MacOS:

- `brew install poetry`
- `brew install pre-commit`

### Installing the `poetry` and `pre-commit` environments

You'll also need to set up your `poetry` and `pre-commit` environments for this
repository:

First ensure you're in the `emojicoin-dot-fun` repository at the root directory.
If you haven't cloned it yet, this might look something like:

```shell
git clone https://github.com/econia-labs/emojicoin-dot-fun
cd emojicoin-dot-fun
```

Then install the Python hooks `poetry` dependencies:

```shell
poetry install -C src/python/hooks --no-root
```

To install `pre-commit` to run prior to every time you `git commit ...` when
relevant files change:

```shell
pre-commit install --config cfg/pre-commit-config.yaml
```

Or you can run the hooks manually yourself against all files:

```shell
pre-commit run --all-files --config cfg/pre-commit-config.yaml
```

If you'd like to bypass `pre-commit` hooks for any reason once you've installed
our `pre-commit` hooks with `pre-commit-config.yaml`, you can bypass the checks
with:

```shell
git commit -m "Some change pre-commit hooks..." --no-verify
```

Note that this will allow you to push your commit onto your branch even if it
fails the `pre-commit` checks, but will likely fail in CI when it runs its
own `pre-commit` checks.

## Running the Python formatters

If you'd like to automate the Python formatting and linting as much as possible,
you can [run our Python format script].

[adding an existing plugin]: https://pre-commit.com/#plugins
[creating a new custom hook entirely]: https://pre-commit.com/#new-hooks
[run our python format script]: ../src/python/hooks/README.md#run-our-formatting-script
[`pre-commit`]: https://pre-commit.com
Loading

0 comments on commit 37bf226

Please sign in to comment.