Skip to content

Commit

Permalink
OS-593: refactors repo for linting and linting during workflows (#8)
Browse files Browse the repository at this point in the history
* ci: add linting and fix package manager warnings

* docs: improved pr template

* ci: rename job

* ci: improve commands and workflows

* ci: fix commands

* style: formatting

* build: improved gitignore

* style(OS-593): improves eslint config

Moves linting to the root of the repository and extends this config for
each package

* ci(OS-593): improves linting and testing for subgraph

reconfigures formatting-linting to be callable by other workflows

* ci(OS-593): fix missing dependency installation

fixes missing dependency installation for subgraph during linting

* chore(OS-593): adds missing peerDependecies in subgraph

---------

Co-authored-by: Mathias Scherer <[email protected]>
  • Loading branch information
heueristik and mathewmeconry authored Oct 19, 2023
1 parent 0cf95e5 commit e446956
Show file tree
Hide file tree
Showing 19 changed files with 1,456 additions and 126 deletions.
27 changes: 27 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
root: true
extends:
- 'eslint:recommended'
- 'plugin:@typescript-eslint/eslint-recommended'
- 'plugin:@typescript-eslint/recommended'
- 'prettier'
plugins:
- '@typescript-eslint'
rules:
'@typescript-eslint/no-floating-promises':
- error
- ignoreIIFE: true
ignoreVoid: true
'@typescript-eslint/no-inferrable-types': 'off'
'@typescript-eslint/no-explicit-any': 'off'
'@typescript-eslint/no-unused-vars':
- error
- argsIgnorePattern: '_'
varsIgnorePattern: '_'

ignorePatterns:
- '*.log'
- '*.env'
- '.env'
- '.DS_Store'
- .pnp.*
- 'node_modules'
17 changes: 9 additions & 8 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ about: Create a bug report to help us
title: 'Bug: <add-text-here>'
labels: bug
assignees: ''

---

**Describe the bug**
A short summary of what the bug is. Please be clear and concise.

**To Reproduce (please complete the following information)**

- Config and flags: [e.g. variable="xyz"]
- Steps to reproduce the behavior:
1. node '...'
2. make request with '....'
3. '...'
4. See error
1. node '...'
2. make request with '....'
3. '...'
4. See error

**Current behavior**
In depth explanation, if required, or a clear and concise description of what actually happens.
Expand All @@ -25,9 +25,10 @@ In depth explanation, if required, or a clear and concise description of what ac
A clear and concise description of what you expected to happen.

**System (please complete the following information):**
- OS: [e.g. Fedora 35]
- Software version [e.g. Docker 8, Node 14.19.1]
- Commit hash [e.g. e84617d]

- OS: [e.g. Fedora 35]
- Software version [e.g. Docker 8, Node 14.19.1]
- Commit hash [e.g. e84617d]

**Additional context**
Add any other context about the problem here.
11 changes: 3 additions & 8 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

Please include a summary of the change and be sure you follow the contributions rules we do provide [here](./CONTRIBUTIONS.md)

Task: [ID]()
Task ID: [OS-?](https://aragonassociation.atlassian.net/browse/OS-?)

## Type of change

<!--- Please delete options that are not relevant. -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
<!--- Use the https://www.conventionalcommits.org to name this PR and its commits.-->
<!--- Consider using https://commitizen.github.io/cz-cli/ for this purpose.-->

## Checklist:

Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/formatting-linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'formatting & linting'

on:
workflow_dispatch:
workflow_call:

jobs:
checks:
runs-on: 'ubuntu-latest'
steps:
- name: 'Check out the repo'
uses: 'actions/checkout@v3'

- name: 'Install Node.js'
uses: 'actions/setup-node@v3'
with:
cache: 'yarn'
node-version: 18

- name: 'Install the dependencies'
run: 'yarn install'

- name: 'Install subgraph dependencies'
run: 'cd subgraph/ && yarn install'

- name: 'Lint subgraph'
run: 'yarn lint:subgraph:ts >> $GITHUB_STEP_SUMMARY'

- name: 'Check code formatting'
run: yarn prettier:check
8 changes: 5 additions & 3 deletions .github/workflows/subgraph-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Subgraph Tests
name: Subgraph
on:
push:
paths:
Expand All @@ -9,7 +9,9 @@ env:
working-directory: subgraph

jobs:
test:
formatting-linting:
uses: ./.github/workflows/formatting-linting.yml
tests:
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -23,4 +25,4 @@ jobs:
- name: Install dependencies
run: yarn install --pure-lockfile
- name: Run Tests
run: yarn run test
run: yarn run coverage >> $GITHUB_STEP_SUMMARY
10 changes: 9 additions & 1 deletion subgraph/.gitignore → .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# dependencies
node_modules

# secrets
.env

# testing
coverage
.coverage_artifacts
.coverage_cache
.coverage_contracts

# production
artifacts
build
cache
dist
dist-ssr
*.local
Expand All @@ -26,5 +34,5 @@ yarn-error.log*
# generated
generated
.bin

coverage.json
.latest.json
27 changes: 27 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# directories
.coverage_artifacts
.coverage_cache
.coverage_contracts
artifacts
build
cache
coverage
deployments
dist
node_modules
typechain
types
imported
generated
*/js-client/test/integration/*.test.ts

# files
*.env
*.log
.DS_Store
.pnp.*
coverage.json
package-lock.json
pnpm-lock.yaml
yarn.lock
extended-schema.ts
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@aragon/osx-commons-repo",
"license": "AGPL-3.0-or-later",
"private": true,
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.44.0",
"@types/node": "^18.7.15",
"eslint": "^8.51.0",
"eslint-config-prettier": "^8.8.0",
"prettier": "^2.4.1",
"prettier-plugin-solidity": "^1.1.1",
"typescript": "^4.9.5"
},
"scripts": {
"lint": "yarn run lint:subgraph:ts",
"lint:subgraph:ts": "eslint --ext .js,.ts ./subgraph/",
"prettier:check": "prettier --check \"**/*.{js,json,md,sol,ts,yml}\"",
"prettier:write": "prettier --write \"**/*.{js,json,md,sol,ts,yml}\""
}
}
9 changes: 9 additions & 0 deletions subgraph/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parser: '@typescript-eslint/parser'
parserOptions:
project: './subgraph/tsconfig.json'

