diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml new file mode 100644 index 000000000..58bf7209f --- /dev/null +++ b/.github/workflows/build-wasm.yml @@ -0,0 +1,56 @@ +name: Build WASM + +on: + workflow_call: + +permissions: + contents: read + +jobs: + npm-build-wasm: + runs-on: runs-on=${{ github.run_id }}/family=i7ie.2xlarge/image=ubuntu22-full-x64 + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + cache: 'npm' + + - name: Install dependencies + run: npm install + + - name: Use correct Rust toolchain + shell: bash + run: | + [ -e rust-toolchain.toml ] || cp rust/rust-toolchain.toml ./ + + - name: Install rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + cache: false # configured below + + - uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc + with: + tool: wasm-pack + + - name: Use Rust cache + uses: Swatinem/rust-cache@v2 + with: + workspaces: './rust' + + - name: Build Wasm + shell: bash + run: npm run build:wasm + + - uses: actions/upload-artifact@v4 + with: + name: prepared-wasm + path: | + rust/kcl-wasm-lib/pkg/kcl_wasm_lib* + + - uses: actions/upload-artifact@v4 + with: + name: prepared-ts-rs-bindings + path: | + rust/kcl-lib/bindings/* diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index cf581934a..31a140249 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -28,53 +28,7 @@ jobs: - run: npm run fmt:check npm-build-wasm: - # Build the wasm blob once on the fastest runner. - runs-on: runs-on=${{ github.run_id }}/family=i7ie.2xlarge/image=ubuntu22-full-x64 - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - cache: 'npm' - - - name: Install dependencies - run: npm install - - - name: Use correct Rust toolchain - shell: bash - run: | - [ -e rust-toolchain.toml ] || cp rust/rust-toolchain.toml ./ - - - name: Install rust - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - cache: false # Configured below. - - - uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc - with: - tool: wasm-pack - - - name: Rust Cache - uses: Swatinem/rust-cache@v2 - with: - workspaces: './rust' - - - name: Build Wasm - shell: bash - run: npm run build:wasm - - - uses: actions/upload-artifact@v4 - with: - name: prepared-wasm - path: | - rust/kcl-wasm-lib/pkg/kcl_wasm_lib* - - - uses: actions/upload-artifact@v4 - with: - name: prepared-ts-rs-bindings - path: | - rust/kcl-lib/bindings/* + uses: ./.github/workflows/build-wasm.yml npm-tsc: runs-on: ubuntu-latest @@ -224,71 +178,3 @@ jobs: run: npm run test:unit:kcl-samples env: VITE_KC_DEV_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }} - - npm-unit-test: - runs-on: ubuntu-latest - needs: npm-build-wasm - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - cache: 'npm' - - - run: npm install - - uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc - with: - tool: wasm-pack - - - name: Download all artifacts - uses: actions/download-artifact@v4 - - - name: Copy prepared wasm - run: | - ls -R prepared-wasm - cp prepared-wasm/kcl_wasm_lib_bg.wasm public - mkdir rust/kcl-wasm-lib/pkg - cp prepared-wasm/kcl_wasm_lib* rust/kcl-wasm-lib/pkg - - - name: Copy prepared ts-rs bindings - run: | - ls -R prepared-ts-rs-bindings - mkdir rust/kcl-lib/bindings - cp -r prepared-ts-rs-bindings/* rust/kcl-lib/bindings/ - - - run: npm run simpleserver:bg - if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }} - - - name: Install Chromium Browser - if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }} - run: npm run playwright install chromium --with-deps - - - name: Run unit tests - if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }} - run: xvfb-run -a npm run test:unit - env: - VITE_KC_DEV_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }} - - - name: Check for changes - if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }} - id: git-check - run: | - git add src/lang/std/artifactMapGraphs - if git status src/lang/std/artifactMapGraphs | grep -q "Changes to be committed" - then echo "modified=true" >> $GITHUB_OUTPUT - else echo "modified=false" >> $GITHUB_OUTPUT - fi - - name: Commit changes, if any - if: ${{ github.event_name != 'release' && github.event_name != 'schedule' && steps.git-check.outputs.modified == 'true' }} - run: | - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - git remote set-url origin https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git - git fetch origin - echo ${{ github.head_ref }} - git checkout ${{ github.head_ref }} - # TODO when webkit works on ubuntu remove the os part of the commit message - git commit -am "Look at this (photo)Graph *in the voice of Nickelback*" || true - git push - git push origin ${{ github.head_ref }} diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 000000000..2998b4519 --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,124 @@ +name: Unit Tests + +on: + pull_request: + push: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: write + pull-requests: write + actions: read + +jobs: + npm-build-wasm: + uses: ./.github/workflows/build-wasm.yml + + npm-test-unit: + runs-on: ubuntu-latest + needs: npm-build-wasm + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + cache: 'npm' + + - run: npm install + - uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc + with: + tool: wasm-pack + + - name: Download all artifacts + uses: actions/download-artifact@v4 + + - name: Copy prepared wasm + run: | + ls -R prepared-wasm + cp prepared-wasm/kcl_wasm_lib_bg.wasm public + mkdir rust/kcl-wasm-lib/pkg + cp prepared-wasm/kcl_wasm_lib* rust/kcl-wasm-lib/pkg + + - name: Copy prepared ts-rs bindings + run: | + ls -R prepared-ts-rs-bindings + mkdir rust/kcl-lib/bindings + cp -r prepared-ts-rs-bindings/* rust/kcl-lib/bindings/ + + - run: npm run simpleserver:bg + if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }} + + - name: Install Chromium Browser + if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }} + run: npm run playwright install chromium --with-deps + + - name: Run unit tests + if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }} + run: xvfb-run -a npm run test:unit + env: + VITE_KC_DEV_TOKEN: ${{ secrets.KITTYCAD_API_TOKEN_DEV }} + + - name: Check for changes + if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }} + id: git-check + run: | + git add src/lang/std/artifactMapGraphs + if git status src/lang/std/artifactMapGraphs | grep -q "Changes to be committed" + then echo "modified=true" >> $GITHUB_OUTPUT + else echo "modified=false" >> $GITHUB_OUTPUT + fi + + - name: Commit changes, if any + if: ${{ github.event_name != 'release' && github.event_name != 'schedule' && steps.git-check.outputs.modified == 'true' }} + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git remote set-url origin https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git + git fetch origin + echo ${{ github.head_ref }} + git checkout ${{ github.head_ref }} + # TODO when webkit works on ubuntu remove the os part of the commit message + git commit -am "Look at this (photo)Graph *in the voice of Nickelback*" || true + git push + git push origin ${{ github.head_ref }} + + npm-test-unit-components: + runs-on: ubuntu-latest + needs: npm-build-wasm + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + cache: 'npm' + + - run: npm install + - uses: taiki-e/install-action@d4635f2de61c8b8104d59cd4aede2060638378cc + with: + tool: wasm-pack + + - name: Download all artifacts + uses: actions/download-artifact@v4 + + - name: Copy prepared wasm + run: | + ls -R prepared-wasm + cp prepared-wasm/kcl_wasm_lib_bg.wasm public + mkdir rust/kcl-wasm-lib/pkg + cp prepared-wasm/kcl_wasm_lib* rust/kcl-wasm-lib/pkg + + - name: Copy prepared ts-rs bindings + run: | + ls -R prepared-ts-rs-bindings + mkdir rust/kcl-lib/bindings + cp -r prepared-ts-rs-bindings/* rust/kcl-lib/bindings/ + + - name: Run component tests + run: npm run test:unit:components