Created
May 23, 2019 15:38
-
-
Save gcarrarom/564566170a3823d214a947aaa57d1ba4 to your computer and use it in GitHub Desktop.
YAML pipeline for python CLI
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
trigger: | |
branches: | |
include: | |
- master | |
pool: | |
vmImage: 'ubuntu-latest' | |
strategy: | |
matrix: | |
Python36: | |
python.version: '3.6' | |
Python37: | |
python.version: '3.7' | |
steps: | |
- task: UsePythonVersion@0 | |
inputs: | |
versionSpec: '$(python.version)' | |
displayName: 'Use Python $(python.version)' | |
- script: | | |
echo "Getting version from the setup.py file..." | |
ApplicationVersion=$(cat setup.py | grep version | cut -d '=' -f 2 | cut -d "'" -f 2) | |
echo "setup.py file version: $ApplicationVersion" | |
echo "Testing if this version already exists in GitHub..." | |
echo "Get the tags first..." | |
tags=$(curl https://api.github.com/repos/gcarrarom/kubeconfig-cleaner-cli/tags) | |
echo "check if there's a match on the version.." | |
Match=$(echo $tags | jq -r ".[] | select(.name == \"v$ApplicationVersion\")") | |
if [[ -z "$Match" ]]; then | |
echo "All good, this doesn't match any old versions" | |
else | |
echo "Nope, we have this already... try choosing another one ;)" | |
exit 100 | |
fi | |
echo "Version to be used: $ApplicationVersion" | |
echo "##vso[task.setvariable variable=ApplicationVersion]$ApplicationVersion" | |
displayName: 'Get application Version' | |
- script: | | |
python -m pip install --upgrade pip | |
pip install pytest-cov | |
pip install . | |
displayName: 'Install dependencies' | |
- script: | | |
pip install pytest pytest-azurepipelines | |
pytest --junitxml=$(System.DefaultWorkingDirectory)/testResults.xml --cov=kcleaner --cov-report=html --cov-report=xml | |
displayName: 'pytest' | |
- task: PublishTestResults@2 | |
displayName: 'Publish test results' | |
inputs: | |
testResultsFiles: '$(System.DefaultWorkingDirectory)/testResults.xml' | |
testRunTitle: Tests | |
- task: PublishCodeCoverageResults@1 | |
displayName: "publishing code coverage" | |
inputs: | |
codeCoverageTool: 'Cobertura' | |
summaryFileLocation: '$(System.DefaultWorkingDirectory)/test-cov.xml' | |
reportDirectory: '$(System.DefaultWorkingDirectory)/htmlcov' | |
additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/htmlcov/**' | |
failIfCoverageEmpty: true | |
- task: CopyFiles@2 | |
inputs: | |
SourceFolder: '$(Build.SourcesDirectory)' | |
Contents: '*.py' | |
TargetFolder: '$(Build.ArtifactStagingDirectory)/code' | |
CleanTargetFolder: true | |
displayName: 'Copying Python files to the Staging directory' | |
- task: CopyFiles@2 | |
inputs: | |
SourceFolder: '$(Build.SourcesDirectory)' | |
Contents: 'README.MD' | |
TargetFolder: '$(Build.ArtifactStagingDirectory)/code' | |
CleanTargetFolder: true | |
displayName: 'Copying ReadMe.md file to the Staging directory' | |
- task: ArchiveFiles@2 | |
inputs: | |
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/code' | |
includeRootFolder: true | |
archiveType: 'tar' | |
archiveFile: '$(Build.ArtifactStagingDirectory)/drop/kcleaner-v$(ApplicationVersion)-$(Build.BuildNumber).tar.gz' | |
replaceExistingArchive: true | |
displayName: 'Archiving release files to tar.gz file' | |
- task: PublishBuildArtifacts@1 | |
inputs: | |
PathtoPublish: '$(Build.ArtifactStagingDirectory)/drop' | |
ArtifactName: 'drop' | |
publishLocation: 'Container' | |
displayName: 'Publishing Drop Artifacts' | |
- task: PublishBuildArtifacts@1 | |
inputs: | |
PathtoPublish: '$(Build.ArtifactStagingDirectory)/code' | |
ArtifactName: 'code' | |
publishLocation: 'Container' | |
displayName: 'Publishing Code Artifacts' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment