From 2779949852e12f0e8aae88ea7478b46cf5c3cede Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 17 Sep 2024 13:41:51 -0600 Subject: [PATCH] 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 7508f24372..2286e31ab1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -111,21 +111,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