Skip to content

Commit

Permalink
chore: convert project to monorepo and add coordinator service
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Jul 30, 2024
1 parent 4530300 commit 42dfe61
Show file tree
Hide file tree
Showing 282 changed files with 46,767 additions and 12,585 deletions.
8 changes: 2 additions & 6 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
node_modules
dist
.next
coverage
build
typechain-types
.eslintrc.js
commitlint.config.js
subgraph/generated
public/mockServiceWorker.js
zkeys
playwright-report
test-results
next.config.js
interface/playwright.config.ts
interface/playwright/fixtures.ts
103 changes: 7 additions & 96 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = {
extends: [
"airbnb",
"prettier",
"next/core-web-vitals",
"plugin:import/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
Expand All @@ -20,26 +19,23 @@ module.exports = {
"plugin:@typescript-eslint/stylistic",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:import/typescript",
"plugin:react/recommended",
"plugin:playwright/playwright-test",
],
plugins: ["json", "prettier", "unused-imports", "import", "@typescript-eslint", "react-hooks"],
plugins: ["json", "prettier", "unused-imports", "import", "@typescript-eslint"],
parser: "@typescript-eslint/parser",
env: {
browser: true,
node: true,
jest: true,
mocha: true,
es2022: true,
},
settings: {
react: {
version: "18",
version: "999.999.999",
},
"import/resolver": {
typescript: {},
node: {
extensions: [".ts", ".js", ".tsx", ".jsx"],
moduleDirectory: ["node_modules", "src", "playwright"],
extensions: [".ts", ".js"],
moduleDirectory: ["node_modules", "ts", "src"],
},
},
},
Expand All @@ -63,15 +59,7 @@ module.exports = {
"import/no-extraneous-dependencies": [
"error",
{
devDependencies: [
"**/*.test.ts",
"./src/test-msw.ts",
"./src/test-setup.ts",
"./src/lib/eas/*.ts",
"./playwright/**/*.ts",
"./playwright.config.ts",
"./vitest.config.ts",
],
devDependencies: ["**/*.test.ts", "**/__benchmarks__/**"],
},
],
"no-debugger": isProduction ? "error" : "off",
Expand Down Expand Up @@ -113,86 +101,9 @@ module.exports = {
"error",
{
builtinGlobals: true,
allow: [
"alert",
"location",
"event",
"history",
"name",
"status",
"Option",
"Image",
"Lock",
"test",
"expect",
"describe",
"beforeAll",
"afterAll",
],
allow: ["location", "event", "history", "name", "status", "Option", "test", "expect"],
},
],
"@typescript-eslint/restrict-template-expressions": ["error", { allowNumber: true }],

"react/jsx-filename-extension": [
"error",
{
extensions: [".tsx", ".jsx", ".js"],
},
],
"react/no-unknown-property": ["error", { ignore: ["tw", "global", "jsx"] }],
"react/jsx-sort-props": [
"error",
{
callbacksLast: true,
shorthandFirst: true,
ignoreCase: true,
reservedFirst: true,
},
],
"react/sort-prop-types": [
"error",
{
callbacksLast: true,
},
],
"react/react-in-jsx-scope": "off",
"react/jsx-boolean-value": "error",
"react/jsx-handler-names": "error",
"react/prop-types": "error",
"react/jsx-no-bind": "error",
"react-hooks/rules-of-hooks": "error",
"react/no-array-index-key": "warn",
"jsx-a11y/no-static-element-interactions": "warn",
"jsx-a11y/click-events-have-key-events": "warn",
"jsx-a11y/anchor-is-valid": "warn",
"react/jsx-props-no-spreading": "off",
"react/forbid-prop-types": "off",
"react/state-in-constructor": "off",
"react/jsx-fragments": "off",
"react/static-property-placement": ["off"],
"react/jsx-newline": ["error", { prevent: false }],
"jsx-a11y/label-has-associated-control": "off",
"jsx-a11y/label-has-for": "off",
"react/require-default-props": [
"error",
{
functions: "defaultArguments",
},
],
"react/no-unused-prop-types": "error",
"react/function-component-definition": ["error", { namedComponents: ["arrow-function"] }],

"playwright/prefer-lowercase-title": "error",
"playwright/prefer-to-be": "error",
"playwright/prefer-to-have-length": "error",
"playwright/prefer-strict-equal": "error",
"playwright/max-nested-describe": ["error", { max: 1 }],
"playwright/no-restricted-matchers": [
"error",
{
toBeFalsy: "Use `toBe(false)` instead.",
not: null,
},
],
},
};
13 changes: 13 additions & 0 deletions .github/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -ex

tasks="maci-coordinator"
for task in $tasks; do
maci_coordinator_revision=$(aws ecs describe-task-definition --task-definition $task --query "taskDefinition.revision")
aws ecs update-service --cluster maci-coordinator --service $task --force-new-deployment --task-definition $task:$maci_coordinator_revision
done

for loop in {1..3}; do
[ "$loop" -eq 3 ] && exit 1
aws ecs wait services-stable --cluster maci-coordinator --services $tasks && break || continue
done
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ jobs:
strategy:
fail-fast: false
matrix:
command: ["prettier", "types", "lint", "test"]
command: ["prettier", "types", "lint"]

runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9

- name: Use Node.js 20
uses: actions/setup-node@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9

- name: Use Node.js 20
uses: actions/setup-node@v4
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/coordinator-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Coordinator

on:
push:
branches: [main]
pull_request:

env:
COORDINATOR_RPC_URL: "http://localhost:8545"
COORDINATOR_PUBLIC_KEY_PATH: "./pub.key"
COORDINATOR_PRIVATE_KEY_PATH: "./priv.key"
COORDINATOR_TALLY_ZKEY_NAME: "TallyVotes_10-1-2_test"
COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME: "ProcessMessages_10-2-1-2_test"
COORDINATOR_ZKEY_PATH: "./zkeys/"
COORDINATOR_RAPIDSNARK_EXE: "~/rapidsnark/build/prover"
SUBGRAPH_FOLDER: "../subgraph"
SUBGRAPH_NAME: ${{ vars.SUBGRAPH_NAME }}
SUBGRAPH_PROVIDER_URL: ${{ vars.SUBGRAPH_PROVIDER_URL }}
SUBGRAPH_DEPLOY_KEY: ${{ secrets.SUBGRAPH_DEPLOY_KEY }}

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9

- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install --yes \
build-essential \
libgmp-dev \
libsodium-dev \
nasm \
nlohmann-json3-dev
- name: Install
run: |
pnpm install --frozen-lockfile --prefer-offline
- name: Build
run: |
pnpm run build
- name: Run hardhat
run: |
pnpm run hardhat &
sleep 5
working-directory: packages/coordinator

- name: Download rapidsnark (1c137)
run: |
mkdir -p ~/rapidsnark/build
wget -qO ~/rapidsnark/build/prover https://maci-devops-zkeys.s3.ap-northeast-2.amazonaws.com/rapidsnark-linux-amd64-1c137
chmod +x ~/rapidsnark/build/prover
- name: Download circom Binary v2.1.6
run: |
wget -qO ${{ github.workspace }}/circom https://github.com/iden3/circom/releases/download/v2.1.6/circom-linux-amd64
chmod +x ${{ github.workspace }}/circom
sudo mv ${{ github.workspace }}/circom /bin/circom
- name: Download zkeys
run: |
pnpm download-zkeys-coordinator:test
- name: Generate keypair
run: |
pnpm generate-keypair
working-directory: packages/coordinator

- name: Test
run: pnpm run test
working-directory: packages/coordinator
37 changes: 37 additions & 0 deletions .github/workflows/coordinator-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CoordinatorDeploy
on:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
deploy:
runs-on: ubuntu-22.04
permissions:
id-token: write
contents: read

steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::490752553772:role/maci-coordinator-ecs-deploy-slc
role-duration-seconds: 2700
aws-region: eu-central-1

- name: Build and Push images to ECR
run: |
.github/scripts/build.sh ${{ secrets.COORDINATOR_RPC_URL }} ${{ secrets.COORDINATOR_ADDRESSES }} ${{ secrets.COORDINATOR_ALLOWED_ORIGINS }}
- name: Create Deployment
run: |
.github/scripts/deploy.sh
5 changes: 4 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9

- name: Use Node.js 20
uses: actions/setup-node@v4
Expand Down Expand Up @@ -96,14 +96,17 @@ jobs:
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: |-
pnpm run install:chromium
working-directory: packages/interface

- name: Build
run: pnpm run build
working-directory: packages/interface

- name: Run Playwright tests
uses: coactions/setup-xvfb@6b00cf1889f4e1d5a48635647013c0508128ee1a
with:
run: pnpm run test:e2e
working-directory: packages/interface

- uses: actions/upload-artifact@v4
if: always()
Expand Down
16 changes: 8 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
node_modules
.pnp
.pnp.js

# testing
/coverage
/playwright-report
/test-results
coverage
playwright-report
test-results

# next.js
/.next/
/out/
.next/
out/
next-env.d.ts

# production
/build
build

# misc
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pnpm exec lint-staged && pnpm run types
pnpm lint && pnpm run types
Loading

0 comments on commit 42dfe61

Please sign in to comment.