Skip to content

Commit

Permalink
fix(cli): setup for linux (#1961)
Browse files Browse the repository at this point in the history
* fix arch sufix

* add setup test in ci

* typo

* typo

* fix script for ci

* ci, debug

* add check

* debug

* debug

* fix exit code

* debug

* add token to auth request

* typo
  • Loading branch information
pepoviola authored Feb 17, 2025
1 parent 078cdc5 commit bbdc2ea
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 21 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/setup-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Zombienet Setup Tests

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
ZOMBIE_TRACE: 1
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

permissions: {}

jobs:
setup_test:
strategy:
matrix:
target: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.target }}
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: setup node
uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm install && npm update
working-directory: "./javascript"
- run: npm run build
working-directory: "./javascript"
- run: |
JS_DIR=$(pwd)
echo "javascript directory: ${JS_DIR}"
mkdir /tmp/a
cd /tmp/a
DEBUG=zombie-cli::setup node $JS_DIR/packages/cli/dist/cli.js setup -y all
working-directory: "./javascript"
- run: ls -ltr /tmp/a
78 changes: 57 additions & 21 deletions javascript/packages/cli/src/actions/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import cliProgress from "cli-progress";
import fs from "fs";
import path from "path";

const debug = require("debug")("zombie-cli::setup");

interface OptIf {
[key: string]: { name: string; url?: string; size?: string };
}
Expand Down Expand Up @@ -52,23 +54,28 @@ export async function setup(params: any, opts?: any) {
console.log(decorators.green("Gathering latest releases' versions...\n"));
const arch_sufix = process.arch === "arm64" ? "aarch64-apple-darwin" : "";

const allReleases = await getAllReleases(POLKADOT_SDK);

await new Promise<void>((resolve) => {
latestPolkadotReleaseURL(POLKADOT_SDK, `${POLKADOT}-${arch_sufix}`).then(
(res: [string, string]) => {
options[POLKADOT] = {
name: POLKADOT,
url: res[0],
size: res[1],
};
resolve();
},
);
latestPolkadotReleaseURL(
POLKADOT_SDK,
`${POLKADOT}${arch_sufix ? "-" + arch_sufix : ""}`,
allReleases,
).then((res: [string, string]) => {
options[POLKADOT] = {
name: POLKADOT,
url: res[0],
size: res[1],
};
resolve();
});
});

await new Promise<void>((resolve) => {
latestPolkadotReleaseURL(
POLKADOT_SDK,
`${POLKADOT_PREPARE_WORKER}-${arch_sufix}`,
`${POLKADOT_PREPARE_WORKER}${arch_sufix ? "-" + arch_sufix : ""}`,
allReleases,
).then((res: [string, string]) => {
options[POLKADOT_PREPARE_WORKER] = {
name: POLKADOT_PREPARE_WORKER,
Expand All @@ -82,7 +89,8 @@ export async function setup(params: any, opts?: any) {
await new Promise<void>((resolve) => {
latestPolkadotReleaseURL(
POLKADOT_SDK,
`${POLKADOT_EXECUTE_WORKER}-${arch_sufix}`,
`${POLKADOT_EXECUTE_WORKER}${arch_sufix ? "-" + arch_sufix : ""}`,
allReleases,
).then((res: [string, string]) => {
options[POLKADOT_EXECUTE_WORKER] = {
name: POLKADOT_EXECUTE_WORKER,
Expand All @@ -96,7 +104,8 @@ export async function setup(params: any, opts?: any) {
await new Promise<void>((resolve) => {
latestPolkadotReleaseURL(
POLKADOT_SDK,
`${POLKADOT_PARACHAIN}-${arch_sufix}`,
`${POLKADOT_PARACHAIN}${arch_sufix ? "-" + arch_sufix : ""}`,
allReleases,
).then((res: [string, string]) => {
options[POLKADOT_PARACHAIN] = {
name: POLKADOT_PARACHAIN,
Expand Down Expand Up @@ -199,6 +208,7 @@ const downloadBinaries = async (binaries: string[]): Promise<void> => {
cliProgress.Presets.shades_grey,
);

debug("Download info:", options);
for (const binary of binaries) {
promises.push(
new Promise<void>(async (resolve) => {
Expand Down Expand Up @@ -257,6 +267,9 @@ const downloadBinaries = async (binaries: string[]): Promise<void> => {
),
decorators.blue(`export PATH=${process.cwd()}:$PATH\n\n`),
);

// set exit code
process.exitCode = 0;
} catch (err) {
console.log(
`\n ${decorators.red("Unexpected error: ")} \t ${decorators.bright(
Expand All @@ -266,19 +279,38 @@ const downloadBinaries = async (binaries: string[]): Promise<void> => {
}
};

const getAllReleases = async (repo: string): Promise<any> => {
const release_url = `https://api.github.com/repos/paritytech/${repo}/releases`;
debug(`release url: ${release_url}`);
const headers: any = {
Accept: "application/vnd.github+json",
};

if (process.env.GH_TOKEN) {
headers["Authorization"] = `Bearer ${process.env.GH_TOKEN}`;
}

const releases = await fetch(
`https://api.github.com/repos/paritytech/${repo}/releases`,
headers,
);

const allReleases = await releases.json();
if (process.env.ZOMBIE_TRACE) {
debug(`all releases: \n ${JSON.stringify(allReleases)}`);
}
return allReleases;
};

// Retrieve the latest release for polkadot
const latestPolkadotReleaseURL = async (
repo: string,
name: string,
allReleases: any,
): Promise<[string, string]> => {
try {
const releases = await fetch(
`https://api.github.com/repos/paritytech/${repo}/releases`,
);

let obj: any;

const allReleases = await releases.json();
const release = allReleases.find((r: any) => {
obj = r?.assets?.find((a: any) => a.name === name);
return Boolean(obj);
Expand Down Expand Up @@ -306,9 +338,13 @@ const latestPolkadotReleaseURL = async (
throw new Error(
"Could not find a release. Error 404 (not found) detected",
);
} else if (err.response) {
throw new Error(
`Error status: ${err?.response?.status}. Error message: ${err?.response}`,
);
}
throw new Error(
`Error status: ${err?.response?.status}. Error message: ${err?.response}`,
);

// fallthrough
throw new Error(`Error: ${err}`);
}
};

0 comments on commit bbdc2ea

Please sign in to comment.