Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI v2 first alpha #110

Merged
merged 9 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/blue-planes-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": major
---

bump sdk to 0.12
5 changes: 5 additions & 0 deletions .changeset/early-ants-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": major
---

remove command `send dapp-address`
5 changes: 5 additions & 0 deletions .changeset/eight-schools-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": major
---

build based on cartesi.toml
28 changes: 5 additions & 23 deletions .github/workflows/cli.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
name: cli
on:
workflow_call:
inputs:
release:
type: boolean
required: false
secrets:
NPM_TOKEN:
required: true
TURBO_TOKEN:
required: true
pull_request:
paths:
- .github/workflows/cli.yaml
Expand Down Expand Up @@ -48,22 +38,14 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Test / Coverage
working-directory: ./apps/cli
run: pnpm run test:coverage
- name: Build
run: pnpm build --filter @cartesi/cli

- name: Test
run: pnpm test --filter @cartesi/cli

- name: "Report Coverage"
if: always()
uses: davelosert/vitest-coverage-report-action@v2
with:
working-directory: ./apps/cli

- name: Build
run: pnpm build --filter @cartesi/cli

- name: Publish
if: ${{ inputs.release }}
working-directory: ./apps/cli
run: pnpm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
17 changes: 0 additions & 17 deletions .github/workflows/devnet.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
name: devnet
on:
workflow_call:
inputs:
release:
type: boolean
required: false
secrets:
NPM_TOKEN:
required: true
TURBO_TOKEN:
required: true
pull_request:
paths:
- .github/workflows/devnet.yaml
Expand Down Expand Up @@ -46,10 +36,3 @@ jobs:

- name: Build
run: pnpm build --filter @cartesi/devnet

- name: Publish
if: ${{ inputs.release }}
run: pnpm publish --access public
working-directory: packages/devnet
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
17 changes: 0 additions & 17 deletions .github/workflows/paymaster.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
name: paymaster
on:
workflow_call:
inputs:
release:
type: boolean
required: false
secrets:
NPM_TOKEN:
required: true
TURBO_TOKEN:
required: true
pull_request:
paths:
- .github/workflows/paymaster.yaml
Expand Down Expand Up @@ -48,10 +38,3 @@ jobs:

- name: Build
run: pnpm build --filter @cartesi/mock-verifying-paymaster

- name: Publish
if: ${{ inputs.release }}
working-directory: ./packages/mock-verifying-paymaster
run: pnpm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
42 changes: 14 additions & 28 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,27 @@ jobs:
- name: Install Dependencies
run: pnpm install

- name: Create Release Pull Request
- name: Build
run: pnpm build

- name: Test
run: pnpm test

- name: "Report Coverage"
if: always()
uses: davelosert/vitest-coverage-report-action@v2
with:
working-directory: ./apps/cli

- name: Create Release Pull Request or Publish to npm
id: changeset
uses: changesets/action@v1
with:
commit: "release: version packages"
publish: pnpm run publish-packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

packages_to_build:
name: Get released packages
Expand All @@ -66,30 +79,3 @@ jobs:
if: ${{ needs.release.outputs.published == 'true' && contains(fromJSON(needs.packages_to_build.outputs.packages), '@cartesi/sdk') }}
uses: ./.github/workflows/sdk.yaml
secrets: inherit

build_devnet:
name: Build devnet
needs: [release, packages_to_build]
if: ${{ needs.release.outputs.published == 'true' && contains(fromJSON(needs.packages_to_build.outputs.packages), '@cartesi/devnet') }}
uses: ./.github/workflows/devnet.yaml
secrets: inherit
with:
release: true

build_cli:
name: Build cli
needs: [release, packages_to_build]
if: ${{ needs.release.outputs.published == 'true' && contains(fromJSON(needs.packages_to_build.outputs.packages), '@cartesi/cli') }}
uses: ./.github/workflows/cli.yaml
secrets: inherit
with:
release: true

