Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Install global dependencies #2098

Merged
merged 24 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 template
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
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 template
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
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
bdemann marked this conversation as resolved.
Show resolved Hide resolved
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 instalation process requires dfx)
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
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"
"rustc": "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 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<void> {
const experimental = process.argv.includes('--experimental');
const httpServer = process.argv.includes('--http-server');
Expand Down
55 changes: 55 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,55 @@
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 DependencyName = 'node' | 'dfx' | 'rustc' | 'wasi2ic';
lastmjs marked this conversation as resolved.
Show resolved Hide resolved

bdemann marked this conversation as resolved.
Show resolved Hide resolved
type Versions = {
[key in DependencyName]: string;
};

type Dependencies = {
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
[key in DependencyName]: boolean;
};

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

async function installDependency(
dependency: DependencyName,
ioType: IOType
): Promise<void> {
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
);
}

async function getGlobalDependencies(): Promise<Versions> {
lastmjs marked this conversation as resolved.
Show resolved Hide resolved
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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
bdemann marked this conversation as resolved.
Show resolved Hide resolved

bdemann marked this conversation as resolved.
Show resolved Hide resolved
if [ -z "$1" ]; then
echo "Error: No DFX version specified."
echo "Usage: ./install_dfx.sh <DFX_VERSION>"
exit 1
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:]')
lastmjs marked this conversation as resolved.
Show resolved Hide resolved

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)"

echo "dfx $DFX_VERSION installation completed."
exit 0
Loading
Loading