# Custom eslint settings for the subgraph can be defined here
ignorePatterns:
- imported/
- generated/
- tests/
19 changes: 11 additions & 8 deletions subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@
"private": false,
"repository": {
"type": "git",
"url": "git+https://github.com/aragon/osx.git"
"url": "git+https://github.com/aragon/osx-commons.git"
},
"author": "",
"license": "AGPL-3.0-or-later",
"bugs": {
"url": "https://github.com/aragon/osx/issues"
"url": "https://github.com/aragon/osx-commons/issues"
},
"homepage": "https://github.com/aragon/osx#readme",
"homepage": "https://github.com/aragon/osx-commons#readme",
"scripts": {
"test": "graph test",
"lint": "prettier --write ./**/*.ts"
"test:fast": "graph test",
"test": "graph test -r",
"coverage": "graph test -c",
"lint": "cd ../ && yarn run lint:subgraph:ts",
"clean": "rimraf deploy-output.txt ./build ./imported ./generated ./tests/.bin tests/.latest.json"
},
"dependencies": {
"@graphprotocol/graph-ts": "0.31.0"
},
"devDependencies": {
"matchstick-as": "0.5.2",
"@graphprotocol/graph-cli": "0.56.0",
"@types/node": "^18.7.15",
"typescript": "^4.9.5"
"@types/node": "^20.8.7",
"matchstick-as": "0.5.2",
"typescript": "^5.2.2"
}
}
6 changes: 3 additions & 3 deletions subgraph/src/ids/permissions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Address, Bytes} from '@graphprotocol/graph-ts';
import {PERMISSION_OPERATIONS} from '../utils/constants';
import {Address, Bytes} from '@graphprotocol/graph-ts';

