Skip to content

Commit

Permalink
Merge pull request #2098 from demergent-labs/install_global_dependencies
Browse files Browse the repository at this point in the history
Install global dependencies
  • Loading branch information
lastmjs authored Sep 19, 2024
2 parents a30d90f + dce9262 commit d15234a
Show file tree
Hide file tree
Showing 19 changed files with 296 additions and 126 deletions.
16 changes: 16 additions & 0 deletions .github/actions/get_dfx_version/action.yml
Original file line number Diff line number Diff line change
@@ -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 templates
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
16 changes: 16 additions & 0 deletions .github/actions/get_node_version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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 templates
value: ${{ steps.get-node-version.outputs.node-version }}
runs:
using: composite
steps:
- uses: actions/checkout@v4

- id: get-node-version
run: |
NODE_VERSION=$(jq -r '.azle.globalDependencies.node // error("node version not found")' "package.json")
echo "node-version=${NODE_VERSION}" >> "$GITHUB_OUTPUT"
shell: bash
7 changes: 3 additions & 4 deletions .github/actions/get_test_infos/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ 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
exclude-dirs:
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
Expand Down
58 changes: 0 additions & 58 deletions .github/scripts/install_global_dependencies.sh

This file was deleted.

25 changes: 18 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
branches:
- main
pull_request: # Runs on pull requests to any branch
env:
DFX_VERSION: 0.21.0
NODE_VERSION: 20
jobs:
determine-should-release:
if: ${{ startsWith(github.head_ref, 'release--') }}
Expand All @@ -30,10 +27,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: ${{ steps.get-node-version.outputs.node-version }}
directories: |
./examples
./tests
Expand All @@ -55,24 +56,34 @@ 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: ${{ env.NODE_VERSION }}
node-version: ${{ steps.get-node-version.outputs.node-version }}
registry-url: https://registry.npmjs.org
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Install curl
run: sudo apt-get install curl -y

- name: Install global dependencies
run: ./.github/scripts/install_global_dependencies.sh
- id: get-dfx-version
uses: ./.github/actions/get_dfx_version

- name: Install dfx
run: |
DFXVM_INIT_YES=true DFX_VERSION=${{ env.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 }}
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
# TODO we should use some Action-specific bot account
- name: Configure git for publishing release
run: |
Expand Down
18 changes: 13 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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--') }}
Expand Down Expand Up @@ -40,6 +38,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: |
Expand Down Expand Up @@ -103,6 +104,7 @@ jobs:
id: get-test-infos
uses: ./.github/actions/get_test_infos
with:
node-version: ${{ steps.get-node-version.outputs.node-version }}
directories: |
./examples
./tests
Expand Down Expand Up @@ -144,15 +146,21 @@ jobs:

- uses: actions/checkout@v4

- id: get-node-version
uses: ./.github/actions/get_node_version

- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
node-version: ${{ steps.get-node-version.outputs.node-version }}

- id: get-dfx-version
uses: ./.github/actions/get_dfx_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)"
# 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
# MacOS-specific DNS configuration
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"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"
}
}
}
28 changes: 28 additions & 0 deletions src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -38,6 +39,12 @@ async function build(): Promise<void> {
return;
}

if (command === 'install-global-dependencies') {
handleInstallGlobalDependenciesCommand(ioType);

return;
}

if (command === 'upload-assets') {
await handleUploadAssetsCommand();

Expand Down Expand Up @@ -129,6 +136,27 @@ async function handleTemplateCommand(ioType: IOType): Promise<void> {
}
}

async function handleInstallGlobalDependenciesCommand(
ioType: IOType
): Promise<void> {
const node = process.argv.includes('--node');
const dfx = process.argv.includes('--dfx');
const rust = process.argv.includes('--rust');
const wasi2ic = process.argv.includes('--wasi2ic');

if (!node && !dfx && !rust && !wasi2ic) {
await runInstallGlobalDependenciesCommand(
{ dfx: true, node: true, rust: true, wasi2ic: true },
ioType
);
} else {
await runInstallGlobalDependenciesCommand(
{ dfx, node, rust, wasi2ic },
ioType
);
}
}

async function handleNewCommand(): Promise<void> {
const experimental = process.argv.includes('--experimental');
const httpServer = process.argv.includes('--http-server');
Expand Down
33 changes: 33 additions & 0 deletions src/build/stable/commands/install_global_dependencies/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { IOType } from 'child_process';

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 DependencyInstallInfo = {
[key in DependencyName]: boolean;
};

export async function runCommand(
dependenciesToInstall: DependencyInstallInfo,
ioType: IOType
): Promise<void> {
for (const key in dependenciesToInstall) {
const dependency = key as DependencyName;
if (dependenciesToInstall[dependency] === true) {
installDependency(dependency, ioType);
}
}
}

function installDependency(dependency: DependencyName, ioType: IOType): void {
console.info(`Installing ${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
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

if [ -z "$1" ]; then
echo "Error: No DFX version specified."
echo "Usage: ./install_dfx.sh <DFX_VERSION>"
exit 1
fi

DFX_VERSION=$1

# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

if [ -z "$1" ]; then
echo "Error: No Node.js version specified."
echo "Usage: ./install_node.sh <NODE_VERSION>"
exit 1
fi

NODE_VERSION=$1

source "$HOME/.nvm/nvm.sh"

if nvm ls "$NODE_VERSION" &> /dev/null; then
echo "Node.js version $NODE_VERSION is already installed. Skipping installation."
nvm use "$NODE_VERSION"
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

node --version
exit 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

if [ -z "$1" ]; then
echo "Error: No Rust version specified."
echo "Usage: ./install_rust.sh <RUST_VERSION>"
exit 1
fi

RUST_VERSION=$1

# 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
Loading

0 comments on commit d15234a

Please sign in to comment.