Skip to content

Commit

Permalink
feat: Implement cache in dotnet pipelines (#74)
Browse files Browse the repository at this point in the history
Change-Id: I6f5def4824f1d7f849b45a66cea05d24144f7e3f
  • Loading branch information
Mykola Serdiuk committed Dec 7, 2023
1 parent a8f0cbb commit 9fbdb69
Show file tree
Hide file tree
Showing 21 changed files with 267 additions and 512 deletions.
254 changes: 5 additions & 249 deletions charts/pipelines-library/templates/pipelines/_common_dotnet.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
{{- define "dotnet-6-0-build-common" -}}
- name: test
taskRef:
kind: Task
name: dotnet
runAfter:
- dotnet-build
params:
- name: BASE_IMAGE
value: $(params.image)
- name: EXTRA_COMMANDS
value: |
ls *Tests*/*.csproj | while read -r file;
do dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover "${file}";
done
workspaces:
- name: source
workspace: shared-workspace
subPath: source

- name: sonar
taskRef:
kind: Task
name: dotnet
runAfter:
- test
- build
params:
- name: BASE_IMAGE
value: 'epamedp/tekton-dotnet:6.0.2'
Expand Down Expand Up @@ -88,246 +69,21 @@
workspaces:
- name: source
workspace: shared-workspace
subPath: source
{{- end -}}

{{- define "dotnet-6-0-review-common" -}}
- name: dotnet-build
- name: build
taskRef:
kind: Task
name: dotnet
name: edp-dotnet
runAfter:
- fetch-repository
- get-cache
params:
- name: BASE_IMAGE
value: $(params.image)
- name: EXTRA_COMMANDS
value: |
dotnet build
workspaces:
- name: source
workspace: shared-workspace
subPath: source

- name: test
taskRef:
kind: Task
name: dotnet
runAfter:
- dotnet-build
params:
- name: BASE_IMAGE
value: $(params.image)
- name: EXTRA_COMMANDS
value: |
ls *Tests*/*.csproj | while read -r file;
do dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover "${file}";
done
workspaces:
- name: source
workspace: shared-workspace
subPath: source

# The fetch-target-branch Task will fetch the target branch during the code-review pipeline
# because the fetch-repository Task fetches only user changes.
- name: fetch-target-branch
taskRef:
kind: Task
name: git-cli
runAfter:
- test
params:
- name: GIT_USER_EMAIL
value: edp-ci@edp.ci-user
- name: GIT_USER_NAME
value: edp-ci
- name: GIT_SCRIPT
value: |
git fetch origin $(params.targetBranch):refs/remotes/origin/$(params.targetBranch)
workspaces:
- name: source
workspace: shared-workspace
subPath: source
- name: ssh-directory
workspace: ssh-creds

- name: sonar-prepare-files
taskRef:
kind: Task
name: sonar-prepare-files-dotnet
runAfter:
- fetch-target-branch
params:
- name: CODEBASE_NAME
value: $(params.CODEBASE_NAME)
- name: BRANCH_NAME
value: $(params.targetBranch)
- name: NORMALIZED_BRANCH
value: $(tasks.init-values.results.NORMALIZED_BRANCH)
- name: CHANGE_NUMBER
value: $(params.changeNumber)
- name: PATCHSET_NUMBER
value: $(params.patchsetNumber)
workspaces:
- name: source
workspace: shared-workspace
subPath: source

- name: sonar
taskRef:
kind: Task
name: dotnet
runAfter:
- sonar-prepare-files
params:
- name: BASE_IMAGE
value: 'epamedp/tekton-dotnet:6.0.2'
- name: EXTRA_COMMANDS
value: |
slnFilename=$(ls *.sln)
# /d:sonar.qualitygate.wait=true \
dotnet sonarscanner begin /d:sonar.host.url=${SONAR_HOST_URL} \
/d:sonar.login=${SONAR_TOKEN} \
/k:$(tasks.sonar-prepare-files.results.SONAR_PROJECT_KEY) \
/n:$(tasks.sonar-prepare-files.results.SONAR_PROJECT_KEY) \
/d:sonar.cs.opencover.reportsPaths=$(tasks.sonar-prepare-files.results.SONAR_SOURCES)/*Tests*/*.xml
dotnet build ${sln_filename}
dotnet sonarscanner end /d:sonar.login=${SONAR_TOKEN}
workspaces:
- name: source
workspace: shared-workspace
subPath: source
{{- end -}}

{{- define "dotnet-build-common" -}}
- name: test
taskRef:
kind: Task
name: dotnet
runAfter:
- compile
params:
- name: BASE_IMAGE
value: $(params.image)
- name: EXTRA_COMMANDS
value: |
ls *Tests*/*.csproj | while read -r file;
do dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover "${file}";
done
workspaces:
- name: source
workspace: shared-workspace
subPath: source

- name: sonar
taskRef:
kind: Task
name: dotnet
runAfter:
- test
params:
- name: BASE_IMAGE
value: 'epamedp/tekton-dotnet:6.0.2'
- name: EXTRA_COMMANDS
value: |
slnFilename=$(ls *.sln)
dotnet sonarscanner begin /d:sonar.host.url=${SONAR_HOST_URL} \
/d:sonar.login=${SONAR_TOKEN} \
/d:sonar.qualitygate.wait=true \
/k:$(params.CODEBASEBRANCH_NAME) \
/n:$(params.CODEBASEBRANCH_NAME) \
/d:sonar.cs.opencover.reportsPaths=./*Tests*/*.xml
dotnet build ${sln_filename}
dotnet sonarscanner end /d:sonar.login=${SONAR_TOKEN}
workspaces:
- name: source
workspace: shared-workspace
subPath: source

- name: get-nexus-repository-url
taskRef:
kind: Task
name: get-nexus-repository-url
runAfter:
- sonar
params:
- name: VERSION
value: $(tasks.get-version.results.VERSION)
- name: TOOL
value: "dotnet"

- name: get-nuget-token
taskRef:
kind: Task
name: get-nuget-token
runAfter:
- get-nexus-repository-url
workspaces:
- name: source
workspace: shared-workspace
subPath: source

- name: push
taskRef:
kind: Task
name: dotnet
runAfter:
- get-nuget-token
params:
- name: BASE_IMAGE
value: $(params.image)
- name: EXTRA_COMMANDS
value: |
set -x
slnFilename=$(ls *.sln)
nugetPackagesPath="/tmp/project-nupkgs/"
dotnet pack ${slnFilename} --no-build --output ${nugetPackagesPath} "-p:PackageVersion=$(tasks.get-version.results.VERSION)"
set +x
nugetApiKey=$(cat $(tasks.get-nuget-token.results.NUGET_TOKEN_FILE))
dotnet nuget push ${nugetPackagesPath} -k ${nugetApiKey} -s $(tasks.get-nexus-repository-url.results.NEXUS_REPOSITORY_URL)/
workspaces:
- name: source
workspace: shared-workspace
subPath: source
{{- end -}}

{{- define "dotnet-review-common" -}}
- name: compile
taskRef:
kind: Task
name: dotnet
runAfter:
- fetch-repository
params:
- name: BASE_IMAGE
value: $(params.image)
- name: EXTRA_COMMANDS
value: |
slnFilename=$(ls *.sln)
dotnet publish $slnFilename
workspaces:
- name: source
workspace: shared-workspace
subPath: source

- name: test
taskRef:
kind: Task
name: dotnet
runAfter:
- compile
params:
- name: BASE_IMAGE
value: $(params.image)
- name: EXTRA_COMMANDS
value: |
ls *Tests*/*.csproj | while read -r file;
do dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover "${file}";
done
workspaces:
- name: source
workspace: shared-workspace
subPath: source

# The fetch-target-branch Task will fetch the target branch during the code-review pipeline
# because the fetch-repository Task fetches only user changes.
Expand All @@ -336,7 +92,7 @@
kind: Task
name: git-cli
runAfter:
- test
- build
params:
- name: GIT_USER_EMAIL
value: edp-ci@edp.ci-user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,24 @@ spec:
workspace: shared-workspace
subPath: source

{{- include "get-cache" $ | nindent 4 }}

{{ include "sonar-cleanup" . | nindent 4 }}

{{ include "security" . | nindent 4 }}

- name: dotnet-build
- name: build
taskRef:
kind: Task
name: dotnet
name: edp-dotnet
runAfter:
- security
- get-cache
params:
- name: BASE_IMAGE
value: $(params.image)
- name: EXTRA_COMMANDS
value: |
dotnet build
workspaces:
- name: source
workspace: shared-workspace
subPath: source

{{- include "dotnet-6-0-build-common" . | nindent 4 }}

Expand All @@ -110,10 +108,11 @@ spec:
workspaces:
- name: source
workspace: shared-workspace
subPath: source

{{- include "build-pipeline-dotnet-image-build-push-common" $ | nindent 4 }}

{{- include "save-cache" $ | nindent 4 }}

{{ include "build-pipeline-end" . | nindent 4 }}

{{ include "finally-block-default" . | nindent 2 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ spec:
- name: CODEBASEBRANCH_NAME
value: $(params.CODEBASEBRANCH_NAME)

{{- include "get-cache" $ | nindent 4 }}

- name: update-build-number
taskRef:
kind: Task
Expand All @@ -85,22 +87,19 @@ spec:

{{ include "security-edp" . | nindent 4 }}

- name: dotnet-build
- name: build
taskRef:
kind: Task
name: dotnet
name: edp-dotnet
runAfter:
- security
- get-cache
- update-build-number
params:
- name: BASE_IMAGE
value: $(params.image)
- name: EXTRA_COMMANDS
value: |
dotnet build
workspaces:
- name: source
workspace: shared-workspace
subPath: source

{{- include "dotnet-6-0-build-common" . | nindent 4 }}

Expand All @@ -120,10 +119,11 @@ spec:
workspaces:
- name: source
workspace: shared-workspace
subPath: source

{{- include "build-pipeline-dotnet-image-build-push-common" $ | nindent 4 }}

{{- include "save-cache" $ | nindent 4 }}

{{ include "build-pipeline-end" . | nindent 4 }}

{{ include "finally-block-edp" . | nindent 2 }}
Expand Down
Loading

0 comments on commit 9fbdb69

Please sign in to comment.