-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#175476527] refactor pipelines (#120)
- Loading branch information
Showing
6 changed files
with
268 additions
and
565 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Azure DevOps pipeline to build, check source codes and run tests. | ||
# | ||
# To make Danger JS run on a pull request you need to add the following pipeline | ||
# variable and set it with a GitHub access token (scope public_repo); otherwise | ||
# set its value to 'skip' without marking it secret: | ||
# - DANGER_GITHUB_API_TOKEN | ||
# | ||
|
||
variables: | ||
NODE_VERSION: '10.14.1' | ||
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn | ||
|
||
# Automatically triggered on PR | ||
# https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#pr-trigger | ||
trigger: none | ||
|
||
# Execute agents (jobs) on latest Ubuntu version. | ||
# To change OS for a specific, ovverride "pool" attribute inside the job definition | ||
pool: | ||
vmImage: 'ubuntu-latest' | ||
|
||
stages: | ||
- stage: Build | ||
dependsOn: [] | ||
jobs: | ||
- job: make_build | ||
pool: | ||
# 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 | ||
|
||
- stage: Static_analysis | ||
dependsOn: [] | ||
jobs: | ||
|
||
- job: lint | ||
steps: | ||
- template: azure-templates/make-build-steps.yml | ||
parameters: | ||
make: install_dependencies | ||
- script: | | ||
yarn lint | ||
displayName: 'Lint' | ||
- job: validate_api_specification | ||
steps: | ||
- template: azure-templates/make-build-steps.yml | ||
parameters: | ||
make: install_dependencies | ||
|
||
- script: | | ||
yarn lint-api | ||
displayName: 'Validate API specification' | ||
- job: danger | ||
condition: | ||
and( | ||
succeeded(), | ||
ne(variables['DANGER_GITHUB_API_TOKEN'], 'skip') | ||
) | ||
steps: | ||
- template: azure-templates/make-build-steps.yml | ||
parameters: | ||
make: install_dependencies | ||
|
||
- bash: | | ||
yarn danger ci | ||
env: | ||
DANGER_GITHUB_API_TOKEN: '$(DANGER_GITHUB_API_TOKEN)' | ||
displayName: 'Danger CI' | ||
# B) Run unit tests if there is a push or pull request on any branch. | ||
- stage: Test | ||
dependsOn: [] | ||
jobs: | ||
- job: unit_tests | ||
steps: | ||
- template: azure-templates/make-build-steps.yml | ||
parameters: | ||
make: install_dependencies | ||
|
||
- script: | | ||
yarn generate | ||
displayName: 'Generate definitions' | ||
- script: | | ||
yarn test:coverage | ||
displayName: 'Unit tests exec' | ||
- bash: | | ||
bash <(curl -s https://codecov.io/bash) | ||
displayName: 'Code coverage' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
# Azure DevOps pipeline to release a new version and deploy to production. | ||
|
||
variables: | ||
NODE_VERSION: '10.14.1' | ||
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn | ||
|
||
parameters: | ||
- name: 'RELEASE_SEMVER' | ||
displayName: 'When packing a release, define the version bump to apply' | ||
type: string | ||
values: | ||
- major | ||
- minor | ||
- patch | ||
default: minor | ||
|
||
# Only manual activations are intended | ||
trigger: none | ||
pr: none | ||
|
||
# This pipeline has been implemented to be run on hosted agent pools based both | ||
# on 'windows' and 'ubuntu' virtual machine images and using the scripts defined | ||
# in the package.json file. Since we are deploying on Azure functions on Windows | ||
# runtime, the pipeline is currently configured to use a Windows hosted image for | ||
# the build and deploy. | ||
pool: | ||
vmImage: 'windows-2019' | ||
|
||
resources: | ||
repositories: | ||
- repository: pagopaCommons | ||
type: github | ||
name: pagopa/azure-pipeline-templates | ||
ref: refs/tags/v3 | ||
endpoint: 'pagopa' | ||
|
||
stages: | ||
|
||
# Create a relase | ||
# Activated when ONE OF these are met: | ||
# - is on branch master | ||
# - is a tag in the form v{version}-RELEASE | ||
- stage: Release | ||
condition: | ||
and( | ||
succeeded(), | ||
or( | ||
eq(variables['Build.SourceBranch'], 'refs/heads/master'), | ||
and( | ||
startsWith(variables['Build.SourceBranch'], 'refs/tags'), | ||
endsWith(variables['Build.SourceBranch'], '-RELEASE') | ||
) | ||
) | ||
) | ||
pool: | ||
vmImage: 'ubuntu-latest' | ||
jobs: | ||
- job: make_release | ||
steps: | ||
- ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}: | ||
- template: templates/node-github-release/template.yaml@pagopaCommons | ||
parameters: | ||
semver: '${{ parameters.RELEASE_SEMVER }}' | ||
gitEmail: $(GIT_EMAIL) | ||
gitUsername: $(GIT_USERNAME) | ||
gitHubConnection: $(GITHUB_CONNECTION) | ||
nodeVersion: $(NODE_VERSION) | ||
pkg_cache_version_id: $(CACHE_VERSION_ID) | ||
pkg_cache_folder: $(YARN_CACHE_FOLDER) | ||
|
||
- ${{ if ne(variables['Build.SourceBranch'], 'refs/heads/master') }}: | ||
- script: | | ||
echo "We assume this reference to be a valid release: $(Build.SourceBranch). Therefore, there is no need to bundle a new release." | ||
displayName: 'Skip release bundle' | ||
# Prepare Artifact | ||
- stage: Deploy_staging | ||
dependsOn: | ||
- Release | ||
jobs: | ||
- job: 'prepare_artifact_and_deploy' | ||
steps: | ||
# Build application | ||
- template: azure-templates/make-build-steps.yml | ||
parameters: | ||
make: predeploy_build | ||
# On the assumption that this stage is executed only when Relase stage is, | ||
# with this parameter we set the reference the deploy script must pull changes from. | ||
# The branch/tag name is calculated from the source branch | ||
# 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/', '') }} | ||
|
||
# Install functions extensions | ||
- task: DotNetCoreCLI@2 | ||
inputs: | ||
command: "build" | ||
arguments: "-o bin" | ||
# Copy application to | ||
- task: CopyFiles@2 | ||
inputs: | ||
SourceFolder: '$(System.DefaultWorkingDirectory)' | ||
TargetFolder: '$(Build.ArtifactStagingDirectory)' | ||
Contents: | | ||
**/* | ||
!.git/**/* | ||
!**/*.js.map | ||
!**/*.ts | ||
!.vscode/**/* | ||
!azure-templates/**/* | ||
!azure-pipelines.yml | ||
!.prettierrc | ||
!.gitignore | ||
!README.md | ||
!jest.config.js | ||
!local.settings.json | ||
!test | ||
!tsconfig.json | ||
displayName: 'Copy deploy files' | ||
|
||
- task: AzureFunctionApp@1 | ||
inputs: | ||
azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)' | ||
resourceGroupName: '$(PRODUCTION_RESOURCE_GROUP_NAME)' | ||
appType: 'functionApp' | ||
appName: '$(PRODUCTION_APP_NAME)' | ||
package: '$(Build.ArtifactStagingDirectory)/' | ||
deploymentMethod: 'auto' | ||
deployToSlotOrASE: true | ||
slotName: 'staging' | ||
displayName: Deploy to staging slot | ||
|
||
# Check that the staging instance is healthy | ||
- stage: Healthcheck | ||
dependsOn: | ||
- Deploy_staging | ||
jobs: | ||
- job: 'do_healthcheck' | ||
steps: | ||
- template: templates/rest-healthcheck/template.yaml@pagopaCommons | ||
parameters: | ||
azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)' | ||
appName: '$(PRODUCTION_APP_NAME)' | ||
endpoint: 'https://$(PRODUCTION_APP_NAME)-staging.azurewebsites.net/info' | ||
endpointType: 'private' | ||
containerInstanceResourceGroup: 'io-p-rg-common' | ||
containerInstanceVNet: 'io-p-vnet-common' | ||
containerInstanceSubnet: 'azure-devops' | ||
|
||
# Promote the staging instance to production | ||
- stage: Deploy_production | ||
dependsOn: | ||
- Healthcheck | ||
- Deploy_staging | ||
jobs: | ||
- job: 'do_deploy' | ||
steps: | ||
- task: AzureAppServiceManage@0 | ||
inputs: | ||
azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)' | ||
resourceGroupName: '$(PRODUCTION_RESOURCE_GROUP_NAME)' | ||
webAppName: '$(PRODUCTION_APP_NAME)' | ||
sourceSlot: staging | ||
swapWithProduction: true | ||
displayName: Swap with production slot |
Oops, something went wrong.