Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
feat: devnets (#823)
Browse files Browse the repository at this point in the history
Co-authored-by: Matias Volpe <matias@parity.io>
  • Loading branch information
tjjfvi and kratico authored Apr 7, 2023
1 parent e044efb commit 18338a8
Show file tree
Hide file tree
Showing 109 changed files with 1,317 additions and 1,054 deletions.
12 changes: 0 additions & 12 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ ARG VARIANT=bullseye
FROM --platform=linux/amd64 mcr.microsoft.com/devcontainers/base:0-${VARIANT}

ARG DENO_VERSION=1.31.1
ARG POLKADOT_VERSION=v0.9.37
ARG POLKADOT_PARACHAIN_VERSION=v0.9.370
ARG ZOMBIENET_VERSION=v1.3.37
ARG SUBSTRATE_CONTRACTS_NODE_VERSION=v0.24.0

ENV DENO_INSTALL=/deno
ENV DENO_INSTALL_ROOT=/usr/local
Expand All @@ -21,14 +17,6 @@ ENV PATH=${DENO_INSTALL}/bin:${PATH} \
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y unzip curl git procps \
&& curl -fsSL -o /usr/local/bin/polkadot https://github.com/paritytech/polkadot/releases/download/${POLKADOT_VERSION}/polkadot \
&& chmod +x /usr/local/bin/polkadot \
&& curl -fsSL -o /usr/local/bin/polkadot-parachain https://github.com/paritytech/cumulus/releases/download/${POLKADOT_PARACHAIN_VERSION}/polkadot-parachain \
&& chmod +x /usr/local/bin/polkadot-parachain \
&& curl -fsSL -o /usr/local/bin/zombienet-linux-x64 https://github.com/paritytech/zombienet/releases/download/${ZOMBIENET_VERSION}/zombienet-linux-x64 \
&& chmod +x /usr/local/bin/zombienet-linux-x64 \
&& curl -fsSL https://github.com/paritytech/substrate-contracts-node/releases/download/${SUBSTRATE_CONTRACTS_NODE_VERSION}/substrate-contracts-node-linux.tar.gz | tar -zx \
&& mv ./artifacts/substrate-contracts-node-linux/substrate-contracts-node /usr/local/bin/ \
&& curl -fsSL https://dprint.dev/install.sh | DPRINT_INSTALL=/usr/local sh \
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get install -y nodejs \
Expand Down
92 changes: 53 additions & 39 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
push:
branches:
- main

env:
CAPI_SHA: ${{ github.event.pull_request.head.sha || github.sha }}

jobs:
fmt:
name: Formatting
Expand Down Expand Up @@ -33,29 +37,54 @@ jobs:
- uses: actions/checkout@v3
- uses: streetsidesoftware/cspell-action@6eb87310ae9cb344fb342ea01a2f74979fb31b86 # v2.7.0

cache:
name: Cache
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@9db7f66e8e16b5699a514448ce994936c63f0d54 # v1.1.0
with:
deno-version: v1.x
- uses: actions/cache@v3
with:
path: ~/.cache/deno
key: cache-${{ env.CAPI_SHA }}
- run: deno run -A _tasks/await_deployment.ts
timeout-minutes: 1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: deno run -A _tasks/use_remote.ts
- run: deno task run _tasks/star.ts
# Attempt caching thrice; #856
- run: deno cache target/star.ts || deno cache target/star.ts || deno cache target/star.ts

sync:
name: Sync
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@9db7f66e8e16b5699a514448ce994936c63f0d54 # v1.1.0
with:
deno-version: v1.x
- run: deno task sync --check

star:
name: Star
runs-on: ubuntu-latest
timeout-minutes: 10
needs: cache
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@9db7f66e8e16b5699a514448ce994936c63f0d54 # v1.1.0
with:
deno-version: v1.x
- name: Cache Deno dependencies
uses: actions/cache@v3
with:
path: |
~/.deno
~/.cache/deno
key: ${{ runner.os }}-deno-${{ hashFiles('deps/**/*.ts') }}
- name: Cache metadata
uses: actions/cache@v3
- uses: actions/cache@v3
with:
path: |
target/capi/**/_metadata
target/capi/**/_chainName
key: ${{ runner.os }}-capi-metadata-${{ hashFiles('import_map.json') }}
path: ~/.cache/deno
key: cache-${{ env.CAPI_SHA }}
- run: deno run -A _tasks/use_remote.ts
- run: deno task run _tasks/star.ts
- run: deno task cache target/star.ts
- run: deno task check target/star.ts
Expand All @@ -64,47 +93,32 @@ jobs:
name: Tests
runs-on: ubuntu-latest
timeout-minutes: 10
needs: cache
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@9db7f66e8e16b5699a514448ce994936c63f0d54 # v1.1.0
with:
deno-version: v1.x
- name: Cache Deno dependencies
uses: actions/cache@v3
- uses: actions/cache@v3
with:
path: |
~/.deno
~/.cache/deno
key: ${{ runner.os }}-deno-${{ hashFiles('deps/**/*.ts') }}
- name: Cache metadata
uses: actions/cache@v3
with:
path: |
target/capi/**/_metadata
target/capi/**/_chainName
key: ${{ runner.os }}-capi-metadata-${{ hashFiles('import_map.json') }}
path: ~/.cache/deno
key: cache-${{ env.CAPI_SHA }}
- run: deno run -A _tasks/use_remote.ts
- run: deno task test

examples-deno:
name: Examples (Deno)
runs-on: ubuntu-latest
timeout-minutes: 15
needs: cache
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@9db7f66e8e16b5699a514448ce994936c63f0d54 # v1.1.0
with:
deno-version: v1.x
- name: Cache Deno dependencies
uses: actions/cache@v3
with:
path: |
~/.deno
~/.cache/deno
key: ${{ runner.os }}-deno-${{ hashFiles('deps/**/*.ts') }}
- name: Cache metadata
uses: actions/cache@v3
- uses: actions/cache@v3
with:
path: |
target/capi/**/_metadata
target/capi/**/_chainName
key: ${{ runner.os }}-capi-metadata-${{ hashFiles('import_map.json') }}
path: ~/.cache/deno
key: cache-${{ env.CAPI_SHA }}
- run: deno run -A _tasks/use_remote.ts
- run: deno task test:examples:deno
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"editor.tabSize": 2,
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"target/**": true
"**/.git/subtree-cache/**": true
},
"prettier.printWidth": 100,
"ltex.disabledRules": {
Expand Down
10 changes: 10 additions & 0 deletions _tasks/await_deployment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { delay } from "../deps/std/async.ts"
import { _getDeploymentUrl } from "../server/capi.dev/delegator.ts"

const sha = Deno.env.get("CAPI_SHA")!

const deploymentPollInterval = 5_000

while (!(await _getDeploymentUrl(sha))) {
await delay(deploymentPollInterval)
}
2 changes: 1 addition & 1 deletion _tasks/generate_artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { hex } from "../crypto/mod.ts"
import { testUser } from "../crypto/mod.ts"
import * as $ from "../deps/scale.ts"
import { emptyDir } from "../deps/std/fs.ts"
import * as path from "../deps/std/path.ts"
import { testUser } from "../devnets/mod.ts"
import dprintConfig from "../dprint.json" assert { type: "json" }
import { compress } from "../util/compression.ts"

Expand Down
37 changes: 37 additions & 0 deletions _tasks/use_remote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This task is used in CI to edit the import map to use capi.dev for codegen
// instead of the local server.

import { config } from "../capi.config.ts"
import { checkCodegenUploaded, syncConfig } from "../mod.ts"

const shaAbbrevLength = 8
const sha = Deno.env.get("CAPI_SHA")!.slice(0, shaAbbrevLength)

const oldServer = config.server
const capiServer = `https://capi.dev/@${sha}/`
config.server = capiServer

const importMap = JSON.parse(await Deno.readTextFile("import_map.json"))
const oldCodegenUrl = importMap.imports["@capi/"]

if (!oldCodegenUrl.startsWith(oldServer)) {
throw new Error("_tasks/use_remote.ts run twice")
}

const codegenUrl = capiServer + oldCodegenUrl.slice(oldServer.length)

console.log(codegenUrl)

importMap.imports["@capi/"] = codegenUrl
importMap.imports[`${capiServer}capi/`] = "./"

await Deno.writeTextFile("import_map.json", JSON.stringify(importMap, null, 2))

const codegenHash = oldCodegenUrl.slice(oldServer.length).split("/")[0]

if (await checkCodegenUploaded(capiServer, codegenHash)) {
console.log("codegen already uploaded")
} else {
console.log("uploading codegen")
await syncConfig("target/capi", config)
}
51 changes: 51 additions & 0 deletions capi.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { binary, CapiConfig } from "./mod.ts"

const polkadot = binary("polkadot", "v0.9.38")
const polkadotParachain = binary("polkadot-parachain", "v0.9.380")
const substrateContractsNode = binary("substrate-contracts-node", "v0.24.0")

export const config: CapiConfig = {
server: "http://localhost:4646/",
chains: {
polkadot: {
url: "wss://rpc.polkadot.io/",
version: "v0.9.40",
},
westend: {
url: "wss://westend-rpc.polkadot.io/",
version: "latest",
},
statemint: {
url: "wss://statemint-rpc.polkadot.io/",
version: "latest",
},
polkadotDev: {
binary: polkadot,
chain: "polkadot-dev",
},
westendDev: {
binary: polkadot,
chain: "westend-dev",
},
contractsDev: {
binary: substrateContractsNode,
chain: "dev",
},
rococoDev: {
binary: polkadot,
chain: "rococo-local",
parachains: {
statemine: {
id: 1000,
binary: polkadotParachain,
chain: "statemine-local",
},
contracts: {
id: 2000,
binary: polkadotParachain,
chain: "contracts-rococo-local",
},
},
},
},
}
10 changes: 0 additions & 10 deletions cli/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,12 @@ import { download } from "../deps/capi_binary_builds.ts"
export default async function(
binary: string,
version: string,
dashDash?: string,
...args: string[]
) {
if (!binary || !version) throw new Error("Must specify binary and version")

const binaryPath = await download(binary, version)

if (!dashDash) {
console.log(binaryPath)
Deno.exit(0)
}

if (dashDash !== "--") {
throw new Error("Arguments to bin must begin with --")
}

const child = new Deno.Command(binaryPath, {
args,
stdin: "inherit",
Expand Down
19 changes: 19 additions & 0 deletions cli/resolveConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as flags from "../deps/std/flags.ts"
import * as path from "../deps/std/path.ts"
import { CapiConfig } from "../devnets/mod.ts"

export async function resolveConfig(...args: string[]) {
const { config: rawConfigPath } = flags.parse(args, {
string: ["config"],
default: {
config: "./capi.config.ts",
},
})
const configPath = path.resolve(rawConfigPath)
await Deno.stat(configPath)
const configModule = await import(path.toFileUrl(configPath).toString())
const config = configModule.config
if (typeof config !== "object") throw new Error("config file must have a config export")

return config as CapiConfig
}
Loading

0 comments on commit 18338a8

Please sign in to comment.