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 f1a6ab99de..a9a61060f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -104,15 +104,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."