diff --git a/.devops/azure-templates/make-build-steps.yml b/.devops/azure-templates/setup-project.yml similarity index 72% rename from .devops/azure-templates/make-build-steps.yml rename to .devops/azure-templates/setup-project.yml index 803230b6..54b50bec 100644 --- a/.devops/azure-templates/make-build-steps.yml +++ b/.devops/azure-templates/setup-project.yml @@ -1,14 +1,9 @@ -# Azure DevOps pipeline template used to checkout, install node dependencies and build the code. +# Azure DevOps pipeline template used to setup the Node project: +# 1. checkout code +# 2. setup correct node version +# 3. install node dependencies parameters: -- name: 'make' - type: string - default: install_dependencies - values: - - install_dependencies - - build - - predeploy_build - - name: 'cache_version_id' type: string default: $(CACHE_VERSION_ID) @@ -22,12 +17,20 @@ steps: - checkout: self displayName: 'Checkout' +# This is needed because the pipeline may point to a different commit than expected +# The common case is when the previous stage pushed another commit +- ${{ if ne(parameters.gitReference, variables['Build.SourceVersion']) }}: + - script: | + git fetch && git checkout ${{ parameters.gitReference }} + displayName: 'Checkout reference' + - task: Cache@2 inputs: key: 'yarn-${{ parameters.cache_version_id }} | "$(Agent.OS)" | yarn.lock' restoreKeys: | yarn-${{ parameters.cache_version_id }} | "$(Agent.OS)" path: $(YARN_CACHE_FOLDER) + cacheHitVar: 'CACHE_RESTORED' displayName: 'Cache yarn packages' @@ -35,23 +38,8 @@ steps: inputs: version: $(NODE_VERSION) displayName: 'Set up Node.js' - -# This is needed because the pipeline may point to a different commit than expected -# The common case is when the previous stage pushed another commit -- ${{ if ne(parameters.gitReference, variables['Build.SourceVersion']) }}: - - script: | - git fetch && git checkout ${{ parameters.gitReference }} - displayName: 'Checkout reference' - script: | yarn install --frozen-lockfile --no-progress --non-interactive --network-concurrency 1 displayName: 'Install node modules' condition: ne(variables.CACHE_RESTORED, 'true') - -- ${{ if eq(parameters.make, 'build') }}: - - bash: yarn build - displayName: 'Build code' - -- ${{ if eq(parameters.make, 'predeploy_build') }}: - - bash: yarn predeploy - displayName: 'Predeploy build code' diff --git a/.devops/code-review-pipelines.yml b/.devops/code-review-pipelines.yml index 80bd24f5..a020c680 100644 --- a/.devops/code-review-pipelines.yml +++ b/.devops/code-review-pipelines.yml @@ -28,9 +28,10 @@ stages: # As we deploy on Wondows machines, we use Windows to build vmImage: 'windows-2019' steps: - - template: azure-templates/make-build-steps.yml - parameters: - make: build + - template: azure-templates/setup-project.yml + - script: | + yarn build + displayName: 'Build' - stage: Static_analysis dependsOn: [] @@ -38,19 +39,14 @@ stages: - job: lint steps: - - template: azure-templates/make-build-steps.yml - parameters: - make: install_dependencies + - template: azure-templates/setup-project.yml - script: | yarn lint displayName: 'Lint' - job: validate_api_specification steps: - - template: azure-templates/make-build-steps.yml - parameters: - make: install_dependencies - + - template: azure-templates/setup-project.yml - script: | yarn lint-api displayName: 'Validate API specification' @@ -62,10 +58,7 @@ stages: ne(variables['DANGER_GITHUB_API_TOKEN'], 'skip') ) steps: - - template: azure-templates/make-build-steps.yml - parameters: - make: install_dependencies - + - template: azure-templates/setup-project.yml - bash: | yarn danger ci env: @@ -79,9 +72,7 @@ stages: jobs: - job: unit_tests steps: - - template: azure-templates/make-build-steps.yml - parameters: - make: install_dependencies + - template: azure-templates/setup-project.yml - script: | yarn generate diff --git a/.devops/deploy-pipelines.yml b/.devops/deploy-pipelines.yml index 9e209622..bd089477 100644 --- a/.devops/deploy-pipelines.yml +++ b/.devops/deploy-pipelines.yml @@ -31,7 +31,7 @@ resources: - repository: pagopaCommons type: github name: pagopa/azure-pipeline-templates - ref: refs/tags/v3 + ref: refs/tags/v4 endpoint: 'pagopa' stages: @@ -82,7 +82,7 @@ stages: - job: 'prepare_artifact_and_deploy' steps: # Build application - - template: azure-templates/make-build-steps.yml + - template: azure-templates/setup-project.yml parameters: make: predeploy_build # On the assumption that this stage is executed only when Relase stage is, @@ -91,7 +91,10 @@ stages: # ex: Build.SourceBranch=refs/heads/master --> master # ex: Build.SourceBranch=refs/tags/v1.2.3-RELEASE --> v1.2.3-RELEASE gitReference: ${{ replace(replace(variables['Build.SourceBranch'], 'refs/tags/', ''), 'refs/heads/', '') }} - + - script: | + yarn predeploy + displayName: 'Build' + # Install functions extensions - task: DotNetCoreCLI@2 inputs: