From 0fac2029f62eaa294648512756b204b5df9de26d Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Mon, 16 Sep 2024 15:06:39 -0600 Subject: [PATCH 01/23] add global dependencies installation --- src/build/index.ts | 13 ++ .../install_global_dependencies/index.ts | 119 ++++++++++++++++++ .../install_dfx.sh | 35 ++++++ .../install_node.sh | 37 ++++++ .../install_rust.sh | 41 ++++++ .../install_wasi2ic.sh | 48 +++++++ src/build/stable/utils/types.ts | 1 + 7 files changed, 294 insertions(+) create mode 100644 src/build/stable/commands/install_global_dependencies/index.ts create mode 100755 src/build/stable/commands/install_global_dependencies/install_dfx.sh create mode 100755 src/build/stable/commands/install_global_dependencies/install_node.sh create mode 100755 src/build/stable/commands/install_global_dependencies/install_rust.sh create mode 100755 src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh diff --git a/src/build/index.ts b/src/build/index.ts index 2730f5aca5..c96eb8bb0e 100755 --- a/src/build/index.ts +++ b/src/build/index.ts @@ -12,6 +12,7 @@ import { import { runCommand as runCleanCommand } from './stable/commands/clean'; import { runCommand as runStableCompileCommand } from './stable/commands/compile'; import { runCommand as runInstallDfxExtensionCommand } from './stable/commands/install_dfx_extension'; +import { runCommand as runInstallGlobalDependenciesCommand } from './stable/commands/install_global_dependencies'; import { runCommand as runNewCommand } from './stable/commands/new'; import { runCommand as runStableTemplateCommand } from './stable/commands/template'; import { runCommand as runVersionCommand } from './stable/commands/version'; @@ -38,6 +39,12 @@ async function build(): Promise { return; } + if (command === 'install-global-dependencies') { + handleInstallGlobalDependenciesCommand(ioType); + + return; + } + if (command === 'upload-assets') { await handleUploadAssetsCommand(); @@ -129,6 +136,12 @@ async function handleTemplateCommand(ioType: IOType): Promise { } } +async function handleInstallGlobalDependenciesCommand( + ioType: IOType +): Promise { + await runInstallGlobalDependenciesCommand(ioType); +} + async function handleNewCommand(): Promise { const experimental = process.argv.includes('--experimental'); const httpServer = process.argv.includes('--http-server'); diff --git a/src/build/stable/commands/install_global_dependencies/index.ts b/src/build/stable/commands/install_global_dependencies/index.ts new file mode 100644 index 0000000000..b45be5ba83 --- /dev/null +++ b/src/build/stable/commands/install_global_dependencies/index.ts @@ -0,0 +1,119 @@ +import { IOType } from 'child_process'; +import { readFile } from 'fs/promises'; +import { join } from 'path'; + +import { execSyncPretty } from '../../utils/exec_sync_pretty'; +import { AZLE_PACKAGE_PATH } from '../../utils/global_paths'; + +type Versions = { + [key in ValidFlag]: string; +}; + +type ValidFlag = 'node' | 'dfx' | 'rustc' | 'wasi2ic'; + +// TODO Hey Jordan, I'm not wild about the package property name, but it works for now +// TODO for that matter the whole idea of package is a little odd. We only need it for rust. I suppose we could just make the flag --rustc and then we wouldn't have to worry about it. I'm just worried if rustc is a lest obvious flag name +// TODO though on the other hand, we do have a nice little usage message that would let them know right away that it was wrong. +// TODO Hey Jordan, Is it too much to stipulate for future dependencies that the install script is install_${name}? Then we wouldn't have to specify the script here +const validFlags = { + node: { name: 'Node.js', script: 'install_node.sh' }, + dfx: { name: 'DFX', script: 'install_dfx.sh' }, + rustc: { name: 'Rust', script: 'install_rust.sh' }, + wasi2ic: { name: 'wasi2ic', script: 'install_wasi2ic.sh' } +}; + +// TODO don't forget, we do want a separate script to get all of these versions so that we can run it as an action. We want this because we are not the ones that install node for the github workflows + +export async function runCommand(ioType: IOType): Promise { + // TODO Hey Jordan, I was noticing that for all of the other commands the handling of flags happens before we get to this point. + // TODO I am guessing that is because of flags like experimental that apply to all of the commands? + // TODO We could modify this so that instead of grabbing the args right here, we could pass the already parsed args as a list. + // TODO We can talk about validating those flags here or where we parse them. On the one hand I think it would be good to be consistent + // TODO On the other hand I think it would be nice to make sure the index.ts file that handles the routing is as lite as possible + // TODO For right now I will leave it like this because it is already like this + // TODO Hey Jordan, on the topic of processing flags before hand. This approach does install things as we are processing flags. So if an invalid flag is in the middle of the list then it will fail after it has successfully installed some dependencies and not others. Maybe we do want to process before we get to this point anyways? + const args = process.argv.slice(3); + const installAll = args.length === 0; + + const versions = await getGlobalDependencies(); + + if (installAll) { + // Install everything if no specific flags are provided + for (const flag in validFlags) { + const { name, script } = validFlags[flag as ValidFlag]; + const version = versions[flag as ValidFlag]; + installDependency(name, script, version, ioType); + } + } else { + // Install dependencies based on provided flags + for (const arg of args) { + const flag = arg.slice(2); + const flagConfig = validFlags[flag as ValidFlag]; + + if (flagConfig !== undefined) { + const { name, script } = flagConfig; + const version = versions[flag as ValidFlag]; + installDependency(name, script, version, ioType); + } else { + console.error(`Unrecognized option: ${arg}`); + printUsage(); + process.exit(1); + } + } + } +} + +function installDependency( + dependency: string, + script: string, + version: string, + ioType: IOType +): void { + console.info(`Installing ${dependency}...`); + execSyncPretty( + `${AZLE_PACKAGE_PATH}/src/build/stable/commands/install_global_dependencies/${script} ${version}`, + ioType + ); +} + +function printUsage(): void { + // Find the longest flag for dynamic spacing + const longestFlagLength = Math.max( + ...Object.keys(validFlags).map((flag) => flag.length) + ); + + console.info(` +Usage: npx azle install-global-dependencies [options] + +Options: +`); + for (const flag in validFlags) { + const padding = ' '.repeat(longestFlagLength - flag.length); + console.info( + ` --${flag}${padding} Install ${ + validFlags[flag as ValidFlag].name + } dependencies` + ); + } + console.info(` +If no options are provided, all dependencies will be installed. +`); +} + +async function getGlobalDependencies(): Promise { + // Path to package.json + const packageJsonPath = join(process.cwd(), 'package.json'); + + // Read the existing package.json file + const packageJsonContent = await readFile(packageJsonPath, 'utf-8'); + const packageJson = JSON.parse(packageJsonContent); + + // Extract globalDependencies + const globalDependencies = packageJson.globalDependencies; + + if (!globalDependencies) { + throw new Error('No globalDependencies found in package.json.'); + } + + return globalDependencies; +} diff --git a/src/build/stable/commands/install_global_dependencies/install_dfx.sh b/src/build/stable/commands/install_global_dependencies/install_dfx.sh new file mode 100755 index 0000000000..2066505f65 --- /dev/null +++ b/src/build/stable/commands/install_global_dependencies/install_dfx.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Ensure that a version argument is passed +if [ -z "$1" ]; then + echo "Error: No DFX version specified." + echo "Usage: ./install_dfx.sh " + exit 1 +fi + +DFX_VERSION=$1 + +# Check if dfx is installed and its version +if command -v dfx &> /dev/null; then + INSTALLED_VERSION=$(dfx --version | cut -d ' ' -f 2) + + echo "Installed dfx version: $INSTALLED_VERSION" + echo "Requested dfx version: $DFX_VERSION" + + # If the installed version matches the requested version, skip installation + if [ "$INSTALLED_VERSION" = "$DFX_VERSION" ]; then + echo "dfx $DFX_VERSION is already installed. No installation needed." + exit 0 + else + echo "Updating dfx from version $INSTALLED_VERSION to $DFX_VERSION" + fi +else + echo "dfx is not installed. Proceeding with installation of dfx $DFX_VERSION." +fi + +# Install or update dfx using the official installation script +echo "Installing dfx version $DFX_VERSION..." +DFXVM_INIT_YES=true DFX_VERSION=$DFX_VERSION sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" + +echo "dfx $DFX_VERSION installation completed." +exit 0 diff --git a/src/build/stable/commands/install_global_dependencies/install_node.sh b/src/build/stable/commands/install_global_dependencies/install_node.sh new file mode 100755 index 0000000000..8a12dbbbe3 --- /dev/null +++ b/src/build/stable/commands/install_global_dependencies/install_node.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Ensure that a version argument is passed +if [ -z "$1" ]; then + echo "Error: No Node.js version specified." + echo "Usage: ./install_node.sh " + exit 1 +fi + +NODE_VERSION=$1 + +# Check if nvm is installed +if ! command -v nvm &> /dev/null; then + echo "nvm is not installed. Installing nvm..." + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash + + # Load nvm into the shell (necessary for the script to use nvm after installation) + export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion +else + echo "nvm is already installed." +fi + +if nvm ls "$NODE_VERSION" &> /dev/null; then + echo "Node.js version $NODE_VERSION is already installed. Skipping installation." + nvm use "$NODE_VERSION" + exit 0 +else + echo "Installing Node.js version $NODE_VERSION..." + nvm install "$NODE_VERSION" + nvm use "$NODE_VERSION" +fi + +echo "Node.js $NODE_VERSION installation completed." +node --version +exit 0 diff --git a/src/build/stable/commands/install_global_dependencies/install_rust.sh b/src/build/stable/commands/install_global_dependencies/install_rust.sh new file mode 100755 index 0000000000..031d969954 --- /dev/null +++ b/src/build/stable/commands/install_global_dependencies/install_rust.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +if [ -z "$1" ]; then + echo "Error: No Rust version specified." + echo "Usage: ./install_rust.sh " + exit 1 +fi + +RUST_VERSION=$1 + +# Check if Rust is installed and its version +if command -v rustc &> /dev/null; then + INSTALLED_VERSION=$(rustc --version | cut -d ' ' -f 2) + + echo "Installed Rust version: $INSTALLED_VERSION" + echo "Requested Rust version: $RUST_VERSION" + + if [ "$INSTALLED_VERSION" = "$RUST_VERSION" ]; then + echo "Rust $RUST_VERSION is already installed. No installation needed." + exit 0 + else + echo "Updating Rust from version $INSTALLED_VERSION to $RUST_VERSION" + fi +else + echo "Rust is not installed. Proceeding with installation of Rust $RUST_VERSION." +fi + +# Install Rust +echo "Installing Rust version $RUST_VERSION..." +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain "$RUST_VERSION" +source $HOME/.cargo/env + +# Add the WASM target for WebAssembly +rustup target add wasm32-wasi + +echo "Rust $RUST_VERSION installation completed." +rustc --version +cargo --version +rustup target list --installed | grep wasm32-wasi + +exit 0 diff --git a/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh b/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh new file mode 100755 index 0000000000..52dc4d215b --- /dev/null +++ b/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Ensure that a version argument is passed +if [ -z "$1" ]; then + echo "Error: No WASI2IC version specified." + echo "Usage: ./install_wasi2ic.sh " + exit 1 +fi + +WASI2IC_VERSION=$1 + +# Check if WASI2IC_VERSION is a URL (repo) or just a version number +if [[ $WASI2IC_VERSION =~ ^https?:// ]]; then + WASI2IC_URL=$WASI2IC_VERSION +else + WASI2IC_URL="" +fi + +# Check if `wasi2ic` is installed +if command -v wasi2ic &> /dev/null; then + INSTALLED_VERSION=$(wasi2ic --version | awk '{print $2}') + + echo "Installed wasi2ic version: $INSTALLED_VERSION" + echo "Requested wasi2ic version: $WASI2IC_VERSION" + + # If the installed version matches the requested version, skip installation + if [ -z "$WASI2IC_URL" ] && [ "$INSTALLED_VERSION" = "$WASI2IC_VERSION" ]; then + echo "wasi2ic $WASI2IC_VERSION is already installed. No installation needed." + exit 0 + else + echo "Updating wasi2ic from version $INSTALLED_VERSION to $WASI2IC_VERSION" + fi +else + echo "wasi2ic is not installed. Proceeding with installation." +fi + +# Install or update wasi2ic +if [[ -n "$WASI2IC_URL" ]]; then + echo "Installing wasi2ic from repository $WASI2IC_URL" + cargo install --git "$WASI2IC_URL" +else + echo "Installing wasi2ic version $WASI2IC_VERSION" + cargo install wasi2ic --version "$WASI2IC_VERSION" +fi + +echo "wasi2ic installation completed." +cargo install --list | grep wasi2ic +exit 0 diff --git a/src/build/stable/utils/types.ts b/src/build/stable/utils/types.ts index 805fd4bc9b..6debef368b 100644 --- a/src/build/stable/utils/types.ts +++ b/src/build/stable/utils/types.ts @@ -32,6 +32,7 @@ export type Context = { export type Command = | 'compile' | 'install-dfx-extension' + | 'install-global-dependencies' | 'template' | 'upload-assets' | '--version' From 8f320214552d2c90367cdcb267521becd4e2b54b Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Mon, 16 Sep 2024 15:27:29 -0600 Subject: [PATCH 02/23] fix node installation to properly source nvm --- .../install_global_dependencies/install_node.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/build/stable/commands/install_global_dependencies/install_node.sh b/src/build/stable/commands/install_global_dependencies/install_node.sh index 8a12dbbbe3..51a5799fd1 100755 --- a/src/build/stable/commands/install_global_dependencies/install_node.sh +++ b/src/build/stable/commands/install_global_dependencies/install_node.sh @@ -9,15 +9,24 @@ fi NODE_VERSION=$1 +# Load nvm if it's installed +if [ -s "$HOME/.nvm/nvm.sh" ]; then + source "$HOME/.nvm/nvm.sh" +elif [ -s "/usr/local/opt/nvm/nvm.sh" ]; then + # Fallback for macOS/Homebrew installation path + source "/usr/local/opt/nvm/nvm.sh" +else + echo "nvm is not installed." +fi + # Check if nvm is installed if ! command -v nvm &> /dev/null; then echo "nvm is not installed. Installing nvm..." - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash # Load nvm into the shell (necessary for the script to use nvm after installation) export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm - [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion else echo "nvm is already installed." fi @@ -25,13 +34,12 @@ fi if nvm ls "$NODE_VERSION" &> /dev/null; then echo "Node.js version $NODE_VERSION is already installed. Skipping installation." nvm use "$NODE_VERSION" - exit 0 else echo "Installing Node.js version $NODE_VERSION..." nvm install "$NODE_VERSION" nvm use "$NODE_VERSION" + echo "Node.js $NODE_VERSION installation completed." fi -echo "Node.js $NODE_VERSION installation completed." node --version exit 0 From b0fb3416765fed92ecde84c02a2805aabbcd1f71 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Mon, 16 Sep 2024 15:34:31 -0600 Subject: [PATCH 03/23] fix install dfx --- package.json | 3 +- .../stable/utils/log_global_dependencies.ts | 32 +++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index b933f3f450..f1f165f2d3 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,8 @@ "globalDependencies": { "wasi2ic": "https://github.com/wasm-forge/wasi2ic?rev=806c3558aad24224852a9582f018178402cb3679#806c3558", "node": "20.11.0", - "rustc": "1.80.1" + "rustc": "1.80.1", + "dfx": "0.22.0" } } } diff --git a/src/build/stable/utils/log_global_dependencies.ts b/src/build/stable/utils/log_global_dependencies.ts index 2652c62875..97819bf6e2 100644 --- a/src/build/stable/utils/log_global_dependencies.ts +++ b/src/build/stable/utils/log_global_dependencies.ts @@ -5,14 +5,16 @@ import { execSyncPretty } from './exec_sync_pretty'; import { AZLE_PACKAGE_PATH } from './global_paths'; export async function logGlobalDependencies(): Promise { - const wasiVersion = await getWasiVersion(); - const nodeVersion = await getNodeVersion(); - const rustVersion = await getRustVersion(); + const wasiVersion = getWasiVersion(); + const nodeVersion = getNodeVersion(); + const rustVersion = getRustVersion(); + const dfxVersion = getDfxVersion(); const globalDependencies = { wasi2ic: wasiVersion, node: nodeVersion, - rustc: rustVersion + rustc: rustVersion, + dfx: dfxVersion }; const packageJsonPath = join(AZLE_PACKAGE_PATH, 'package.json'); @@ -30,11 +32,11 @@ export async function logGlobalDependencies(): Promise { ); } -async function getWasiVersion(): Promise { - return await getCargoVersion('wasi2ic'); +function getWasiVersion(): string { + return getCargoVersion('wasi2ic'); } -async function getNodeVersion(): Promise { +function getNodeVersion(): string { const nodeOutput = execSyncPretty('node --version').toString().trim(); const match = nodeOutput.match(/^v(\d+\.\d+\.\d+)/); @@ -45,7 +47,7 @@ async function getNodeVersion(): Promise { } } -async function getRustVersion(): Promise { +function getRustVersion(): string { const rustcOutput = execSyncPretty('rustc --version').toString().trim(); const match = rustcOutput.match(/^rustc\s+(\d+\.\d+\.\d+)/); @@ -56,7 +58,7 @@ async function getRustVersion(): Promise { } } -async function getCargoVersion(packageName: string): Promise { +function getCargoVersion(packageName: string): string { const cargoOutput = execSyncPretty('cargo install --list').toString(); // Regular expression to capture both with and without a repository link @@ -75,3 +77,15 @@ async function getCargoVersion(packageName: string): Promise { throw new Error(`Could not parse ${packageName} version`); } } + +function getDfxVersion(): string { + const dfxOutput = execSyncPretty('dfx --version').toString().trim(); + + const match = dfxOutput.match(/dfx (\d+\.\d+\.\d+)/); + + if (match !== null && match.length > 1 && typeof match[1] === 'string') { + return match[1]; // Return the version number + } else { + throw new Error('Could not parse the dfx version'); + } +} From 5e7f6e7a00ee4cf3b9e6262176f1a94beb70d7a6 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Mon, 16 Sep 2024 16:51:07 -0600 Subject: [PATCH 04/23] more consistent version checking --- .../install_global_dependencies/index.ts | 2 +- .../install_wasi2ic.sh | 7 +-- .../stable/utils/log_global_dependencies.ts | 63 ++----------------- src/build/stable/utils/versions/dfx.ts | 29 +++++++++ src/build/stable/utils/versions/node.ts | 28 +++++++++ src/build/stable/utils/versions/rust.ts | 28 +++++++++ src/build/stable/utils/versions/wasi2ic.ts | 41 ++++++++++++ 7 files changed, 133 insertions(+), 65 deletions(-) create mode 100644 src/build/stable/utils/versions/dfx.ts create mode 100644 src/build/stable/utils/versions/node.ts create mode 100644 src/build/stable/utils/versions/rust.ts create mode 100644 src/build/stable/utils/versions/wasi2ic.ts diff --git a/src/build/stable/commands/install_global_dependencies/index.ts b/src/build/stable/commands/install_global_dependencies/index.ts index b45be5ba83..1016f0ef24 100644 --- a/src/build/stable/commands/install_global_dependencies/index.ts +++ b/src/build/stable/commands/install_global_dependencies/index.ts @@ -102,7 +102,7 @@ If no options are provided, all dependencies will be installed. async function getGlobalDependencies(): Promise { // Path to package.json - const packageJsonPath = join(process.cwd(), 'package.json'); + const packageJsonPath = join(AZLE_PACKAGE_PATH, 'package.json'); // Read the existing package.json file const packageJsonContent = await readFile(packageJsonPath, 'utf-8'); diff --git a/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh b/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh index 52dc4d215b..7a4b78a27d 100755 --- a/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh +++ b/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh @@ -1,6 +1,5 @@ #!/bin/bash -# Ensure that a version argument is passed if [ -z "$1" ]; then echo "Error: No WASI2IC version specified." echo "Usage: ./install_wasi2ic.sh " @@ -16,15 +15,13 @@ else WASI2IC_URL="" fi -# Check if `wasi2ic` is installed if command -v wasi2ic &> /dev/null; then - INSTALLED_VERSION=$(wasi2ic --version | awk '{print $2}') + INSTALLED_VERSION=$(npx tsx src/build/stable/utils/versions/wasi2ic.ts 2>&1 | tr -d '[:space:]') echo "Installed wasi2ic version: $INSTALLED_VERSION" echo "Requested wasi2ic version: $WASI2IC_VERSION" - # If the installed version matches the requested version, skip installation - if [ -z "$WASI2IC_URL" ] && [ "$INSTALLED_VERSION" = "$WASI2IC_VERSION" ]; then + if [ "$INSTALLED_VERSION" = "$WASI2IC_VERSION" ]; then echo "wasi2ic $WASI2IC_VERSION is already installed. No installation needed." exit 0 else diff --git a/src/build/stable/utils/log_global_dependencies.ts b/src/build/stable/utils/log_global_dependencies.ts index 97819bf6e2..2072781c74 100644 --- a/src/build/stable/utils/log_global_dependencies.ts +++ b/src/build/stable/utils/log_global_dependencies.ts @@ -1,8 +1,11 @@ import { readFile, writeFile } from 'fs/promises'; import { join } from 'path'; -import { execSyncPretty } from './exec_sync_pretty'; import { AZLE_PACKAGE_PATH } from './global_paths'; +import { getDfxVersion } from './versions/dfx'; +import { getNodeVersion } from './versions/node'; +import { getRustVersion } from './versions/rust'; +import { getWasiVersion } from './versions/wasi2ic'; export async function logGlobalDependencies(): Promise { const wasiVersion = getWasiVersion(); @@ -31,61 +34,3 @@ export async function logGlobalDependencies(): Promise { ) ); } - -function getWasiVersion(): string { - return getCargoVersion('wasi2ic'); -} - -function getNodeVersion(): string { - const nodeOutput = execSyncPretty('node --version').toString().trim(); - const match = nodeOutput.match(/^v(\d+\.\d+\.\d+)/); - - if (match !== null && match.length > 1 && typeof match[1] === 'string') { - return match[1]; // Returns the version number (e.g., "16.13.0") - } else { - throw new Error('Could not parse node version'); - } -} - -function getRustVersion(): string { - const rustcOutput = execSyncPretty('rustc --version').toString().trim(); - const match = rustcOutput.match(/^rustc\s+(\d+\.\d+\.\d+)/); - - if (match !== null && match.length > 1 && typeof match[1] === 'string') { - return match[1]; // Returns the version number - } else { - throw new Error('Could not parse rustc version'); - } -} - -function getCargoVersion(packageName: string): string { - const cargoOutput = execSyncPretty('cargo install --list').toString(); - - // Regular expression to capture both with and without a repository link - const regex = new RegExp( - `${packageName}\\s+v(\\d+\\.\\d+\\.\\d+)(?:\\s+\\((https?:\\/\\/.+?)\\))?` - ); - const match = cargoOutput.match(regex); - - if (match !== null && match.length > 1 && typeof match[1] === 'string') { - if (match.length > 2 && typeof match[2] === 'string') { - return match[2]; // Return the repository link if available - } else { - return match[1]; // Return the version number if no link is found - } - } else { - throw new Error(`Could not parse ${packageName} version`); - } -} - -function getDfxVersion(): string { - const dfxOutput = execSyncPretty('dfx --version').toString().trim(); - - const match = dfxOutput.match(/dfx (\d+\.\d+\.\d+)/); - - if (match !== null && match.length > 1 && typeof match[1] === 'string') { - return match[1]; // Return the version number - } else { - throw new Error('Could not parse the dfx version'); - } -} diff --git a/src/build/stable/utils/versions/dfx.ts b/src/build/stable/utils/versions/dfx.ts new file mode 100644 index 0000000000..dddd528355 --- /dev/null +++ b/src/build/stable/utils/versions/dfx.ts @@ -0,0 +1,29 @@ +import { pathToFileURL } from 'url'; + +import { execSyncPretty } from '../exec_sync_pretty'; + +export function getDfxVersion(): string { + const dfxOutput = execSyncPretty('dfx --version').toString().trim(); + + const match = dfxOutput.match(/dfx (\d+\.\d+\.\d+)/); + + if (match !== null && match.length > 1 && typeof match[1] === 'string') { + return match[1]; // Return the version number + } else { + throw new Error('Could not parse the dfx version'); + } +} + +function main(): void { + try { + const version = getDfxVersion(); + console.log(version); + } catch (error: any) { + console.error(error.message); + process.exit(1); + } +} + +if (import.meta.url === pathToFileURL(process.argv[1]).href) { + main(); +} diff --git a/src/build/stable/utils/versions/node.ts b/src/build/stable/utils/versions/node.ts new file mode 100644 index 0000000000..907c87d304 --- /dev/null +++ b/src/build/stable/utils/versions/node.ts @@ -0,0 +1,28 @@ +import { pathToFileURL } from 'url'; + +import { execSyncPretty } from '../exec_sync_pretty'; + +export function getNodeVersion(): string { + const nodeOutput = execSyncPretty('node --version').toString().trim(); + const match = nodeOutput.match(/^v(\d+\.\d+\.\d+)/); + + if (match !== null && match.length > 1 && typeof match[1] === 'string') { + return match[1]; // Returns the version number (e.g., "16.13.0") + } else { + throw new Error('Could not parse node version'); + } +} + +function main(): void { + try { + const version = getNodeVersion(); + console.log(version); + } catch (error: any) { + console.error(error.message); + process.exit(1); + } +} + +if (import.meta.url === pathToFileURL(process.argv[1]).href) { + main(); +} diff --git a/src/build/stable/utils/versions/rust.ts b/src/build/stable/utils/versions/rust.ts new file mode 100644 index 0000000000..e3ec773bd7 --- /dev/null +++ b/src/build/stable/utils/versions/rust.ts @@ -0,0 +1,28 @@ +import { pathToFileURL } from 'url'; + +import { execSyncPretty } from '../exec_sync_pretty'; + +export function getRustVersion(): string { + const rustcOutput = execSyncPretty('rustc --version').toString().trim(); + const match = rustcOutput.match(/^rustc\s+(\d+\.\d+\.\d+)/); + + if (match !== null && match.length > 1 && typeof match[1] === 'string') { + return match[1]; // Returns the version number + } else { + throw new Error('Could not parse rustc version'); + } +} + +function main(): void { + try { + const version = getRustVersion(); + console.log(version); + } catch (error: any) { + console.error(error.message); + process.exit(1); + } +} + +if (import.meta.url === pathToFileURL(process.argv[1]).href) { + main(); +} diff --git a/src/build/stable/utils/versions/wasi2ic.ts b/src/build/stable/utils/versions/wasi2ic.ts new file mode 100644 index 0000000000..50bf801966 --- /dev/null +++ b/src/build/stable/utils/versions/wasi2ic.ts @@ -0,0 +1,41 @@ +import { pathToFileURL } from 'url'; + +import { execSyncPretty } from '../exec_sync_pretty'; + +export function getWasiVersion(): string { + return getCargoVersion('wasi2ic'); +} + +function getCargoVersion(packageName: string): string { + const cargoOutput = execSyncPretty('cargo install --list').toString(); + + // Regular expression to capture both with and without a repository link + const regex = new RegExp( + `${packageName}\\s+v(\\d+\\.\\d+\\.\\d+)(?:\\s+\\((https?:\\/\\/.+?)\\))?` + ); + const match = cargoOutput.match(regex); + + if (match !== null && match.length > 1 && typeof match[1] === 'string') { + if (match.length > 2 && typeof match[2] === 'string') { + return match[2]; // Return the repository link if available + } else { + return match[1]; // Return the version number if no link is found + } + } else { + throw new Error(`Could not parse ${packageName} version`); + } +} + +function main(): void { + try { + const version = getWasiVersion(); + console.log(version); + } catch (error: any) { + console.error(error.message); + process.exit(1); + } +} + +if (import.meta.url === pathToFileURL(process.argv[1]).href) { + main(); +} From 6545bf16226d46c4fa140b91f792190651bd90d5 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Mon, 16 Sep 2024 16:55:07 -0600 Subject: [PATCH 05/23] update rust and dfx to follow suit of version checking --- .../stable/commands/install_global_dependencies/install_dfx.sh | 2 +- .../stable/commands/install_global_dependencies/install_rust.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/stable/commands/install_global_dependencies/install_dfx.sh b/src/build/stable/commands/install_global_dependencies/install_dfx.sh index 2066505f65..78c15e21f5 100755 --- a/src/build/stable/commands/install_global_dependencies/install_dfx.sh +++ b/src/build/stable/commands/install_global_dependencies/install_dfx.sh @@ -11,7 +11,7 @@ DFX_VERSION=$1 # Check if dfx is installed and its version if command -v dfx &> /dev/null; then - INSTALLED_VERSION=$(dfx --version | cut -d ' ' -f 2) + INSTALLED_VERSION=$(npx tsx src/build/stable/utils/versions/dfx.ts 2>&1 | tr -d '[:space:]') echo "Installed dfx version: $INSTALLED_VERSION" echo "Requested dfx version: $DFX_VERSION" diff --git a/src/build/stable/commands/install_global_dependencies/install_rust.sh b/src/build/stable/commands/install_global_dependencies/install_rust.sh index 031d969954..bbb55dc549 100755 --- a/src/build/stable/commands/install_global_dependencies/install_rust.sh +++ b/src/build/stable/commands/install_global_dependencies/install_rust.sh @@ -10,7 +10,7 @@ RUST_VERSION=$1 # Check if Rust is installed and its version if command -v rustc &> /dev/null; then - INSTALLED_VERSION=$(rustc --version | cut -d ' ' -f 2) + INSTALLED_VERSION=$(npx tsx src/build/stable/utils/versions/rust.ts 2>&1 | tr -d '[:space:]') echo "Installed Rust version: $INSTALLED_VERSION" echo "Requested Rust version: $RUST_VERSION" From 18190c834f8d8fb3d21c745af3c195129202febe Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Mon, 16 Sep 2024 17:14:59 -0600 Subject: [PATCH 06/23] update workflows --- .github/actions/get_node_version/action.yml | 16 +++++ .../get_node_version/get_node_version.sh | 20 +++++++ .../scripts/install_global_dependencies.sh | 58 ------------------- .github/workflows/release.yml | 6 +- .github/workflows/test.yml | 20 +++++-- 5 files changed, 53 insertions(+), 67 deletions(-) create mode 100644 .github/actions/get_node_version/action.yml create mode 100755 .github/actions/get_node_version/get_node_version.sh delete mode 100755 .github/scripts/install_global_dependencies.sh diff --git a/.github/actions/get_node_version/action.yml b/.github/actions/get_node_version/action.yml new file mode 100644 index 0000000000..e71d492733 --- /dev/null +++ b/.github/actions/get_node_version/action.yml @@ -0,0 +1,16 @@ +name: Get node version +description: Determines Azle's node version +outputs: + node-version: + description: Returns the version of node Azle used for it's last template + value: ${{ steps.get-node-version.outputs.node-version }} +runs: + using: composite + steps: + - uses: actions/checkout@v4 + + - id: get-node-version + run: | + NODE_VERSION=$(./.github/actions/get_node_version/get_node_version.sh) + echo "node-version=${NODE_VERSION}" >> "$GITHUB_OUTPUT" + shell: bash diff --git a/.github/actions/get_node_version/get_node_version.sh b/.github/actions/get_node_version/get_node_version.sh new file mode 100755 index 0000000000..03e0419835 --- /dev/null +++ b/.github/actions/get_node_version/get_node_version.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Path to package.json +PACKAGE_JSON_PATH="package.json" + +# Check if package.json exists +if [ ! -f "$PACKAGE_JSON_PATH" ]; then + echo "Error: $PACKAGE_JSON_PATH not found." + exit 1 +fi + +# Extract the Node.js version from globalDependencies +NODE_VERSION=$(jq -r '.azle.globalDependencies.node // empty' "$PACKAGE_JSON_PATH") + +if [ -z "$NODE_VERSION" ]; then + echo "Node.js version not found in globalDependencies." + exit 1 +else + echo "$NODE_VERSION" +fi diff --git a/.github/scripts/install_global_dependencies.sh b/.github/scripts/install_global_dependencies.sh deleted file mode 100755 index fd745a8677..0000000000 --- a/.github/scripts/install_global_dependencies.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -# File path for the package.json -PACKAGE_JSON_FILE="$PWD/package.json" - -# Ensure jq is installed for JSON parsing -if ! command -v jq &> /dev/null; then - echo "jq could not be found. Please install jq to parse JSON." - exit 1 -fi - -# Extract the rustc version from the globalDependencies in package.json -RUST_VERSION=$(jq -r '.azle.globalDependencies.rustc // empty' "$PACKAGE_JSON_FILE") - -if [[ -z "$RUST_VERSION" ]]; then - echo "Rust version not found in $PACKAGE_JSON_FILE" - exit 1 -fi - -# Install Rust using rustup with the extracted version -echo "Installing Rust version $RUST_VERSION" -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain "$RUST_VERSION" -source $HOME/.cargo/env - -rustup target add wasm32-wasi - -# Extract the wasi2ic version and repository URL from globalDependencies in package.json -WASI2IC_VERSION=$(jq -r '.azle.globalDependencies.wasi2ic // empty' "$PACKAGE_JSON_FILE") - -# Determine if WASI2IC_VERSION is a URL (repo) or just a version number -if [[ $WASI2IC_VERSION =~ ^https?:// ]]; then - WASI2IC_URL=$WASI2IC_VERSION -else - WASI2IC_URL="" -fi - -if [[ -z "$WASI2IC_VERSION" ]]; then - echo "wasi2ic version not found in $PACKAGE_JSON_FILE" - exit 1 -fi - -# Install wasi2ic -if [[ -n "$WASI2IC_URL" ]]; then - echo "Installing wasi2ic from repository $WASI2IC_URL" - cargo install --git "$WASI2IC_URL" -else - echo "Installing wasi2ic version $WASI2IC_VERSION" - cargo install wasi2ic --version "$WASI2IC_VERSION" -fi - -# Confirm installation -echo "\nThe following global dependencies were installed" -rustc --version -cargo --version - -rustup target list --installed | grep wasm32-wasi - -cargo install --list | grep wasi2ic diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 82e3f95461..405a744eb5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,7 +5,6 @@ on: - main pull_request: # Runs on pull requests to any branch env: - DFX_VERSION: 0.21.0 NODE_VERSION: 20 jobs: determine-should-release: @@ -66,11 +65,8 @@ jobs: run: sudo apt-get install curl -y - name: Install global dependencies - run: ./.github/scripts/install_global_dependencies.sh - - - name: Install dfx run: | - DFXVM_INIT_YES=true DFX_VERSION=${{ env.DFX_VERSION }} sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" + npx azle install-global-dependencies --rust --wasi2ic --dfx echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH # TODO we should use some Action-specific bot account diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 45e467a940..348553661e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,8 +10,6 @@ on: - main pull_request: # Runs on pull requests to any branch env: - DFX_VERSION: 0.22.0 - NODE_VERSION: 20 AZLE_IS_MAIN_BRANCH_PUSH: ${{ github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'demergent-labs/release--') }} AZLE_IS_MAIN_BRANCH_MERGE_FROM_RELEASE_PUSH: ${{ github.ref == 'refs/heads/main' && contains(github.event.head_commit.message, 'demergent-labs/release--') }} AZLE_IS_RELEASE_BRANCH_PR: ${{ startsWith(github.head_ref, 'release--') }} @@ -30,6 +28,19 @@ jobs: - id: determine-should-run-tests uses: ./.github/actions/should_release + get-node-version: + name: Get node version + runs-on: ubuntu-latest + outputs: + node-version: ${{ steps.get-node-version.outputs.node-version }} + steps: + - uses: actions/checkout@v4 + + - id: get-node-version + uses: ./.github/actions/get_node_version + - id: report + run: echo ${{steps.get-node-version.outputs.node-version}} + get-test-infos: name: Get test infos needs: determine-should-run-tests @@ -112,6 +123,7 @@ jobs: name: '${{matrix.tests.name}} | ${{matrix.tests.displayPath}} | ${{matrix.azle_source}}' needs: - determine-should-run-tests + - get-node-version - get-test-infos if: ${{ needs.determine-should-run-tests.outputs.should-run-tests == 'true' }} runs-on: ${{ matrix.os }} @@ -146,13 +158,13 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: ${{ env.NODE_VERSION }} + node-version: ${{ needs.get-node-version.outputs.node-version }} - name: Run pre-test Azle setup run: | # Install dfx - DFXVM_INIT_YES=true DFX_VERSION=${{ env.DFX_VERSION }} sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" + npx azle install-global-dependencies --dfx echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH # MacOS-specific DNS configuration From 999e308dd00649df8aa3bcce95fc74ecb008d803 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 17 Sep 2024 09:15:52 -0600 Subject: [PATCH 07/23] add get node-version to release --- .github/workflows/release.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 405a744eb5..0b56e2f234 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,8 +4,6 @@ on: branches: - main pull_request: # Runs on pull requests to any branch -env: - NODE_VERSION: 20 jobs: determine-should-release: if: ${{ startsWith(github.head_ref, 'release--') }} @@ -19,6 +17,21 @@ jobs: - id: determine-should-release uses: ./.github/actions/should_release + get-node-version: + needs: determine-should-release + if: ${{ startsWith(github.head_ref, 'release--') && needs.determine-should-release.outputs.should-release }} + name: Get node version + runs-on: ubuntu-latest + outputs: + node-version: ${{ steps.get-node-version.outputs.node-version }} + steps: + - uses: actions/checkout@v4 + + - id: get-node-version + uses: ./.github/actions/get_node_version + - id: report + run: echo ${{steps.get-node-version.outputs.node-version}} + get-test-infos: needs: determine-should-release if: ${{ startsWith(github.head_ref, 'release--') && needs.determine-should-release.outputs.should-release }} @@ -44,6 +57,7 @@ jobs: needs: - determine-should-release - get-test-infos + - get-node-version runs-on: ubuntu-latest env: GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }} # All commits must be verified @@ -56,7 +70,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: ${{ env.NODE_VERSION }} + node-version: ${{ needs.get-node-version.outputs.node-version }} registry-url: https://registry.npmjs.org env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From 6bb9d98909f36056b51323f5ffe26c92efbd972a Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Mon, 16 Sep 2024 19:29:24 -0600 Subject: [PATCH 08/23] fix install dfx --- .github/workflows/test.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 348553661e..b1d59ddf09 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -163,8 +163,16 @@ jobs: - name: Run pre-test Azle setup run: | + npm install + + if [[ "${{ matrix.azle_source }}" == "repo" ]]; then + npm link + fi + # Install dfx - npx azle install-global-dependencies --dfx + # Hey Jordan, can you help me figure out why this doesn't work? While we are at it, there is a weird error that happens when we npm install + # npx azle install-global-dependencies --dfx + node src/build/index.js install-global-dependencies --dfx echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH # MacOS-specific DNS configuration @@ -172,12 +180,6 @@ jobs: sudo networksetup -setdnsservers Ethernet 9.9.9.9 fi - npm install - - if [[ "${{ matrix.azle_source }}" == "repo" ]]; then - npm link - fi - npm run lint shell: bash -l {0} From 7d01636982eaace207e4dc2002bbbaac56231a00 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 17 Sep 2024 12:26:15 -0600 Subject: [PATCH 09/23] pass node version to get_test_infos --- .github/actions/get_test_infos/action.yml | 7 +++---- .github/workflows/release.yml | 5 ++++- .github/workflows/test.yml | 7 ++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/actions/get_test_infos/action.yml b/.github/actions/get_test_infos/action.yml index 9751ea0cbd..9d66d7ba09 100644 --- a/.github/actions/get_test_infos/action.yml +++ b/.github/actions/get_test_infos/action.yml @@ -9,6 +9,9 @@ description: displayPath: string // An abbreviated version of the path for display purposes only }' inputs: + node-version: + description: The version of Node.js to use + required: true directories: description: List of directories to search for npm projects with an npm test script required: true @@ -16,10 +19,6 @@ inputs: description: List of directories to exclude from the search required: false default: '' - node-version: - description: The version of Node.js to use - required: true - default: '20.x' outputs: test-infos: description: All of the test info objects found by this action diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0b56e2f234..a41ef88bea 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,7 +33,9 @@ jobs: run: echo ${{steps.get-node-version.outputs.node-version}} get-test-infos: - needs: determine-should-release + needs: + - determine-should-release + - get-node-version if: ${{ startsWith(github.head_ref, 'release--') && needs.determine-should-release.outputs.should-release }} name: Get test infos runs-on: ubuntu-latest @@ -46,6 +48,7 @@ jobs: id: get-test-infos uses: ./.github/actions/get_test_infos with: + node-version: ${{ needs.get-node-version.outputs.node-version }} directories: | ./examples ./tests diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b1d59ddf09..494bac2b25 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,12 +38,12 @@ jobs: - id: get-node-version uses: ./.github/actions/get_node_version - - id: report - run: echo ${{steps.get-node-version.outputs.node-version}} get-test-infos: name: Get test infos - needs: determine-should-run-tests + needs: + - determine-should-run-tests + - get-node-version if: ${{ needs.determine-should-run-tests.outputs.should-run-tests == 'true' }} runs-on: ubuntu-latest outputs: @@ -114,6 +114,7 @@ jobs: id: get-test-infos uses: ./.github/actions/get_test_infos with: + node-version: ${{ needs.get-node-version.outputs.node-version }} directories: | ./examples ./tests From 1c33d33eb7c6a7c5364ab6d361eab825f4f6626c Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 17 Sep 2024 13:41:51 -0600 Subject: [PATCH 10/23] install dfx with the right version --- .github/actions/get_dfx_version/action.yml | 16 +++++++++++++++ .../get_dfx_version/get_dfx_version.sh | 20 +++++++++++++++++++ .github/workflows/release.yml | 13 +++++++++++- .github/workflows/test.yml | 14 +++++++------ 4 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 .github/actions/get_dfx_version/action.yml create mode 100755 .github/actions/get_dfx_version/get_dfx_version.sh diff --git a/.github/actions/get_dfx_version/action.yml b/.github/actions/get_dfx_version/action.yml new file mode 100644 index 0000000000..2eef312300 --- /dev/null +++ b/.github/actions/get_dfx_version/action.yml @@ -0,0 +1,16 @@ +name: Get dfx version +description: Determines Azle's dfx version +outputs: + dfx-version: + description: Returns the version of dfx Azle used for it's last template + value: ${{ steps.get-dfx-version.outputs.dfx-version }} +runs: + using: composite + steps: + - uses: actions/checkout@v4 + + - id: get-dfx-version + run: | + DFX_VERSION=$(./.github/actions/get_dfx_version/get_dfx_version.sh) + echo "dfx-version=${DFX_VERSION}" >> "$GITHUB_OUTPUT" + shell: bash diff --git a/.github/actions/get_dfx_version/get_dfx_version.sh b/.github/actions/get_dfx_version/get_dfx_version.sh new file mode 100755 index 0000000000..ebf528cf34 --- /dev/null +++ b/.github/actions/get_dfx_version/get_dfx_version.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Path to package.json +PACKAGE_JSON_PATH="package.json" + +# Check if package.json exists +if [ ! -f "$PACKAGE_JSON_PATH" ]; then + echo "Error: $PACKAGE_JSON_PATH not found." + exit 1 +fi + +# Extract the Node.js version from globalDependencies +DFX_VERSION=$(jq -r '.azle.globalDependencies.dfx // empty' "$PACKAGE_JSON_PATH") + +if [ -z "$DFX_VERSION" ]; then + echo "dfx version not found in globalDependencies." + exit 1 +else + echo "$DFX_VERSION" +fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a41ef88bea..1c8cc61c0c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -81,9 +81,20 @@ jobs: - name: Install curl run: sudo apt-get install curl -y + - id: get-dfx-version + # TODO Hey Jordan, This is here to demonstrate two different ways of doing get node version and get dfx version. I think we should unify them, but I wanted to have both to see which you prefered + uses: ./.github/actions/get_dfx_version + + - name: Install dfx + run: | + + # Install dfx (Note: DFX must be installed before `npm install` because the azle instalation process required dfx) + # TODO if you want we could explore using the install script... it's kind of overkill and we would still have to supply the version. Though if dfinity ever changed their install script again it would be only one place we would have to update. This would apply to the installation in the test.yml as well + DFXVM_INIT_YES=true DFX_VERSION=${{ steps.get-dfx-version.outputs.dfx-version }} sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" + - name: Install global dependencies run: | - npx azle install-global-dependencies --rust --wasi2ic --dfx + npx azle install-global-dependencies --rust --wasi2ic echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH # TODO we should use some Action-specific bot account diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 494bac2b25..a41dc82092 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -161,21 +161,23 @@ jobs: with: node-version: ${{ needs.get-node-version.outputs.node-version }} + - id: get-dfx-version + # TODO Hey Jordan, This is here to demonstrate two different ways of doing get node version and get dfx version. I think we should unify them, but I wanted to have both to see which you prefered + uses: ./.github/actions/get_dfx_version + - name: Run pre-test Azle setup run: | + # Install dfx (Note: DFX must be installed before `npm install` because the azle instalation process required dfx) + DFXVM_INIT_YES=true DFX_VERSION=${{ steps.get-dfx-version.outputs.dfx-version }} sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" + echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH + npm install if [[ "${{ matrix.azle_source }}" == "repo" ]]; then npm link fi - # Install dfx - # Hey Jordan, can you help me figure out why this doesn't work? While we are at it, there is a weird error that happens when we npm install - # npx azle install-global-dependencies --dfx - node src/build/index.js install-global-dependencies --dfx - echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH - # MacOS-specific DNS configuration if [[ "${{ matrix.os }}" == "macos-latest" ]]; then sudo networksetup -setdnsservers Ethernet 9.9.9.9 From 858c1dd80586718f98e84277f487ab075f3d1f36 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 17 Sep 2024 14:54:45 -0600 Subject: [PATCH 11/23] put that thing back where it came from or so help me --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a41dc82092..2eca8eaa78 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -172,17 +172,17 @@ jobs: DFXVM_INIT_YES=true DFX_VERSION=${{ steps.get-dfx-version.outputs.dfx-version }} sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH + # MacOS-specific DNS configuration + if [[ "${{ matrix.os }}" == "macos-latest" ]]; then + sudo networksetup -setdnsservers Ethernet 9.9.9.9 + fi + npm install if [[ "${{ matrix.azle_source }}" == "repo" ]]; then npm link fi - # MacOS-specific DNS configuration - if [[ "${{ matrix.os }}" == "macos-latest" ]]; then - sudo networksetup -setdnsservers Ethernet 9.9.9.9 - fi - npm run lint shell: bash -l {0} From eacd8592faa98adf244083541bceb225f381facc Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 17 Sep 2024 15:13:07 -0600 Subject: [PATCH 12/23] update comments, update path to global dependencies --- .../commands/install_global_dependencies/index.ts | 12 +++--------- .../install_global_dependencies/install_dfx.sh | 3 --- .../install_global_dependencies/install_node.sh | 1 - .../install_global_dependencies/install_rust.sh | 1 - 4 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/build/stable/commands/install_global_dependencies/index.ts b/src/build/stable/commands/install_global_dependencies/index.ts index 1016f0ef24..2388143049 100644 --- a/src/build/stable/commands/install_global_dependencies/index.ts +++ b/src/build/stable/commands/install_global_dependencies/index.ts @@ -22,8 +22,6 @@ const validFlags = { wasi2ic: { name: 'wasi2ic', script: 'install_wasi2ic.sh' } }; -// TODO don't forget, we do want a separate script to get all of these versions so that we can run it as an action. We want this because we are not the ones that install node for the github workflows - export async function runCommand(ioType: IOType): Promise { // TODO Hey Jordan, I was noticing that for all of the other commands the handling of flags happens before we get to this point. // TODO I am guessing that is because of flags like experimental that apply to all of the commands? @@ -101,17 +99,13 @@ If no options are provided, all dependencies will be installed. } async function getGlobalDependencies(): Promise { - // Path to package.json const packageJsonPath = join(AZLE_PACKAGE_PATH, 'package.json'); - // Read the existing package.json file - const packageJsonContent = await readFile(packageJsonPath, 'utf-8'); - const packageJson = JSON.parse(packageJsonContent); + const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf-8')); - // Extract globalDependencies - const globalDependencies = packageJson.globalDependencies; + const globalDependencies = packageJson.azle.globalDependencies; - if (!globalDependencies) { + if (globalDependencies === undefined) { throw new Error('No globalDependencies found in package.json.'); } diff --git a/src/build/stable/commands/install_global_dependencies/install_dfx.sh b/src/build/stable/commands/install_global_dependencies/install_dfx.sh index 78c15e21f5..29e8b7c5bd 100755 --- a/src/build/stable/commands/install_global_dependencies/install_dfx.sh +++ b/src/build/stable/commands/install_global_dependencies/install_dfx.sh @@ -1,6 +1,5 @@ #!/bin/bash -# Ensure that a version argument is passed if [ -z "$1" ]; then echo "Error: No DFX version specified." echo "Usage: ./install_dfx.sh " @@ -9,14 +8,12 @@ fi DFX_VERSION=$1 -# Check if dfx is installed and its version if command -v dfx &> /dev/null; then INSTALLED_VERSION=$(npx tsx src/build/stable/utils/versions/dfx.ts 2>&1 | tr -d '[:space:]') echo "Installed dfx version: $INSTALLED_VERSION" echo "Requested dfx version: $DFX_VERSION" - # If the installed version matches the requested version, skip installation if [ "$INSTALLED_VERSION" = "$DFX_VERSION" ]; then echo "dfx $DFX_VERSION is already installed. No installation needed." exit 0 diff --git a/src/build/stable/commands/install_global_dependencies/install_node.sh b/src/build/stable/commands/install_global_dependencies/install_node.sh index 51a5799fd1..d2e67b998c 100755 --- a/src/build/stable/commands/install_global_dependencies/install_node.sh +++ b/src/build/stable/commands/install_global_dependencies/install_node.sh @@ -1,6 +1,5 @@ #!/bin/bash -# Ensure that a version argument is passed if [ -z "$1" ]; then echo "Error: No Node.js version specified." echo "Usage: ./install_node.sh " diff --git a/src/build/stable/commands/install_global_dependencies/install_rust.sh b/src/build/stable/commands/install_global_dependencies/install_rust.sh index bbb55dc549..4e20123c7b 100755 --- a/src/build/stable/commands/install_global_dependencies/install_rust.sh +++ b/src/build/stable/commands/install_global_dependencies/install_rust.sh @@ -8,7 +8,6 @@ fi RUST_VERSION=$1 -# Check if Rust is installed and its version if command -v rustc &> /dev/null; then INSTALLED_VERSION=$(npx tsx src/build/stable/utils/versions/rust.ts 2>&1 | tr -d '[:space:]') From 56fac07c4309823e9716255c7a3777d759bfd4c3 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Wed, 18 Sep 2024 09:58:56 -0600 Subject: [PATCH 13/23] update get node and get dfx versions to use ts --- .github/actions/get_dfx_version/action.yml | 16 ---------- .../get_dfx_version/get_dfx_version.sh | 20 ------------ .github/actions/get_node_version/action.yml | 6 ++-- .../get_node_version/get_node_version.sh | 20 ------------ .github/actions/get_node_version/index.ts | 18 +++++++++++ .github/workflows/release.yml | 32 +++++++------------ .github/workflows/test.yml | 28 +++++++--------- .../stable/utils/log_global_dependencies.ts | 4 +-- src/build/stable/utils/versions/dfx.ts | 21 +++++++----- .../versions/get_version_from_package_json.ts | 18 +++++++++++ 10 files changed, 77 insertions(+), 106 deletions(-) delete mode 100644 .github/actions/get_dfx_version/action.yml delete mode 100755 .github/actions/get_dfx_version/get_dfx_version.sh delete mode 100755 .github/actions/get_node_version/get_node_version.sh create mode 100644 .github/actions/get_node_version/index.ts create mode 100644 src/build/stable/utils/versions/get_version_from_package_json.ts diff --git a/.github/actions/get_dfx_version/action.yml b/.github/actions/get_dfx_version/action.yml deleted file mode 100644 index 2eef312300..0000000000 --- a/.github/actions/get_dfx_version/action.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Get dfx version -description: Determines Azle's dfx version -outputs: - dfx-version: - description: Returns the version of dfx Azle used for it's last template - value: ${{ steps.get-dfx-version.outputs.dfx-version }} -runs: - using: composite - steps: - - uses: actions/checkout@v4 - - - id: get-dfx-version - run: | - DFX_VERSION=$(./.github/actions/get_dfx_version/get_dfx_version.sh) - echo "dfx-version=${DFX_VERSION}" >> "$GITHUB_OUTPUT" - shell: bash diff --git a/.github/actions/get_dfx_version/get_dfx_version.sh b/.github/actions/get_dfx_version/get_dfx_version.sh deleted file mode 100755 index ebf528cf34..0000000000 --- a/.github/actions/get_dfx_version/get_dfx_version.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Path to package.json -PACKAGE_JSON_PATH="package.json" - -# Check if package.json exists -if [ ! -f "$PACKAGE_JSON_PATH" ]; then - echo "Error: $PACKAGE_JSON_PATH not found." - exit 1 -fi - -# Extract the Node.js version from globalDependencies -DFX_VERSION=$(jq -r '.azle.globalDependencies.dfx // empty' "$PACKAGE_JSON_PATH") - -if [ -z "$DFX_VERSION" ]; then - echo "dfx version not found in globalDependencies." - exit 1 -else - echo "$DFX_VERSION" -fi diff --git a/.github/actions/get_node_version/action.yml b/.github/actions/get_node_version/action.yml index e71d492733..0934b769f0 100644 --- a/.github/actions/get_node_version/action.yml +++ b/.github/actions/get_node_version/action.yml @@ -2,15 +2,17 @@ name: Get node version description: Determines Azle's node version outputs: node-version: - description: Returns the version of node Azle used for it's last template + description: Returns the version of node that Azle will test against and use to generate its Wasm binary template value: ${{ steps.get-node-version.outputs.node-version }} runs: using: composite steps: - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - id: get-node-version run: | - NODE_VERSION=$(./.github/actions/get_node_version/get_node_version.sh) + NODE_VERSION=$(npx tsx ./.github/actions/get_node_version/index.ts) echo "node-version=${NODE_VERSION}" >> "$GITHUB_OUTPUT" shell: bash diff --git a/.github/actions/get_node_version/get_node_version.sh b/.github/actions/get_node_version/get_node_version.sh deleted file mode 100755 index 03e0419835..0000000000 --- a/.github/actions/get_node_version/get_node_version.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Path to package.json -PACKAGE_JSON_PATH="package.json" - -# Check if package.json exists -if [ ! -f "$PACKAGE_JSON_PATH" ]; then - echo "Error: $PACKAGE_JSON_PATH not found." - exit 1 -fi - -# Extract the Node.js version from globalDependencies -NODE_VERSION=$(jq -r '.azle.globalDependencies.node // empty' "$PACKAGE_JSON_PATH") - -if [ -z "$NODE_VERSION" ]; then - echo "Node.js version not found in globalDependencies." - exit 1 -else - echo "$NODE_VERSION" -fi diff --git a/.github/actions/get_node_version/index.ts b/.github/actions/get_node_version/index.ts new file mode 100644 index 0000000000..8a73acad46 --- /dev/null +++ b/.github/actions/get_node_version/index.ts @@ -0,0 +1,18 @@ +import { pathToFileURL } from 'url'; +import { readFileSync } from 'fs'; + +function main(): void { + const packageJson = JSON.parse(readFileSync('package.json', 'utf-8')); + + const version = packageJson?.azle?.globalDependencies?.node; + + if (version !== undefined) { + process.stdout.write(version); + } else { + throw new Error(`node version not found in azle.globalDependencies`); + } +} + +if (import.meta.url === pathToFileURL(process.argv[1]).href) { + main(); +} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c8cc61c0c..4776d221d1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,25 +17,9 @@ jobs: - id: determine-should-release uses: ./.github/actions/should_release - get-node-version: - needs: determine-should-release - if: ${{ startsWith(github.head_ref, 'release--') && needs.determine-should-release.outputs.should-release }} - name: Get node version - runs-on: ubuntu-latest - outputs: - node-version: ${{ steps.get-node-version.outputs.node-version }} - steps: - - uses: actions/checkout@v4 - - - id: get-node-version - uses: ./.github/actions/get_node_version - - id: report - run: echo ${{steps.get-node-version.outputs.node-version}} - get-test-infos: needs: - determine-should-release - - get-node-version if: ${{ startsWith(github.head_ref, 'release--') && needs.determine-should-release.outputs.should-release }} name: Get test infos runs-on: ubuntu-latest @@ -44,11 +28,14 @@ jobs: steps: - uses: actions/checkout@v4 + - id: get-node-version + uses: ./.github/actions/get_node_version + - name: Get all test infos id: get-test-infos uses: ./.github/actions/get_test_infos with: - node-version: ${{ needs.get-node-version.outputs.node-version }} + node-version: ${{ steps.get-node-version.outputs.node-version }} directories: | ./examples ./tests @@ -60,7 +47,6 @@ jobs: needs: - determine-should-release - get-test-infos - - get-node-version runs-on: ubuntu-latest env: GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }} # All commits must be verified @@ -71,9 +57,12 @@ jobs: ref: ${{ github.event.pull_request.head.ref || github.ref }} token: ${{ secrets.LASTMJS_GITHUB_TOKEN || github.token }} + - id: get-node-version + uses: ./.github/actions/get_node_version + - uses: actions/setup-node@v4 with: - node-version: ${{ needs.get-node-version.outputs.node-version }} + node-version: ${{ steps.get-node-version.outputs.node-version }} registry-url: https://registry.npmjs.org env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} @@ -82,8 +71,9 @@ jobs: run: sudo apt-get install curl -y - id: get-dfx-version - # TODO Hey Jordan, This is here to demonstrate two different ways of doing get node version and get dfx version. I think we should unify them, but I wanted to have both to see which you prefered - uses: ./.github/actions/get_dfx_version + run: | + DFX_VERSION=$(npx tsx ./src/build/stable/utils/versions/dfx.ts) + echo "dfx-version=${DFX_VERSION}" >> "$GITHUB_OUTPUT" - name: Install dfx run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2eca8eaa78..554eb669a3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,22 +28,10 @@ jobs: - id: determine-should-run-tests uses: ./.github/actions/should_release - get-node-version: - name: Get node version - runs-on: ubuntu-latest - outputs: - node-version: ${{ steps.get-node-version.outputs.node-version }} - steps: - - uses: actions/checkout@v4 - - - id: get-node-version - uses: ./.github/actions/get_node_version - get-test-infos: name: Get test infos needs: - determine-should-run-tests - - get-node-version if: ${{ needs.determine-should-run-tests.outputs.should-run-tests == 'true' }} runs-on: ubuntu-latest outputs: @@ -51,6 +39,9 @@ jobs: steps: - uses: actions/checkout@v4 + - id: get-node-version + uses: ./.github/actions/get_node_version + - name: Set exclude dirs id: set-exclude-dirs run: | @@ -114,7 +105,7 @@ jobs: id: get-test-infos uses: ./.github/actions/get_test_infos with: - node-version: ${{ needs.get-node-version.outputs.node-version }} + node-version: ${{ steps.get-node-version.outputs.node-version }} directories: | ./examples ./tests @@ -124,7 +115,6 @@ jobs: name: '${{matrix.tests.name}} | ${{matrix.tests.displayPath}} | ${{matrix.azle_source}}' needs: - determine-should-run-tests - - get-node-version - get-test-infos if: ${{ needs.determine-should-run-tests.outputs.should-run-tests == 'true' }} runs-on: ${{ matrix.os }} @@ -157,13 +147,17 @@ jobs: - uses: actions/checkout@v4 + - id: get-node-version + uses: ./.github/actions/get_node_version + - uses: actions/setup-node@v4 with: - node-version: ${{ needs.get-node-version.outputs.node-version }} + node-version: ${{ steps.get-node-version.outputs.node-version }} - id: get-dfx-version - # TODO Hey Jordan, This is here to demonstrate two different ways of doing get node version and get dfx version. I think we should unify them, but I wanted to have both to see which you prefered - uses: ./.github/actions/get_dfx_version + run: | + DFX_VERSION=$(npx tsx ./src/build/stable/utils/versions/dfx.ts) + echo "dfx-version=${DFX_VERSION}" >> "$GITHUB_OUTPUT" - name: Run pre-test Azle setup run: | diff --git a/src/build/stable/utils/log_global_dependencies.ts b/src/build/stable/utils/log_global_dependencies.ts index 2072781c74..200f82e479 100644 --- a/src/build/stable/utils/log_global_dependencies.ts +++ b/src/build/stable/utils/log_global_dependencies.ts @@ -2,7 +2,7 @@ import { readFile, writeFile } from 'fs/promises'; import { join } from 'path'; import { AZLE_PACKAGE_PATH } from './global_paths'; -import { getDfxVersion } from './versions/dfx'; +import { getDfxVersionLocal } from './versions/dfx'; import { getNodeVersion } from './versions/node'; import { getRustVersion } from './versions/rust'; import { getWasiVersion } from './versions/wasi2ic'; @@ -11,7 +11,7 @@ export async function logGlobalDependencies(): Promise { const wasiVersion = getWasiVersion(); const nodeVersion = getNodeVersion(); const rustVersion = getRustVersion(); - const dfxVersion = getDfxVersion(); + const dfxVersion = getDfxVersionLocal(); const globalDependencies = { wasi2ic: wasiVersion, diff --git a/src/build/stable/utils/versions/dfx.ts b/src/build/stable/utils/versions/dfx.ts index dddd528355..9d72033d2a 100644 --- a/src/build/stable/utils/versions/dfx.ts +++ b/src/build/stable/utils/versions/dfx.ts @@ -1,8 +1,9 @@ import { pathToFileURL } from 'url'; import { execSyncPretty } from '../exec_sync_pretty'; +import { getVersionFromPackageJson } from './get_version_from_package_json'; -export function getDfxVersion(): string { +export function getDfxVersionLocal(): string { const dfxOutput = execSyncPretty('dfx --version').toString().trim(); const match = dfxOutput.match(/dfx (\d+\.\d+\.\d+)/); @@ -14,13 +15,17 @@ export function getDfxVersion(): string { } } -function main(): void { - try { - const version = getDfxVersion(); - console.log(version); - } catch (error: any) { - console.error(error.message); - process.exit(1); +export async function getDfxVersionPackageJson(): Promise { + return await getVersionFromPackageJson('dfx'); +} + +async function main(): Promise { + const args = process.argv.slice(2); + + if (args.includes('--local')) { + process.stdout.write(getDfxVersionLocal()); + } else { + process.stdout.write(await getDfxVersionPackageJson()); } } diff --git a/src/build/stable/utils/versions/get_version_from_package_json.ts b/src/build/stable/utils/versions/get_version_from_package_json.ts new file mode 100644 index 0000000000..dddb63fdab --- /dev/null +++ b/src/build/stable/utils/versions/get_version_from_package_json.ts @@ -0,0 +1,18 @@ +import { readFile } from 'fs/promises'; +import { join } from 'path'; + +import { AZLE_PACKAGE_PATH } from '../global_paths'; + +export async function getVersionFromPackageJson(name: string): Promise { + const packageJson = JSON.parse( + await readFile(join(AZLE_PACKAGE_PATH, 'package.json'), 'utf-8') + ); + + const version = packageJson?.azle?.globalDependencies[name]; + + if (version !== undefined) { + return version; + } else { + throw new Error(`${name} version not found in azle.globalDependencies`); + } +} From 17672b805e806bb03945034e4cba7d274766368f Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Wed, 18 Sep 2024 10:25:42 -0600 Subject: [PATCH 14/23] simplify install global dependencies flags --- src/build/index.ts | 17 +++- .../install_global_dependencies/index.ts | 92 ++++--------------- 2 files changed, 32 insertions(+), 77 deletions(-) diff --git a/src/build/index.ts b/src/build/index.ts index c96eb8bb0e..85ff7fcaba 100755 --- a/src/build/index.ts +++ b/src/build/index.ts @@ -139,7 +139,22 @@ async function handleTemplateCommand(ioType: IOType): Promise { async function handleInstallGlobalDependenciesCommand( ioType: IOType ): Promise { - await runInstallGlobalDependenciesCommand(ioType); + const node = process.argv.includes('--node'); + const dfx = process.argv.includes('--dfx'); + const rustc = process.argv.includes('--rust'); + const wasi2ic = process.argv.includes('--wasi2ic'); + + if (!node && !dfx && !rustc && !wasi2ic) { + await runInstallGlobalDependenciesCommand( + { dfx: true, node: true, rustc: true, wasi2ic: true }, + ioType + ); + } else { + await runInstallGlobalDependenciesCommand( + { dfx, node, rustc, wasi2ic }, + ioType + ); + } } async function handleNewCommand(): Promise { diff --git a/src/build/stable/commands/install_global_dependencies/index.ts b/src/build/stable/commands/install_global_dependencies/index.ts index 2388143049..0600e06101 100644 --- a/src/build/stable/commands/install_global_dependencies/index.ts +++ b/src/build/stable/commands/install_global_dependencies/index.ts @@ -5,99 +5,39 @@ import { join } from 'path'; import { execSyncPretty } from '../../utils/exec_sync_pretty'; import { AZLE_PACKAGE_PATH } from '../../utils/global_paths'; +type ValidFlag = 'node' | 'dfx' | 'rustc' | 'wasi2ic'; + type Versions = { [key in ValidFlag]: string; }; -type ValidFlag = 'node' | 'dfx' | 'rustc' | 'wasi2ic'; - -// TODO Hey Jordan, I'm not wild about the package property name, but it works for now -// TODO for that matter the whole idea of package is a little odd. We only need it for rust. I suppose we could just make the flag --rustc and then we wouldn't have to worry about it. I'm just worried if rustc is a lest obvious flag name -// TODO though on the other hand, we do have a nice little usage message that would let them know right away that it was wrong. -// TODO Hey Jordan, Is it too much to stipulate for future dependencies that the install script is install_${name}? Then we wouldn't have to specify the script here -const validFlags = { - node: { name: 'Node.js', script: 'install_node.sh' }, - dfx: { name: 'DFX', script: 'install_dfx.sh' }, - rustc: { name: 'Rust', script: 'install_rust.sh' }, - wasi2ic: { name: 'wasi2ic', script: 'install_wasi2ic.sh' } +type Dependencies = { + [key in ValidFlag]: boolean; }; -export async function runCommand(ioType: IOType): Promise { - // TODO Hey Jordan, I was noticing that for all of the other commands the handling of flags happens before we get to this point. - // TODO I am guessing that is because of flags like experimental that apply to all of the commands? - // TODO We could modify this so that instead of grabbing the args right here, we could pass the already parsed args as a list. - // TODO We can talk about validating those flags here or where we parse them. On the one hand I think it would be good to be consistent - // TODO On the other hand I think it would be nice to make sure the index.ts file that handles the routing is as lite as possible - // TODO For right now I will leave it like this because it is already like this - // TODO Hey Jordan, on the topic of processing flags before hand. This approach does install things as we are processing flags. So if an invalid flag is in the middle of the list then it will fail after it has successfully installed some dependencies and not others. Maybe we do want to process before we get to this point anyways? - const args = process.argv.slice(3); - const installAll = args.length === 0; - - const versions = await getGlobalDependencies(); - - if (installAll) { - // Install everything if no specific flags are provided - for (const flag in validFlags) { - const { name, script } = validFlags[flag as ValidFlag]; - const version = versions[flag as ValidFlag]; - installDependency(name, script, version, ioType); - } - } else { - // Install dependencies based on provided flags - for (const arg of args) { - const flag = arg.slice(2); - const flagConfig = validFlags[flag as ValidFlag]; - - if (flagConfig !== undefined) { - const { name, script } = flagConfig; - const version = versions[flag as ValidFlag]; - installDependency(name, script, version, ioType); - } else { - console.error(`Unrecognized option: ${arg}`); - printUsage(); - process.exit(1); - } - } +export async function runCommand( + dependencies: Dependencies, + ioType: IOType +): Promise { + for (const key in dependencies) { + const dependency = key as ValidFlag; + if (dependencies[dependency]) installDependency(dependency, ioType); } } -function installDependency( - dependency: string, - script: string, - version: string, +async function installDependency( + dependency: ValidFlag, ioType: IOType -): void { +): Promise { console.info(`Installing ${dependency}...`); + const version = (await getGlobalDependencies())[dependency]; + const script = `install_${dependency}.sh`; execSyncPretty( `${AZLE_PACKAGE_PATH}/src/build/stable/commands/install_global_dependencies/${script} ${version}`, ioType ); } -function printUsage(): void { - // Find the longest flag for dynamic spacing - const longestFlagLength = Math.max( - ...Object.keys(validFlags).map((flag) => flag.length) - ); - - console.info(` -Usage: npx azle install-global-dependencies [options] - -Options: -`); - for (const flag in validFlags) { - const padding = ' '.repeat(longestFlagLength - flag.length); - console.info( - ` --${flag}${padding} Install ${ - validFlags[flag as ValidFlag].name - } dependencies` - ); - } - console.info(` -If no options are provided, all dependencies will be installed. -`); -} - async function getGlobalDependencies(): Promise { const packageJsonPath = join(AZLE_PACKAGE_PATH, 'package.json'); From 162a010729e54438fa9491f75dd5aad4ca0916d7 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Wed, 18 Sep 2024 10:33:44 -0600 Subject: [PATCH 15/23] clean up --- .github/workflows/release.yml | 3 +-- .github/workflows/test.yml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4776d221d1..5438413201 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,8 +18,7 @@ jobs: uses: ./.github/actions/should_release get-test-infos: - needs: - - determine-should-release + needs: determine-should-release if: ${{ startsWith(github.head_ref, 'release--') && needs.determine-should-release.outputs.should-release }} name: Get test infos runs-on: ubuntu-latest diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 554eb669a3..1db6d4e1fd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,8 +30,7 @@ jobs: get-test-infos: name: Get test infos - needs: - - determine-should-run-tests + needs: determine-should-run-tests if: ${{ needs.determine-should-run-tests.outputs.should-run-tests == 'true' }} runs-on: ubuntu-latest outputs: From a91c30c77215b042b9def00b68664c0a58344352 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Wed, 18 Sep 2024 10:38:50 -0600 Subject: [PATCH 16/23] write directly to stdout --- src/build/stable/utils/log_global_dependencies.ts | 12 ++++++------ src/build/stable/utils/versions/node.ts | 10 ++-------- src/build/stable/utils/versions/rust.ts | 10 ++-------- src/build/stable/utils/versions/wasi2ic.ts | 10 ++-------- 4 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/build/stable/utils/log_global_dependencies.ts b/src/build/stable/utils/log_global_dependencies.ts index 200f82e479..27676e0eae 100644 --- a/src/build/stable/utils/log_global_dependencies.ts +++ b/src/build/stable/utils/log_global_dependencies.ts @@ -3,14 +3,14 @@ import { join } from 'path'; import { AZLE_PACKAGE_PATH } from './global_paths'; import { getDfxVersionLocal } from './versions/dfx'; -import { getNodeVersion } from './versions/node'; -import { getRustVersion } from './versions/rust'; -import { getWasiVersion } from './versions/wasi2ic'; +import { getNodeVersionLocal } from './versions/node'; +import { getRustVersionLocal } from './versions/rust'; +import { getWasi2icVersionLocal } from './versions/wasi2ic'; export async function logGlobalDependencies(): Promise { - const wasiVersion = getWasiVersion(); - const nodeVersion = getNodeVersion(); - const rustVersion = getRustVersion(); + const wasiVersion = getWasi2icVersionLocal(); + const nodeVersion = getNodeVersionLocal(); + const rustVersion = getRustVersionLocal(); const dfxVersion = getDfxVersionLocal(); const globalDependencies = { diff --git a/src/build/stable/utils/versions/node.ts b/src/build/stable/utils/versions/node.ts index 907c87d304..a1593edabf 100644 --- a/src/build/stable/utils/versions/node.ts +++ b/src/build/stable/utils/versions/node.ts @@ -2,7 +2,7 @@ import { pathToFileURL } from 'url'; import { execSyncPretty } from '../exec_sync_pretty'; -export function getNodeVersion(): string { +export function getNodeVersionLocal(): string { const nodeOutput = execSyncPretty('node --version').toString().trim(); const match = nodeOutput.match(/^v(\d+\.\d+\.\d+)/); @@ -14,13 +14,7 @@ export function getNodeVersion(): string { } function main(): void { - try { - const version = getNodeVersion(); - console.log(version); - } catch (error: any) { - console.error(error.message); - process.exit(1); - } + process.stdout.write(getNodeVersionLocal()); } if (import.meta.url === pathToFileURL(process.argv[1]).href) { diff --git a/src/build/stable/utils/versions/rust.ts b/src/build/stable/utils/versions/rust.ts index e3ec773bd7..c18b37ca17 100644 --- a/src/build/stable/utils/versions/rust.ts +++ b/src/build/stable/utils/versions/rust.ts @@ -2,7 +2,7 @@ import { pathToFileURL } from 'url'; import { execSyncPretty } from '../exec_sync_pretty'; -export function getRustVersion(): string { +export function getRustVersionLocal(): string { const rustcOutput = execSyncPretty('rustc --version').toString().trim(); const match = rustcOutput.match(/^rustc\s+(\d+\.\d+\.\d+)/); @@ -14,13 +14,7 @@ export function getRustVersion(): string { } function main(): void { - try { - const version = getRustVersion(); - console.log(version); - } catch (error: any) { - console.error(error.message); - process.exit(1); - } + process.stdout.write(getRustVersionLocal()); } if (import.meta.url === pathToFileURL(process.argv[1]).href) { diff --git a/src/build/stable/utils/versions/wasi2ic.ts b/src/build/stable/utils/versions/wasi2ic.ts index 50bf801966..15f4698d28 100644 --- a/src/build/stable/utils/versions/wasi2ic.ts +++ b/src/build/stable/utils/versions/wasi2ic.ts @@ -2,7 +2,7 @@ import { pathToFileURL } from 'url'; import { execSyncPretty } from '../exec_sync_pretty'; -export function getWasiVersion(): string { +export function getWasi2icVersionLocal(): string { return getCargoVersion('wasi2ic'); } @@ -27,13 +27,7 @@ function getCargoVersion(packageName: string): string { } function main(): void { - try { - const version = getWasiVersion(); - console.log(version); - } catch (error: any) { - console.error(error.message); - process.exit(1); - } + process.stdout.write(getWasi2icVersionLocal()); } if (import.meta.url === pathToFileURL(process.argv[1]).href) { From d624c21c1af7c95fe5040086da2ac286016d3743 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Wed, 18 Sep 2024 11:11:52 -0600 Subject: [PATCH 17/23] use bash where acceptable --- .github/actions/get_dfx_version/action.yml | 16 ++++++++++++++ .github/actions/get_node_version/action.yml | 4 +--- .github/actions/get_node_version/index.ts | 18 --------------- .github/workflows/release.yml | 10 +++------ .github/workflows/test.yml | 8 +++---- .../install_node.sh | 22 +------------------ 6 files changed, 24 insertions(+), 54 deletions(-) create mode 100644 .github/actions/get_dfx_version/action.yml delete mode 100644 .github/actions/get_node_version/index.ts diff --git a/.github/actions/get_dfx_version/action.yml b/.github/actions/get_dfx_version/action.yml new file mode 100644 index 0000000000..1acb4e5fad --- /dev/null +++ b/.github/actions/get_dfx_version/action.yml @@ -0,0 +1,16 @@ +name: Get dfx version +description: Determines Azle's dfx version +outputs: + dfx-version: + description: Returns the version of dfx that Azle will test against and use to generate its Wasm binary template + value: ${{ steps.get-dfx-version.outputs.dfx-version }} +runs: + using: composite + steps: + - uses: actions/checkout@v4 + + - id: get-dfx-version + run: | + DFX_VERSION=$(jq -r '.azle.globalDependencies.dfx // error("dfx version not found")' "package.json") + echo "dfx-version=${DFX_VERSION}" >> "$GITHUB_OUTPUT" + shell: bash diff --git a/.github/actions/get_node_version/action.yml b/.github/actions/get_node_version/action.yml index 0934b769f0..262c7adc50 100644 --- a/.github/actions/get_node_version/action.yml +++ b/.github/actions/get_node_version/action.yml @@ -9,10 +9,8 @@ runs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - - id: get-node-version run: | - NODE_VERSION=$(npx tsx ./.github/actions/get_node_version/index.ts) + NODE_VERSION=$(jq -r '.azle.globalDependencies.node // error("node version not found")' "package.json") echo "node-version=${NODE_VERSION}" >> "$GITHUB_OUTPUT" shell: bash diff --git a/.github/actions/get_node_version/index.ts b/.github/actions/get_node_version/index.ts deleted file mode 100644 index 8a73acad46..0000000000 --- a/.github/actions/get_node_version/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { pathToFileURL } from 'url'; -import { readFileSync } from 'fs'; - -function main(): void { - const packageJson = JSON.parse(readFileSync('package.json', 'utf-8')); - - const version = packageJson?.azle?.globalDependencies?.node; - - if (version !== undefined) { - process.stdout.write(version); - } else { - throw new Error(`node version not found in azle.globalDependencies`); - } -} - -if (import.meta.url === pathToFileURL(process.argv[1]).href) { - main(); -} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5438413201..5a34e24018 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -70,16 +70,12 @@ jobs: run: sudo apt-get install curl -y - id: get-dfx-version - run: | - DFX_VERSION=$(npx tsx ./src/build/stable/utils/versions/dfx.ts) - echo "dfx-version=${DFX_VERSION}" >> "$GITHUB_OUTPUT" + uses: ./.github/actions/get_dfx_version - name: Install dfx run: | - - # Install dfx (Note: DFX must be installed before `npm install` because the azle instalation process required dfx) - # TODO if you want we could explore using the install script... it's kind of overkill and we would still have to supply the version. Though if dfinity ever changed their install script again it would be only one place we would have to update. This would apply to the installation in the test.yml as well - DFXVM_INIT_YES=true DFX_VERSION=${{ steps.get-dfx-version.outputs.dfx-version }} sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" + # Install dfx (Note: DFX must be installed before `npx azle` because the azle instalation process requires dfx) + src/build/stable/commands/install_global_dependencies/install_dfx.sh ${{ steps.get-dfx-version.outputs.dfx-version }} - name: Install global dependencies run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1db6d4e1fd..ca53608ff3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -154,15 +154,13 @@ jobs: node-version: ${{ steps.get-node-version.outputs.node-version }} - id: get-dfx-version - run: | - DFX_VERSION=$(npx tsx ./src/build/stable/utils/versions/dfx.ts) - echo "dfx-version=${DFX_VERSION}" >> "$GITHUB_OUTPUT" + uses: ./.github/actions/get_dfx_version - name: Run pre-test Azle setup run: | - # Install dfx (Note: DFX must be installed before `npm install` because the azle instalation process required dfx) - DFXVM_INIT_YES=true DFX_VERSION=${{ steps.get-dfx-version.outputs.dfx-version }} sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" + # Install dfx (Note: DFX must be installed before `npm install` because the azle instalation process requires dfx) + src/build/stable/commands/install_global_dependencies/install_dfx.sh ${{ steps.get-dfx-version.outputs.dfx-version }} echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH # MacOS-specific DNS configuration diff --git a/src/build/stable/commands/install_global_dependencies/install_node.sh b/src/build/stable/commands/install_global_dependencies/install_node.sh index d2e67b998c..4bc72bbd7a 100755 --- a/src/build/stable/commands/install_global_dependencies/install_node.sh +++ b/src/build/stable/commands/install_global_dependencies/install_node.sh @@ -8,27 +8,7 @@ fi NODE_VERSION=$1 -# Load nvm if it's installed -if [ -s "$HOME/.nvm/nvm.sh" ]; then - source "$HOME/.nvm/nvm.sh" -elif [ -s "/usr/local/opt/nvm/nvm.sh" ]; then - # Fallback for macOS/Homebrew installation path - source "/usr/local/opt/nvm/nvm.sh" -else - echo "nvm is not installed." -fi - -# Check if nvm is installed -if ! command -v nvm &> /dev/null; then - echo "nvm is not installed. Installing nvm..." - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash - - # Load nvm into the shell (necessary for the script to use nvm after installation) - export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm -else - echo "nvm is already installed." -fi +source "$HOME/.nvm/nvm.sh" if nvm ls "$NODE_VERSION" &> /dev/null; then echo "Node.js version $NODE_VERSION is already installed. Skipping installation." From 2fff8edaa8834fe37853cf17e9f8d2ec80f077ee Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Wed, 18 Sep 2024 11:17:50 -0600 Subject: [PATCH 18/23] make more declarative --- .../install_global_dependencies/index.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/build/stable/commands/install_global_dependencies/index.ts b/src/build/stable/commands/install_global_dependencies/index.ts index 0600e06101..827397ef5f 100644 --- a/src/build/stable/commands/install_global_dependencies/index.ts +++ b/src/build/stable/commands/install_global_dependencies/index.ts @@ -5,28 +5,30 @@ import { join } from 'path'; import { execSyncPretty } from '../../utils/exec_sync_pretty'; import { AZLE_PACKAGE_PATH } from '../../utils/global_paths'; -type ValidFlag = 'node' | 'dfx' | 'rustc' | 'wasi2ic'; +type DependencyName = 'node' | 'dfx' | 'rustc' | 'wasi2ic'; type Versions = { - [key in ValidFlag]: string; + [key in DependencyName]: string; }; type Dependencies = { - [key in ValidFlag]: boolean; + [key in DependencyName]: boolean; }; export async function runCommand( - dependencies: Dependencies, + dependenciesToInstall: Dependencies, ioType: IOType ): Promise { - for (const key in dependencies) { - const dependency = key as ValidFlag; - if (dependencies[dependency]) installDependency(dependency, ioType); + for (const key in dependenciesToInstall) { + const dependency = key as DependencyName; + if (dependenciesToInstall[dependency] === true) { + installDependency(dependency, ioType); + } } } async function installDependency( - dependency: ValidFlag, + dependency: DependencyName, ioType: IOType ): Promise { console.info(`Installing ${dependency}...`); From 5962aa3efbd616653778a8116dd4bceacd11a07b Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Wed, 18 Sep 2024 14:47:22 -0600 Subject: [PATCH 19/23] fix path name for rust installation --- .github/workflows/release.yml | 2 +- .../{install_rust.sh => install_rustc.sh} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/build/stable/commands/install_global_dependencies/{install_rust.sh => install_rustc.sh} (100%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5a34e24018..77d1e9a3b5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -79,7 +79,7 @@ jobs: - name: Install global dependencies run: | - npx azle install-global-dependencies --rust --wasi2ic + AZLE_VERBOSE=true npx azle install-global-dependencies --rust --wasi2ic echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH # TODO we should use some Action-specific bot account diff --git a/src/build/stable/commands/install_global_dependencies/install_rust.sh b/src/build/stable/commands/install_global_dependencies/install_rustc.sh similarity index 100% rename from src/build/stable/commands/install_global_dependencies/install_rust.sh rename to src/build/stable/commands/install_global_dependencies/install_rustc.sh From 4157c5d6166c282deeced95a2f991a5cf258c04c Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Thu, 19 Sep 2024 10:33:03 -0600 Subject: [PATCH 20/23] install azle before global dependencies --- .github/workflows/release.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 77d1e9a3b5..20945b47e5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -76,11 +76,13 @@ jobs: run: | # Install dfx (Note: DFX must be installed before `npx azle` because the azle instalation process requires dfx) src/build/stable/commands/install_global_dependencies/install_dfx.sh ${{ steps.get-dfx-version.outputs.dfx-version }} + echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH + + - run: npm install - name: Install global dependencies run: | AZLE_VERBOSE=true npx azle install-global-dependencies --rust --wasi2ic - echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH # TODO we should use some Action-specific bot account - name: Configure git for publishing release From 2f5c439bc75b736b025ffe2d523c80c6980e8969 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Thu, 19 Sep 2024 14:44:32 -0600 Subject: [PATCH 21/23] change from rustc to rust --- package.json | 2 +- src/build/index.ts | 8 ++++---- .../stable/commands/install_global_dependencies/index.ts | 2 +- src/build/stable/utils/log_global_dependencies.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index f1f165f2d3..7632b3fe75 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "globalDependencies": { "wasi2ic": "https://github.com/wasm-forge/wasi2ic?rev=806c3558aad24224852a9582f018178402cb3679#806c3558", "node": "20.11.0", - "rustc": "1.80.1", + "rust": "1.80.1", "dfx": "0.22.0" } } diff --git a/src/build/index.ts b/src/build/index.ts index 85ff7fcaba..5d4022dc5f 100755 --- a/src/build/index.ts +++ b/src/build/index.ts @@ -141,17 +141,17 @@ async function handleInstallGlobalDependenciesCommand( ): Promise { const node = process.argv.includes('--node'); const dfx = process.argv.includes('--dfx'); - const rustc = process.argv.includes('--rust'); + const rust = process.argv.includes('--rust'); const wasi2ic = process.argv.includes('--wasi2ic'); - if (!node && !dfx && !rustc && !wasi2ic) { + if (!node && !dfx && !rust && !wasi2ic) { await runInstallGlobalDependenciesCommand( - { dfx: true, node: true, rustc: true, wasi2ic: true }, + { dfx: true, node: true, rust: true, wasi2ic: true }, ioType ); } else { await runInstallGlobalDependenciesCommand( - { dfx, node, rustc, wasi2ic }, + { dfx, node, rust, wasi2ic }, ioType ); } diff --git a/src/build/stable/commands/install_global_dependencies/index.ts b/src/build/stable/commands/install_global_dependencies/index.ts index 827397ef5f..fe3b328251 100644 --- a/src/build/stable/commands/install_global_dependencies/index.ts +++ b/src/build/stable/commands/install_global_dependencies/index.ts @@ -5,7 +5,7 @@ import { join } from 'path'; import { execSyncPretty } from '../../utils/exec_sync_pretty'; import { AZLE_PACKAGE_PATH } from '../../utils/global_paths'; -type DependencyName = 'node' | 'dfx' | 'rustc' | 'wasi2ic'; +type DependencyName = 'node' | 'dfx' | 'rust' | 'wasi2ic'; type Versions = { [key in DependencyName]: string; diff --git a/src/build/stable/utils/log_global_dependencies.ts b/src/build/stable/utils/log_global_dependencies.ts index 27676e0eae..5f02c41227 100644 --- a/src/build/stable/utils/log_global_dependencies.ts +++ b/src/build/stable/utils/log_global_dependencies.ts @@ -16,7 +16,7 @@ export async function logGlobalDependencies(): Promise { const globalDependencies = { wasi2ic: wasiVersion, node: nodeVersion, - rustc: rustVersion, + rust: rustVersion, dfx: dfxVersion }; From 8bab7a981c9447ef5d5d48c4cecfcdfd68b8a274 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Thu, 19 Sep 2024 14:48:02 -0600 Subject: [PATCH 22/23] rename install rust script --- .../{install_rustc.sh => install_rust.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/build/stable/commands/install_global_dependencies/{install_rustc.sh => install_rust.sh} (100%) diff --git a/src/build/stable/commands/install_global_dependencies/install_rustc.sh b/src/build/stable/commands/install_global_dependencies/install_rust.sh similarity index 100% rename from src/build/stable/commands/install_global_dependencies/install_rustc.sh rename to src/build/stable/commands/install_global_dependencies/install_rust.sh From dce9262d79da9fdd9f971b92ff2607802d8c8329 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Thu, 19 Sep 2024 15:58:17 -0600 Subject: [PATCH 23/23] pr fixes --- .github/actions/get_dfx_version/action.yml | 2 +- .github/actions/get_node_version/action.yml | 2 +- .github/workflows/test.yml | 2 +- .../install_global_dependencies/index.ts | 32 +++---------------- .../install_dfx.sh | 16 ---------- .../install_node.sh | 1 + .../install_rust.sh | 16 ---------- .../install_wasi2ic.sh | 16 ---------- .../stable/utils/log_global_dependencies.ts | 16 +++++----- src/build/stable/utils/versions/dfx.ts | 23 +------------ .../versions/get_version_from_package_json.ts | 18 ----------- src/build/stable/utils/versions/node.ts | 12 +------ src/build/stable/utils/versions/rust.ts | 12 +------ src/build/stable/utils/versions/wasi2ic.ts | 12 +------ 14 files changed, 21 insertions(+), 159 deletions(-) delete mode 100644 src/build/stable/utils/versions/get_version_from_package_json.ts diff --git a/.github/actions/get_dfx_version/action.yml b/.github/actions/get_dfx_version/action.yml index 1acb4e5fad..92f68b5baa 100644 --- a/.github/actions/get_dfx_version/action.yml +++ b/.github/actions/get_dfx_version/action.yml @@ -2,7 +2,7 @@ name: Get dfx version description: Determines Azle's dfx version outputs: dfx-version: - description: Returns the version of dfx that Azle will test against and use to generate its Wasm binary template + description: Returns the version of dfx that Azle will test against and use to generate its Wasm binary templates value: ${{ steps.get-dfx-version.outputs.dfx-version }} runs: using: composite diff --git a/.github/actions/get_node_version/action.yml b/.github/actions/get_node_version/action.yml index 262c7adc50..eadb0684f6 100644 --- a/.github/actions/get_node_version/action.yml +++ b/.github/actions/get_node_version/action.yml @@ -2,7 +2,7 @@ name: Get node version description: Determines Azle's node version outputs: node-version: - description: Returns the version of node that Azle will test against and use to generate its Wasm binary template + description: Returns the version of node that Azle will test against and use to generate its Wasm binary templates value: ${{ steps.get-node-version.outputs.node-version }} runs: using: composite diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ca53608ff3..586f8cf843 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -159,7 +159,7 @@ jobs: - name: Run pre-test Azle setup run: | - # Install dfx (Note: DFX must be installed before `npm install` because the azle instalation process requires dfx) + # Install dfx (Note: DFX must be installed before `npm install` because the azle installation process requires dfx) src/build/stable/commands/install_global_dependencies/install_dfx.sh ${{ steps.get-dfx-version.outputs.dfx-version }} echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH diff --git a/src/build/stable/commands/install_global_dependencies/index.ts b/src/build/stable/commands/install_global_dependencies/index.ts index fe3b328251..9a0d7040cf 100644 --- a/src/build/stable/commands/install_global_dependencies/index.ts +++ b/src/build/stable/commands/install_global_dependencies/index.ts @@ -1,22 +1,17 @@ import { IOType } from 'child_process'; -import { readFile } from 'fs/promises'; -import { join } from 'path'; +import { azle } from '../../../../../package.json'; import { execSyncPretty } from '../../utils/exec_sync_pretty'; import { AZLE_PACKAGE_PATH } from '../../utils/global_paths'; type DependencyName = 'node' | 'dfx' | 'rust' | 'wasi2ic'; -type Versions = { - [key in DependencyName]: string; -}; - -type Dependencies = { +type DependencyInstallInfo = { [key in DependencyName]: boolean; }; export async function runCommand( - dependenciesToInstall: Dependencies, + dependenciesToInstall: DependencyInstallInfo, ioType: IOType ): Promise { for (const key in dependenciesToInstall) { @@ -27,29 +22,12 @@ export async function runCommand( } } -async function installDependency( - dependency: DependencyName, - ioType: IOType -): Promise { +function installDependency(dependency: DependencyName, ioType: IOType): void { console.info(`Installing ${dependency}...`); - const version = (await getGlobalDependencies())[dependency]; + const version = azle.globalDependencies[dependency]; const script = `install_${dependency}.sh`; execSyncPretty( `${AZLE_PACKAGE_PATH}/src/build/stable/commands/install_global_dependencies/${script} ${version}`, ioType ); } - -async function getGlobalDependencies(): Promise { - const packageJsonPath = join(AZLE_PACKAGE_PATH, 'package.json'); - - const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf-8')); - - const globalDependencies = packageJson.azle.globalDependencies; - - if (globalDependencies === undefined) { - throw new Error('No globalDependencies found in package.json.'); - } - - return globalDependencies; -} diff --git a/src/build/stable/commands/install_global_dependencies/install_dfx.sh b/src/build/stable/commands/install_global_dependencies/install_dfx.sh index 29e8b7c5bd..e957673178 100755 --- a/src/build/stable/commands/install_global_dependencies/install_dfx.sh +++ b/src/build/stable/commands/install_global_dependencies/install_dfx.sh @@ -8,22 +8,6 @@ fi DFX_VERSION=$1 -if command -v dfx &> /dev/null; then - INSTALLED_VERSION=$(npx tsx src/build/stable/utils/versions/dfx.ts 2>&1 | tr -d '[:space:]') - - echo "Installed dfx version: $INSTALLED_VERSION" - echo "Requested dfx version: $DFX_VERSION" - - if [ "$INSTALLED_VERSION" = "$DFX_VERSION" ]; then - echo "dfx $DFX_VERSION is already installed. No installation needed." - exit 0 - else - echo "Updating dfx from version $INSTALLED_VERSION to $DFX_VERSION" - fi -else - echo "dfx is not installed. Proceeding with installation of dfx $DFX_VERSION." -fi - # Install or update dfx using the official installation script echo "Installing dfx version $DFX_VERSION..." DFXVM_INIT_YES=true DFX_VERSION=$DFX_VERSION sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" diff --git a/src/build/stable/commands/install_global_dependencies/install_node.sh b/src/build/stable/commands/install_global_dependencies/install_node.sh index 4bc72bbd7a..93b55f7625 100755 --- a/src/build/stable/commands/install_global_dependencies/install_node.sh +++ b/src/build/stable/commands/install_global_dependencies/install_node.sh @@ -17,6 +17,7 @@ else echo "Installing Node.js version $NODE_VERSION..." nvm install "$NODE_VERSION" nvm use "$NODE_VERSION" + nvm alias default "$NODE_VERSION" echo "Node.js $NODE_VERSION installation completed." fi diff --git a/src/build/stable/commands/install_global_dependencies/install_rust.sh b/src/build/stable/commands/install_global_dependencies/install_rust.sh index 4e20123c7b..45091a8c7e 100755 --- a/src/build/stable/commands/install_global_dependencies/install_rust.sh +++ b/src/build/stable/commands/install_global_dependencies/install_rust.sh @@ -8,22 +8,6 @@ fi RUST_VERSION=$1 -if command -v rustc &> /dev/null; then - INSTALLED_VERSION=$(npx tsx src/build/stable/utils/versions/rust.ts 2>&1 | tr -d '[:space:]') - - echo "Installed Rust version: $INSTALLED_VERSION" - echo "Requested Rust version: $RUST_VERSION" - - if [ "$INSTALLED_VERSION" = "$RUST_VERSION" ]; then - echo "Rust $RUST_VERSION is already installed. No installation needed." - exit 0 - else - echo "Updating Rust from version $INSTALLED_VERSION to $RUST_VERSION" - fi -else - echo "Rust is not installed. Proceeding with installation of Rust $RUST_VERSION." -fi - # Install Rust echo "Installing Rust version $RUST_VERSION..." curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain "$RUST_VERSION" diff --git a/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh b/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh index 7a4b78a27d..3124a4e330 100755 --- a/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh +++ b/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh @@ -15,22 +15,6 @@ else WASI2IC_URL="" fi -if command -v wasi2ic &> /dev/null; then - INSTALLED_VERSION=$(npx tsx src/build/stable/utils/versions/wasi2ic.ts 2>&1 | tr -d '[:space:]') - - echo "Installed wasi2ic version: $INSTALLED_VERSION" - echo "Requested wasi2ic version: $WASI2IC_VERSION" - - if [ "$INSTALLED_VERSION" = "$WASI2IC_VERSION" ]; then - echo "wasi2ic $WASI2IC_VERSION is already installed. No installation needed." - exit 0 - else - echo "Updating wasi2ic from version $INSTALLED_VERSION to $WASI2IC_VERSION" - fi -else - echo "wasi2ic is not installed. Proceeding with installation." -fi - # Install or update wasi2ic if [[ -n "$WASI2IC_URL" ]]; then echo "Installing wasi2ic from repository $WASI2IC_URL" diff --git a/src/build/stable/utils/log_global_dependencies.ts b/src/build/stable/utils/log_global_dependencies.ts index 5f02c41227..ac67caf065 100644 --- a/src/build/stable/utils/log_global_dependencies.ts +++ b/src/build/stable/utils/log_global_dependencies.ts @@ -2,16 +2,16 @@ import { readFile, writeFile } from 'fs/promises'; import { join } from 'path'; import { AZLE_PACKAGE_PATH } from './global_paths'; -import { getDfxVersionLocal } from './versions/dfx'; -import { getNodeVersionLocal } from './versions/node'; -import { getRustVersionLocal } from './versions/rust'; -import { getWasi2icVersionLocal } from './versions/wasi2ic'; +import { getLocalDfxVersion } from './versions/dfx'; +import { getLocalNodeVersion } from './versions/node'; +import { getLocalRustVersion } from './versions/rust'; +import { getLocalWasi2icVersion } from './versions/wasi2ic'; export async function logGlobalDependencies(): Promise { - const wasiVersion = getWasi2icVersionLocal(); - const nodeVersion = getNodeVersionLocal(); - const rustVersion = getRustVersionLocal(); - const dfxVersion = getDfxVersionLocal(); + const wasiVersion = getLocalWasi2icVersion(); + const nodeVersion = getLocalNodeVersion(); + const rustVersion = getLocalRustVersion(); + const dfxVersion = getLocalDfxVersion(); const globalDependencies = { wasi2ic: wasiVersion, diff --git a/src/build/stable/utils/versions/dfx.ts b/src/build/stable/utils/versions/dfx.ts index 9d72033d2a..d5a8f7e763 100644 --- a/src/build/stable/utils/versions/dfx.ts +++ b/src/build/stable/utils/versions/dfx.ts @@ -1,9 +1,6 @@ -import { pathToFileURL } from 'url'; - import { execSyncPretty } from '../exec_sync_pretty'; -import { getVersionFromPackageJson } from './get_version_from_package_json'; -export function getDfxVersionLocal(): string { +export function getLocalDfxVersion(): string { const dfxOutput = execSyncPretty('dfx --version').toString().trim(); const match = dfxOutput.match(/dfx (\d+\.\d+\.\d+)/); @@ -14,21 +11,3 @@ export function getDfxVersionLocal(): string { throw new Error('Could not parse the dfx version'); } } - -export async function getDfxVersionPackageJson(): Promise { - return await getVersionFromPackageJson('dfx'); -} - -async function main(): Promise { - const args = process.argv.slice(2); - - if (args.includes('--local')) { - process.stdout.write(getDfxVersionLocal()); - } else { - process.stdout.write(await getDfxVersionPackageJson()); - } -} - -if (import.meta.url === pathToFileURL(process.argv[1]).href) { - main(); -} diff --git a/src/build/stable/utils/versions/get_version_from_package_json.ts b/src/build/stable/utils/versions/get_version_from_package_json.ts deleted file mode 100644 index dddb63fdab..0000000000 --- a/src/build/stable/utils/versions/get_version_from_package_json.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { readFile } from 'fs/promises'; -import { join } from 'path'; - -import { AZLE_PACKAGE_PATH } from '../global_paths'; - -export async function getVersionFromPackageJson(name: string): Promise { - const packageJson = JSON.parse( - await readFile(join(AZLE_PACKAGE_PATH, 'package.json'), 'utf-8') - ); - - const version = packageJson?.azle?.globalDependencies[name]; - - if (version !== undefined) { - return version; - } else { - throw new Error(`${name} version not found in azle.globalDependencies`); - } -} diff --git a/src/build/stable/utils/versions/node.ts b/src/build/stable/utils/versions/node.ts index a1593edabf..0f045f0aa9 100644 --- a/src/build/stable/utils/versions/node.ts +++ b/src/build/stable/utils/versions/node.ts @@ -1,8 +1,6 @@ -import { pathToFileURL } from 'url'; - import { execSyncPretty } from '../exec_sync_pretty'; -export function getNodeVersionLocal(): string { +export function getLocalNodeVersion(): string { const nodeOutput = execSyncPretty('node --version').toString().trim(); const match = nodeOutput.match(/^v(\d+\.\d+\.\d+)/); @@ -12,11 +10,3 @@ export function getNodeVersionLocal(): string { throw new Error('Could not parse node version'); } } - -function main(): void { - process.stdout.write(getNodeVersionLocal()); -} - -if (import.meta.url === pathToFileURL(process.argv[1]).href) { - main(); -} diff --git a/src/build/stable/utils/versions/rust.ts b/src/build/stable/utils/versions/rust.ts index c18b37ca17..faa5b58650 100644 --- a/src/build/stable/utils/versions/rust.ts +++ b/src/build/stable/utils/versions/rust.ts @@ -1,8 +1,6 @@ -import { pathToFileURL } from 'url'; - import { execSyncPretty } from '../exec_sync_pretty'; -export function getRustVersionLocal(): string { +export function getLocalRustVersion(): string { const rustcOutput = execSyncPretty('rustc --version').toString().trim(); const match = rustcOutput.match(/^rustc\s+(\d+\.\d+\.\d+)/); @@ -12,11 +10,3 @@ export function getRustVersionLocal(): string { throw new Error('Could not parse rustc version'); } } - -function main(): void { - process.stdout.write(getRustVersionLocal()); -} - -if (import.meta.url === pathToFileURL(process.argv[1]).href) { - main(); -} diff --git a/src/build/stable/utils/versions/wasi2ic.ts b/src/build/stable/utils/versions/wasi2ic.ts index 15f4698d28..23d5a6db20 100644 --- a/src/build/stable/utils/versions/wasi2ic.ts +++ b/src/build/stable/utils/versions/wasi2ic.ts @@ -1,8 +1,6 @@ -import { pathToFileURL } from 'url'; - import { execSyncPretty } from '../exec_sync_pretty'; -export function getWasi2icVersionLocal(): string { +export function getLocalWasi2icVersion(): string { return getCargoVersion('wasi2ic'); } @@ -25,11 +23,3 @@ function getCargoVersion(packageName: string): string { throw new Error(`Could not parse ${packageName} version`); } } - -function main(): void { - process.stdout.write(getWasi2icVersionLocal()); -} - -if (import.meta.url === pathToFileURL(process.argv[1]).href) { - main(); -}