From 5af8774a0b1c6fb7f4afc0dedb6ed563db411672 Mon Sep 17 00:00:00 2001 From: Yulong Wang <7679871+fs-eire@users.noreply.github.com> Date: Fri, 4 Aug 2023 16:44:45 -0700 Subject: [PATCH] [build] do init and precheck first (#16961) ### Description This change allows Web CI to do some check as the first step, so that if there are errors it won't launch the task to build web assembly, which is heavy. Checks includes: - "npm ci" in /js, /js/common and /js/web. this implicitly include: - typescript compiler in /js - typescript compiler in /js/common - webpack build in /js/common - typescript compiler in /js/web - ESLint on typescripts - clang-format formatter (.js, .ts, .cc, .h, .mm) - Prettier formatter (.json, .jsonc, .md) --------- Co-authored-by: Caroline Zhu --- .../templates/linux-web-ci.yml | 41 +------------------ .../templates/linux-web-init-and-check.yml | 41 +++++++++++++++++++ .../azure-pipelines/templates/web-ci.yml | 24 +++++++---- 3 files changed, 59 insertions(+), 47 deletions(-) create mode 100644 tools/ci_build/github/azure-pipelines/templates/linux-web-init-and-check.yml diff --git a/tools/ci_build/github/azure-pipelines/templates/linux-web-ci.yml b/tools/ci_build/github/azure-pipelines/templates/linux-web-ci.yml index 66e4766e32..d2f5df1d17 100644 --- a/tools/ci_build/github/azure-pipelines/templates/linux-web-ci.yml +++ b/tools/ci_build/github/azure-pipelines/templates/linux-web-ci.yml @@ -82,46 +82,7 @@ jobs: targetFolder: $(Build.SourcesDirectory)/js/web/lib/wasm/binding flattenFolders: true displayName: 'Binplace js files' - - script: | - npm ci - workingDirectory: '$(Build.SourcesDirectory)/js' - displayName: 'npm ci /js/' - - script: | - npm run lint - workingDirectory: '$(Build.SourcesDirectory)/js' - displayName: 'run ESLint without TS type populated' - - script: | - npm ci - workingDirectory: '$(Build.SourcesDirectory)/js/common' - displayName: 'npm ci /js/common/' - - script: | - npm test - workingDirectory: '$(Build.SourcesDirectory)/js/common' - displayName: 'run onnxruntime-common tests' - - script: | - npm ci - workingDirectory: '$(Build.SourcesDirectory)/js/web' - displayName: 'npm ci /js/web/' - - script: | - npm run lint - workingDirectory: '$(Build.SourcesDirectory)/js' - displayName: 'run ESLint' - - script: | - npm run format - workingDirectory: '$(Build.SourcesDirectory)/js' - displayName: 'Clang-format' - - script: | - node -e "a=require('child_process').execSync('git diff --name-only').toString();if(a)throw new Error('Following source files are not formatted: (did you run \"npm run format\"?)\n'+a)" - workingDirectory: '$(Build.SourcesDirectory)/js' - displayName: 'Check unformatted files' - - script: | - npm run build:doc - workingDirectory: '$(Build.SourcesDirectory)/js/web' - displayName: 'Generating documents' - - script: | - node -e "a=require('child_process').execSync('git diff --name-only').toString();if(a)throw new Error('Following documents are not up-to-date: (did you run \"npm run build:doc\"?)\n'+a)" - workingDirectory: '$(Build.SourcesDirectory)/js/web' - displayName: 'Check out of dated documents' + - template: linux-web-init-and-check.yml - task: Cache@2 inputs: key: onnxtestdata | $(Build.SourcesDirectory)\js\scripts\prepare-onnx-node-tests.ts diff --git a/tools/ci_build/github/azure-pipelines/templates/linux-web-init-and-check.yml b/tools/ci_build/github/azure-pipelines/templates/linux-web-init-and-check.yml new file mode 100644 index 0000000000..abd8c94dab --- /dev/null +++ b/tools/ci_build/github/azure-pipelines/templates/linux-web-init-and-check.yml @@ -0,0 +1,41 @@ +steps: +- script: | + npm ci + workingDirectory: '$(Build.SourcesDirectory)/js' + displayName: 'npm ci /js/' +- script: | + npm run lint + workingDirectory: '$(Build.SourcesDirectory)/js' + displayName: 'run ESLint without TS type populated' +- script: | + npm ci + workingDirectory: '$(Build.SourcesDirectory)/js/common' + displayName: 'npm ci /js/common/' +- script: | + npm test + workingDirectory: '$(Build.SourcesDirectory)/js/common' + displayName: 'run onnxruntime-common tests' +- script: | + npm ci + workingDirectory: '$(Build.SourcesDirectory)/js/web' + displayName: 'npm ci /js/web/' +- script: | + npm run lint + workingDirectory: '$(Build.SourcesDirectory)/js' + displayName: 'run ESLint' +- script: | + npm run format + workingDirectory: '$(Build.SourcesDirectory)/js' + displayName: 'Clang-format' +- script: | + node -e "a=require('child_process').execSync('git diff --name-only').toString();if(a)throw new Error('Following source files are not formatted: (did you run \"npm run format\"?)\n'+a)" + workingDirectory: '$(Build.SourcesDirectory)/js' + displayName: 'Check unformatted files' +- script: | + npm run build:doc + workingDirectory: '$(Build.SourcesDirectory)/js/web' + displayName: 'Generating documents' +- script: | + node -e "a=require('child_process').execSync('git diff --name-only').toString();if(a)throw new Error('Following documents are not up-to-date: (did you run \"npm run build:doc\"?)\n'+a)" + workingDirectory: '$(Build.SourcesDirectory)/js/web' + displayName: 'Check out of dated documents' diff --git a/tools/ci_build/github/azure-pipelines/templates/web-ci.yml b/tools/ci_build/github/azure-pipelines/templates/web-ci.yml index 0212bd0b46..0651145ed8 100644 --- a/tools/ci_build/github/azure-pipelines/templates/web-ci.yml +++ b/tools/ci_build/github/azure-pipelines/templates/web-ci.yml @@ -48,9 +48,9 @@ parameters: default: false stages: -- stage: Extract_commit +- stage: Precheck_and_extract_commit jobs: - - job: Extract_commit + - job: Precheck_and_extract_commit pool: ${{ parameters.PoolName }} variables: runCodesignValidationInjection: false @@ -58,23 +58,33 @@ stages: workspace: clean: all steps: - - checkout: none + - checkout: self fetchDepth: 1 submodules: false + - script: | + git submodule sync -- cmake/external/onnx + git submodule update --init -- cmake/external/onnx + workingDirectory: '$(Build.SourcesDirectory)' + displayName: 'Checkout submodule onnx' + - task: NodeTool@0 + inputs: + versionSpec: '16.x' + - template: linux-web-init-and-check.yml - task: Bash@3 + displayName: 'Extract commit SHA and save to __commit.txt' inputs: targetType: 'inline' script: | echo $(Build.SourceVersion) echo $(Build.SourceVersion) > "$(Build.ArtifactStagingDirectory)"/__commit.txt - task: PublishPipelineArtifact@0 - displayName: 'Publish Pipeline Artifact' + displayName: 'Publish __commit.txt' inputs: artifactName: '__commit' targetPath: '$(Build.ArtifactStagingDirectory)' - stage: Build_wasm_Debug - dependsOn: Extract_commit + dependsOn: Precheck_and_extract_commit jobs: - template: ${{ parameters.WASMTemplate }} parameters: @@ -100,7 +110,7 @@ stages: PackageName: ${{ parameters.PackageName }} - stage: Build_wasm_Release - dependsOn: Extract_commit + dependsOn: Precheck_and_extract_commit jobs: - template: ${{ parameters.WASMTemplate }} parameters: @@ -113,7 +123,7 @@ stages: - ${{ if eq(parameters.BuildStaticLib, 'true') }}: - stage: Build_wasm_Release_static_library - dependsOn: Extract_commit + dependsOn: Precheck_and_extract_commit jobs: - template: ${{ parameters.WASMTemplate }} parameters: