From be640ea0bd487ad104ff2414b933a1eaaa1979fe Mon Sep 17 00:00:00 2001 From: Jonathan Tran Date: Mon, 10 Mar 2025 14:53:43 -0400 Subject: [PATCH] ci: Fix e2e workflow to install rust toolchain when needed (#5728) * ci: Fix e2e workflow to install rust toolchain when needed * Unify conditions * Pull out condition to variable * Add echo so that debuggin is easier --- .github/workflows/build-and-store-wasm.yml | 16 +++++--- .github/workflows/build-apps.yml | 17 ++++++--- .github/workflows/e2e-tests.yml | 44 ++++++++++++++-------- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build-and-store-wasm.yml b/.github/workflows/build-and-store-wasm.yml index 32e39e508..8adbc934e 100644 --- a/.github/workflows/build-and-store-wasm.yml +++ b/.github/workflows/build-and-store-wasm.yml @@ -16,15 +16,21 @@ jobs: cache: 'yarn' - name: Install dependencies run: yarn - - name: Setup Rust - uses: dtolnay/rust-toolchain@stable - - name: Cache wasm - uses: Swatinem/rust-cache@v2 + - name: Use correct Rust toolchain + shell: bash + run: | + cp --update=none rust/rust-toolchain.toml ./ || true + - name: Install rust + uses: actions-rust-lang/setup-rust-toolchain@v1 with: - workspaces: './rust' + cache: false # Configured below. - uses: taiki-e/install-action@955a6ff1416eae278c9f833008a9beb4b7f9afe3 with: tool: wasm-pack + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + with: + workspaces: rust - name: build wasm run: yarn build:wasm diff --git a/.github/workflows/build-apps.yml b/.github/workflows/build-apps.yml index 8daa0e74b..f51f66b29 100644 --- a/.github/workflows/build-apps.yml +++ b/.github/workflows/build-apps.yml @@ -33,18 +33,25 @@ jobs: - run: yarn install - - name: Setup Rust - uses: dtolnay/rust-toolchain@stable - - - uses: Swatinem/rust-cache@v2 + - name: Use correct Rust toolchain + shell: bash + run: | + cp --update=none rust/rust-toolchain.toml ./ || true + - name: Install rust + uses: actions-rust-lang/setup-rust-toolchain@v1 with: - workspaces: './rust' + cache: false # Configured below. # TODO: see if we can fetch from main instead if no diff at rust - uses: taiki-e/install-action@955a6ff1416eae278c9f833008a9beb4b7f9afe3 with: tool: wasm-pack + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + with: + workspaces: rust + - name: Run build:wasm run: "yarn build:wasm" diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 5b915ef6f..e5ca22335 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -135,19 +135,35 @@ jobs: shell: bash run: cp rust/kcl-wasm-lib/pkg/kcl_wasm_lib_bg.wasm public continue-on-error: true - - name: Setup Rust - if: ${{ needs.conditions.outputs.should-run == 'true' }} - uses: dtolnay/rust-toolchain@stable + - name: Build WASM condition + id: wasm + if: needs.conditions.outputs.should-run == 'true' + shell: bash + run: | + set -euox pipefail + # Build wasm if this is a scheduled run, there are Rust changes, or + # downloading from the wasm cache failed. + if [[ ${{github.event_name}} == 'schedule' || ${{steps.filter.outputs.rust}} == 'true' || ${{steps.download-wasm.outcome}} == 'failure' ]]; then + echo "should-build-wasm=true" >> $GITHUB_OUTPUT + else + echo "should-build-wasm=false" >> $GITHUB_OUTPUT + fi + - name: Use correct Rust toolchain + if: ${{ needs.conditions.outputs.should-run == 'true' && steps.wasm.outputs.should-build-wasm == 'true' }} + shell: bash + run: | + cp --update=none rust/rust-toolchain.toml ./ || true + - name: Install rust + if: ${{ needs.conditions.outputs.should-run == 'true' && steps.wasm.outputs.should-build-wasm == 'true' }} + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + cache: false # Configured below. - uses: taiki-e/install-action@955a6ff1416eae278c9f833008a9beb4b7f9afe3 + if: ${{ needs.conditions.outputs.should-run == 'true' && steps.wasm.outputs.should-build-wasm == 'true' }} with: tool: wasm-pack - - name: Cache Wasm (because rust diff) - if: ${{ needs.conditions.outputs.should-run == 'true' && (github.event_name == 'schedule' || steps.filter.outputs.rust == 'true') }} - uses: Swatinem/rust-cache@v2 - with: - workspaces: './rust' - - name: OR Cache Wasm (because wasm cache failed) - if: ${{ needs.conditions.outputs.should-run == 'true' && steps.download-wasm.outcome == 'failure' }} + - name: Rust Cache + if: ${{ needs.conditions.outputs.should-run == 'true' && steps.wasm.outputs.should-build-wasm == 'true' }} uses: Swatinem/rust-cache@v2 with: workspaces: './rust' @@ -174,12 +190,8 @@ jobs: sed -i "s#GH_ACTIONS_AXIOM_TOKEN#${{secrets.GH_ACTIONS_AXIOM_TOKEN}}#g" /tmp/vector.toml cat /tmp/vector.toml ${HOME}/.vector/bin/vector --config /tmp/vector.toml & - - name: Build Wasm (because rust diff) - if: ${{ needs.conditions.outputs.should-run == 'true' && (github.event_name == 'schedule' || steps.filter.outputs.rust == 'true') }} - shell: bash - run: yarn build:wasm - - name: OR Build Wasm (because wasm cache failed) - if: ${{ needs.conditions.outputs.should-run == 'true' && steps.download-wasm.outcome == 'failure' }} + - name: Build Wasm + if: ${{ needs.conditions.outputs.should-run == 'true' && steps.wasm.outputs.should-build-wasm == 'true' }} shell: bash run: yarn build:wasm - name: build web