/**
* Generates a unique permission ID using the given parameters.
Expand All @@ -20,7 +20,7 @@ export function generatePermissionEntityId(
emittingContract.toHexString(),
permissionId.toHexString(),
where.toHexString(),
who.toHexString()
who.toHexString(),
];
return ids.join('_');
}
Expand Down Expand Up @@ -48,7 +48,7 @@ export function generatePluginPermissionEntityId(
operationId,
where.toHexString(),
who.toHexString(),
permissionId.toHexString()
permissionId.toHexString(),
];

return ids.join('_');
Expand Down
9 changes: 5 additions & 4 deletions subgraph/src/ids/pluginRepo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {PERMISSION_OPERATIONS} from '../utils/constants';
import {
Address,
ByteArray,
Bytes,
crypto,
ethereum
ethereum,
} from '@graphprotocol/graph-ts';

/**
Expand Down Expand Up @@ -37,11 +38,11 @@ export function generatePluginInstallationEntityId(
dao: Address,
plugin: Address
): string | null {
let installationIdTuple = new ethereum.Tuple();
const installationIdTuple = new ethereum.Tuple();
installationIdTuple.push(ethereum.Value.fromAddress(dao));
installationIdTuple.push(ethereum.Value.fromAddress(plugin));

let installationIdTupleEncoded = ethereum.encode(
const installationIdTupleEncoded = ethereum.encode(
ethereum.Value.fromTuple(installationIdTuple)
);

Expand Down Expand Up @@ -104,7 +105,7 @@ export function generatePluginVersionEntityId(
const ids = [
generatePluginRepoEntityId(pluginRepo),
release.toString(),
build.toString()
build.toString(),
];
return ids.join('_');
}
10 changes: 2 additions & 8 deletions subgraph/tests/ids/dao.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import {Address} from '@graphprotocol/graph-ts';
import {generateDaoEntityId} from '../../src';
import {
afterAll,
assert,
beforeAll,
describe,
test
} from 'matchstick-as/assembly/index';
import {ADDRESS_ONE} from '../constants';
import {Address} from '@graphprotocol/graph-ts';
import {assert, describe, test} from 'matchstick-as/assembly/index';

// Tests structure (matchstick-as >=0.5.0)
// https://thegraph.com/docs/en/developer/matchstick/#tests-structure-0-5-0
Expand Down
10 changes: 5 additions & 5 deletions subgraph/tests/ids/permissions.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {Address, Bytes} from '@graphprotocol/graph-ts';
import {
generatePermissionEntityId,
generatePluginPermissionEntityId,
generatePluginPreparationEntityId
generatePluginPreparationEntityId,
} from '../../src';
import {assert, describe, test} from 'matchstick-as/assembly/index';
import {PERMISSION_OPERATIONS} from '../../src/utils/constants';
import {
ADDRESS_ZERO,
ADDRESS_ONE,
ADDRESS_TWO,
DUMMY_BYTES32_HEX
DUMMY_BYTES32_HEX,
} from '../constants';
import {PERMISSION_OPERATIONS} from '../../src/utils/constants';
import {Address, Bytes} from '@graphprotocol/graph-ts';
import {assert, describe, test} from 'matchstick-as/assembly/index';

// Tests structure (matchstick-as >=0.5.0)
// https://thegraph.com/docs/en/developer/matchstick/#tests-structure-0-5-0
Expand Down
13 changes: 4 additions & 9 deletions subgraph/tests/ids/pluginRepo.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import {Address, Bytes, crypto} from '@graphprotocol/graph-ts';
import {assert, describe, log, test} from 'matchstick-as/assembly/index';
import {
generatePluginRepoEntityId,
generatePluginSetupEntityId,
generatePluginInstallationEntityId,
generatePluginPreparationEntityId,
generatePluginReleaseEntityId,
generatePluginVersionEntityId,
generatePluginPermissionEntityId
generatePluginPermissionEntityId,
} from '../../src';
import {
ADDRESS_ONE,
ADDRESS_TWO,
DUMMY_BYTES32_HEX,
DUMMY_INSTALLATION_ID
} from '../constants';
import {PERMISSION_OPERATIONS} from '../../src/utils/constants';
import {ADDRESS_ONE, ADDRESS_TWO, DUMMY_BYTES32_HEX} from '../constants';
import {Address, Bytes, crypto} from '@graphprotocol/graph-ts';
import {assert, describe, test} from 'matchstick-as/assembly/index';

describe('PluginRepo ID generation', () => {
test('`generatePluginRepoEntityId` should return the hexadecimal representation of the provided address', () => {
Expand Down
1 change: 0 additions & 1 deletion subgraph/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "./node_modules/assemblyscript/std/assembly.json",
"include": ["index.ts"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit e446956

Please sign in to comment.