Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only run CI job for changes which are not docs changes #1217

Merged
merged 1 commit into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ pr:
branches:
include:
- master
paths:
exclude:
- docs/*
- README.md

resources:
- repo: self
Expand Down Expand Up @@ -60,27 +56,38 @@ variables:
steps:
- checkout: self # self represents the repo where the initial Pipelines YAML file was found
lfs: "true"

- task: Bash@3
name: "check_changes"
inputs:
targetType: 'filePath'
filePath: './scripts/check-changes.sh'

- script: |
make validate-copyright-headers
make validate-cainjection-files
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')
displayName: 'Validate Source'
continueOnError: 'false'


- task: GoTool@0
displayName: Get Go 1.13.7
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')
inputs:
version: '1.13.7'

- task: Go@0
displayName: Get Go dependencies
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')
inputs:
command: 'get'
arguments: '-d'
workingDirectory: '$(System.DefaultWorkingDirectory)'

- task: Bash@3
displayName: Install kubebuilder, kustomize and test dependencies
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')
inputs:
targetType: 'inline'
script: |
Expand Down Expand Up @@ -118,6 +125,7 @@ steps:
export TEST_APIM_NAME=$(TEST_APIM_NAME)
make test-integration-controllers
displayName: Run tests on a Kind Cluster
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')
continueOnError: 'false'
env:
GO111MODULE: on
Expand All @@ -134,17 +142,20 @@ steps:
export PATH=$PATH:$(go env GOPATH)/bin
make test-process-coverage
displayName: Render Coverage Reports
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')
continueOnError: true
workingDirectory: '$(System.DefaultWorkingDirectory)'

- task: PublishCodeCoverageResults@1
displayName: Publish Codecoverage results
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(System.DefaultWorkingDirectory)/reports/merged-coverage.xml

- task: PublishBuildArtifacts@1
displayName: Publish test reports
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')
inputs:
pathtoPublish: '$(System.DefaultWorkingDirectory)/reports'
artifactName: reports
Expand All @@ -160,16 +171,19 @@ steps:

- script: docker build -t $(IMAGE_NAME) .
displayName: Docker build
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')
workingDirectory: '$(System.DefaultWorkingDirectory)'

- task: Docker@2
displayName: Login to temporary pipeline ACR
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')
inputs:
containerRegistry: $(PIPELINE_CONTAINER_REGISTRY)
command: 'login'

- task: Docker@2
displayName: Build and Push Docker Image to temporary ACR for validation
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')
inputs:
containerRegistry: $(PIPELINE_CONTAINER_REGISTRY)
repository: '$(IMAGE_NAME)'
Expand Down Expand Up @@ -199,27 +213,31 @@ steps:
workingDirectory: '$(System.DefaultWorkingDirectory)'
failOnStandardError: true
displayName: Deploy to AKS - Find available AKS cluster and connect to it
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')

- script: |
kubectl create namespace cert-manager
kubectl label namespace cert-manager cert-manager.io/disable-validation=true
kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v0.12.0/cert-manager.yaml
displayName: Deploy to AKS - Install Cert Manager
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')

- task: HelmInstaller@1
displayName: Deploy to AKS - Install latest Helm
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')
inputs:
helmVersionToInstall: 'latest'

- script: |
# Replace image repository in values.yaml to the official image in ACR
img="$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION"
echo $img
sed -i -e 's@azureserviceoperator:latest@azureserviceoperator:'${img}'@' charts/azure-service-operator/values.yaml
displayName: Deploy to AKS - Replace image in values.yaml
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')

- task: Bash@3
displayName: Deploy to AKS - Helm Deploy
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')
inputs:
targetType: 'inline'
script: |
Expand Down Expand Up @@ -265,6 +283,7 @@ steps:
workingDirectory: '$(System.DefaultWorkingDirectory)'
failOnStandardError: true
displayName: Deploy to AKS - Clean up deployment and release cluster back to free pool
condition: eq(variables['check_changes.SOURCE_CODE_CHANGED'], 'true')

- task: Docker@2
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
Expand Down
35 changes: 35 additions & 0 deletions scripts/check-changes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -e

IGNORE_FILTERS=("docs/" "README.md")
CHANGED_FILES=$(git diff HEAD HEAD~ --name-only)
IGNORED_COUNT=0
NON_IGNORED_COUNT=0
echo "Checking for file changes..."
for FILE in $CHANGED_FILES; do
# Check if the file matches one of the ignore filters
MATCHED=0
for FILTER in ${IGNORE_FILTERS[@]}; do
if [[ $FILE == *$FILTER* ]]; then
MATCHED=1
echo "${FILE} in ignore filter $FILTER"
fi
done

if [[ $MATCHED -eq 0 ]]; then
echo "Source code file ${FILE} changed"
NON_IGNORED_COUNT=$(($NON_IGNORED_COUNT+1))
else
IGNORED_COUNT=$(($IGNORED_COUNT+1))

fi
done

echo "" # Blank line for readability
echo "$IGNORED_COUNT match(es) for ignore filter '${IGNORE_FILTERS[*]}' found."
echo "$NON_IGNORED_COUNT match(es) for changed source code files found."
if [[ $NON_IGNORED_COUNT -gt 0 ]]; then
echo "##vso[task.setvariable variable=SOURCE_CODE_CHANGED;isOutput=true]true"
else
echo "##vso[task.setvariable variable=SOURCE_CODE_CHANGED;isOutput=true]false"
fi