-
Notifications
You must be signed in to change notification settings - Fork 3
/
CI-Pipeline.yml
139 lines (131 loc) · 4.33 KB
/
CI-Pipeline.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# data quality test (Part of the CI)
trigger: none
# branches:
# include:
# - main
# paths:
# include:
# - WT-DBTDemoPOC/*
resources:
repositories:
- repository: main_branch
type: git
name: WT-DBTDemoPOC
ref: main
pool:
vmImage: 'ubuntu-latest' #might need to be Linux or Ubuntu
#Group name in Library that host all the ENV keys for CI & CD
variables:
- group: dbt_POC
stages:
- stage: CI
displayName: 'CI Pipeline'
jobs:
- job: Publish_Main_Manifest
steps:
- checkout: git://WesTrac-CaptisDevelopment/WT-DBTDemoPOC
path: main
- task: UsePythonVersion@0
inputs:
versionSpec: '3.9'
addToPath: true
architecture: 'x64'
- task: Bash@3
displayName: Install Dependencies
inputs:
targetType: inline
script: |
python -m pip install --upgrade pip
pip install -r dbt_transformation/requirements.txt
- task: Bash@3
displayName: Run dbt deps
inputs:
targetType: inline
script: |
cd dbt_transformation
dbt deps
- task: Bash@3
displayName: Generate dbt manifest
inputs:
targetType: inline
script: |
cd dbt_transformation
dbt deps
dbt compile --target dev
env:
DB_HOST: '$(DB_HOST)'
DB_TOKEN: '$(DB_TOKEN)'
DB_HTTP_PATH: '$(DB_HTTP_PATH)'
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(System.DefaultWorkingDirectory)/dbt_transformation/target/manifest.json
artifactName: dbt_manifest
- job: Integration_Testing
dependsOn: publish_main_manifest
steps:
- checkout: self
# The following part checks for what Triggers the pipeline,
# does nothing if committing to Main and gets the Pull Request ID and store it as a variable.
- script: |
if [ "$(Build.SourceBranchName)" == "main" ]; then
echo "Versioning for Main build"
elif [ -n "$(System.PullRequest.PullRequestId)" ]; then
echo "Versioning for PR build"
echo $(System.PullRequest.PullRequestId)
GH_REF=$(System.PullRequest.PullRequestId)
echo "##vso[task.setvariable variable=GH_REF]$GH_REF"
else
echo "Branch is not for master nor a pull request"
exit 1
fi
echo $GH_REF
displayName: Check Trigger and gets Pull Request Number
- task: UsePythonVersion@0
inputs:
versionSpec: '3.9'
addToPath: true
architecture: 'x64'
- task: Bash@3
displayName: Install Dependencies
inputs:
targetType: inline
script: |
python -m pip install --upgrade pip
pip install -r dbt_transformation/requirements.txt
- task: Bash@3
displayName: Run dbt deps
inputs:
targetType: inline
script: |
cd dbt_transformation
dbt deps
- task: Bash@3
displayName: Perform SQL linting
inputs:
targetType: inline
script: |
sqlfluff lint dbt_transformation
env:
DB_HOST: '$(DB_HOST)'
DB_TOKEN: '$(DB_TOKEN)'
DB_HTTP_PATH: '$(DB_HTTP_PATH)'
- task: DownloadBuildArtifacts@1
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'dbt_manifest'
downloadPath: '$(System.DefaultWorkingDirectory)/dbt_transformation'
- task: Bash@3
displayName: Perform dbt run and test state modified
inputs:
targetType: inline
script: |
cd dbt_transformation
dbt deps
dbt run -m state:modified+1 --defer --state dbt_manifest --target ci
dbt test -m state:modified+1 --defer --state dbt_manifest --target ci
env:
DB_HOST: '$(DB_HOST)'
DB_TOKEN: '$(DB_TOKEN)'
DB_HTTP_PATH: '$(DB_HTTP_PATH)'
GH_REF: $GH_REF