Skip to content

Commit

Permalink
Merge pull request #34 from Hats-Protocol/github-actions
Browse files Browse the repository at this point in the history
Automated tests and bundling
  • Loading branch information
gershido authored Jan 17, 2024
2 parents 07b744e + f567977 commit 5d82fc4
Show file tree
Hide file tree
Showing 20 changed files with 522 additions and 313 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/bundle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "Bundle"

on:
workflow_dispatch:
push:
branches:
- main
paths:
- "modules/*.json"
- "infra/*.json"

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18.16.1
- name: Set up foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Install
run: yarn install --frozen-lockfile
- name: Bundle
run: |
yarn bundle
yarn format-bundle
git config user.name github-actions
git config user.email [email protected]
git add .
git commit -m "automated bundle"
git push
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "Test"

on: [pull_request]

env:
GOERLI_RPC: https://goerli.infura.io/v3/${{ secrets.INFURA_KEY }}
SEPOLIA_RPC: https://sepolia.infura.io/v3/${{ secrets.INFURA_KEY }}
MAINNET_RPC: https://mainnet.infura.io/v3/${{ secrets.INFURA_KEY }}
POLYGON_RPC: https://polygon-mainnet.infura.io/v3/${{ secrets.INFURA_KEY }}
OPTIMISM_RPC: https://optimism-mainnet.infura.io/v3/${{ secrets.INFURA_KEY }}
ARBITRUM_RPC: https://arbitrum-mainnet.infura.io/v3/${{ secrets.INFURA_KEY }}
GNOSIS_RPC: https://gnosis.publicnode.com
BASE_RPC: https://base.publicnode.com
PGN_RPC: https://rpc.publicgoods.network
CELO_RPC: https://forno.celo.org
ETHERSCAN_KEY: ${{ secrets.ETHERSCAN_KEY }}

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18.16.1
- name: Set up foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Install
run: yarn install --frozen-lockfile
- name: Check Format
run: yarn prettier . --check
- name: Test
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: yarn test
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,7 @@ Following the [example JSON](#module-registry-schema) and existing modules, fill

Keep in mind that much of the metadata will be seen by end users in apps that use the registry, so make sure to be clear and concise.

### Step 2 - Bundle

Consumers of the modules registry do so from a single bundle, so new modules — or changes to existing modules — need to be added to the bundle.
### Step 2 - Test

Install dependencies:

Expand All @@ -235,24 +233,16 @@ yarn install

Then run:

```bash
yarn bundle
```

### Step 3 - Test

Run:

```bash
yarn test
```

### Step 4 - Format
### Step 3 - Format

Run:

```bash
yarn prettier
yarn format-all
```

י
30 changes: 30 additions & 0 deletions bundler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as fs from "fs";

export function bundleModules() {
const factoryBuffer = fs.readFileSync("./infra/factory.json");
const factory = JSON.parse(factoryBuffer.toString());

const eligibilitiesChainBuffer = fs.readFileSync(
"./infra/eligibilitiesChain.json",
);
const eligibilitiesChain = JSON.parse(eligibilitiesChainBuffer.toString());

const togglesChainBuffer = fs.readFileSync("./infra/togglesChain.json");
const togglesChain = JSON.parse(togglesChainBuffer.toString());

let moduleFiles = fs.readdirSync("modules");
const modules = [];
for (let i = 0; i < moduleFiles.length; i++) {
const moduleFile = moduleFiles[i];
const moduleBuffer = fs.readFileSync(`./modules/${moduleFile}`);
const module = JSON.parse(moduleBuffer.toString());
modules.push(module);
}

return {
factory,
eligibilitiesChain,
togglesChain,
modules,
};
}
37 changes: 0 additions & 37 deletions merger.mjs

This file was deleted.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@
"version": "0.1.0",
"author": "Haberdasher Labs",
"license": "MIT",
"type": "module",
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules yarn exec jest -- -i",
"bundle": "node merger.mjs",
"prettier": "prettier --write ."
"bundle": "tsx ./publish.ts",
"format-all": "prettier --write .",
"format-bundle": "prettier --write modules.json"
},
"devDependencies": {
"@hatsprotocol/modules-sdk": "^0.14.1",
"@types/jest": "^29.5.4",
"@viem/anvil": "^0.0.6",
"@viem/anvil": "0.0.5",
"async-sema": "^3.1.1",
"axios": "^1.6.1",
"dotenv": "^16.3.1",
"jest": "^29.6.3",
"prettier": "3.0.2",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"tsx": "^4.7.0",
"typescript": "^5.1.6",
"viem": "1.9.5",
"viem": "1.11.0",
"zod": "^3.22.4"
}
}
9 changes: 9 additions & 0 deletions publish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { bundleModules } from "./bundler";
import * as fs from "fs";

export function updateBundle() {
const bundledModules = bundleModules();
fs.writeFileSync("modules.json", JSON.stringify(bundledModules));
}

updateBundle();
6 changes: 2 additions & 4 deletions test/arbitrumDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { arbitrum } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand Down Expand Up @@ -45,9 +45,7 @@ describe("Arbitrum deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
6 changes: 2 additions & 4 deletions test/baseDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand Down Expand Up @@ -45,9 +45,7 @@ describe("Base deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
6 changes: 2 additions & 4 deletions test/celoDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { celo } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand Down Expand Up @@ -45,9 +45,7 @@ describe("Celo deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
7 changes: 3 additions & 4 deletions test/gnosisDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { gnosis } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand All @@ -28,6 +28,7 @@ describe("Gnosis deployments", () => {
beforeAll(async () => {
anvil = createAnvil({
forkUrl: process.env.GNOSIS_RPC,
startTimeout: 20000,
});
await anvil.start();

Expand All @@ -45,9 +46,7 @@ describe("Gnosis deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
7 changes: 3 additions & 4 deletions test/goerliDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { goerli } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand All @@ -28,6 +28,7 @@ describe("Goerli deployments", () => {
beforeAll(async () => {
anvil = createAnvil({
forkUrl: process.env.GOERLI_RPC,
startTimeout: 20000,
});
await anvil.start();

Expand All @@ -45,9 +46,7 @@ describe("Goerli deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
6 changes: 2 additions & 4 deletions test/mainnetDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand Down Expand Up @@ -45,9 +45,7 @@ describe("Mainnet deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
6 changes: 2 additions & 4 deletions test/optimismDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { optimism } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand Down Expand Up @@ -45,9 +45,7 @@ describe("Optimism deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
Loading

0 comments on commit 5d82fc4

Please sign in to comment.