build_paymaster:
name: Build paymaster
needs: [release, packages_to_build]
if: ${{ needs.release.outputs.published == 'true' && contains(fromJSON(needs.packages_to_build.outputs.packages), '@cartesi/mock-verifying-paymaster') }}
uses: ./.github/workflows/paymaster.yaml
secrets: inherit
with:
release: true
6 changes: 5 additions & 1 deletion apps/cli/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ module.exports = {
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["./tsconfig.eslint.json", "./tsconfig.json"],
project: [
"./tsconfig.build.json",
"./tsconfig.eslint.json",
"./tsconfig.json",
],
tsconfigRootDir: __dirname,
},
};
1 change: 1 addition & 0 deletions apps/cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ node_modules
oclif.manifest.json
src/contracts.ts
src/graphql/
test/builder/output
6 changes: 3 additions & 3 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"ora": "^8.1.0",
"progress-stream": "^2.0.0",
"semver": "^7.6.3",
"smol-toml": "^1.3.0",
"tmp": "^0.2.3",
"viem": "^2.21.27"
},
Expand Down Expand Up @@ -85,14 +86,13 @@
"clean": "rimraf dist",
"codegen": "run-p codegen:wagmi",
"codegen:wagmi": "wagmi generate",
"compile": "tsc -b",
"compile": "tsc -p tsconfig.build.json",
"copy-files": "copyfiles -u 1 \"src/**/*.yaml\" \"src/**/*.env\" \"src/**/*.txt\" dist",
"lint": "eslint \"src/**/*.ts*\"",
"postpack": "rimraf oclif.manifest.json",
"posttest": "pnpm lint",
"prepack": "pnpm build && oclif manifest",
"test": "vitest",
"test:coverage": "vitest --coverage.enabled true"
"test": "vitest"
},
"engines": {
"node": ">=18.0.0"
Expand Down
19 changes: 12 additions & 7 deletions apps/cli/src/baseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import fs from "fs";
import path from "path";
import { Address, Hash, getAddress, isHash } from "viem";

import { Config, parse } from "./config.js";
import {
authorityHistoryPairFactoryAddress,
cartesiDAppFactoryAddress,
dAppAddressRelayAddress,
applicationFactoryAddress,
authorityFactoryAddress,
erc1155BatchPortalAddress,
erc1155SinglePortalAddress,
erc20PortalAddress,
Expand Down Expand Up @@ -54,6 +54,12 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
return path.join(".cartesi", ...paths);
}

protected getApplicationConfig(configPath: string): Config {
return fs.existsSync(configPath)
? parse(fs.readFileSync(configPath).toString())
: parse("");
}

protected getMachineHash(): Hash | undefined {
// read hash of the cartesi machine snapshot, if one exists
const hashPath = this.getContextPath("image", "hash");
Expand All @@ -80,10 +86,9 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {

// build rollups contracts address book
const contracts: AddressBook = {
AuthorityHistoryPairFactory: authorityHistoryPairFactoryAddress,
CartesiDApp: applicationAddress,
CartesiDAppFactory: cartesiDAppFactoryAddress,
DAppAddressRelay: dAppAddressRelayAddress,
Application: applicationAddress,
ApplicationFactory: applicationFactoryAddress,
AuthorityFactory: authorityFactoryAddress,
EntryPointV06: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
EntryPointV07: "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
ERC1155BatchPortal: erc1155BatchPortalAddress,
Expand Down
45 changes: 45 additions & 0 deletions apps/cli/src/builder/directory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import fs from "fs-extra";
import path from "path";
import { DirectoryDriveConfig } from "../config.js";
import { genext2fs, mksquashfs } from "../exec/index.js";

export const build = async (
name: string,
drive: DirectoryDriveConfig,
sdkImage: string,
destination: string,
): Promise<void> => {
const filename = `${name}.${drive.format}`;

// copy directory to destination
const dest = path.join(destination, name);
await fs.mkdirp(dest);
await fs.copy(drive.directory, dest);

try {
switch (drive.format) {
case "ext2": {
await genext2fs.fromDirectory({
extraSize: drive.extraSize,
input: name,
output: filename,
cwd: destination,
image: sdkImage,
});
break;
}
case "sqfs": {
await mksquashfs.fromDirectory({
input: name,
output: filename,
cwd: destination,
image: sdkImage,
});
break;
}
}
} finally {
// delete copied
await fs.remove(dest);
}
};
Loading
Loading