blob: 4500cb6e8cedefb5accd71d237b053c659962097 (
plain) (
blame)
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
|
# https://aka.ms/yaml
variables:
PIP_NO_CACHE_DIR: false
PIP_USER: 1
PIPENV_HIDE_EMOJIS: 1
PIPENV_IGNORE_VIRTUALENVS: 1
PIPENV_NOSPIN: 1
PRE_COMMIT_HOME: $(Pipeline.Workspace)/pre-commit-cache
PYTHONUSERBASE: $(Pipeline.Workspace)/py-user-base
jobs:
- job: test
displayName: 'Lint & Test'
pool:
vmImage: ubuntu-18.04
variables:
BOT_API_KEY: foo
BOT_SENTRY_DSN: blah
BOT_TOKEN: bar
REDDIT_CLIENT_ID: spam
REDDIT_SECRET: ham
WOLFRAM_API_KEY: baz
REDIS_PASSWORD: ''
steps:
- task: UsePythonVersion@0
displayName: 'Set Python version'
name: python
inputs:
versionSpec: '3.8.x'
addToPath: true
- task: Cache@2
displayName: 'Restore Python environment'
inputs:
key: python | $(Agent.OS) | "$(python.pythonLocation)" | 0 | ./Pipfile | ./Pipfile.lock
cacheHitVar: PY_ENV_RESTORED
path: $(PYTHONUSERBASE)
- script: echo '##vso[task.prependpath]$(PYTHONUSERBASE)/bin'
displayName: 'Prepend PATH'
- script: pip install pipenv
displayName: 'Install pipenv'
condition: and(succeeded(), ne(variables.PY_ENV_RESTORED, 'true'))
- script: pipenv install --dev --deploy --system
displayName: 'Install project using pipenv'
condition: and(succeeded(), ne(variables.PY_ENV_RESTORED, 'true'))
# Create an executable shell script which replaces the original pipenv binary.
# The shell script ignores the first argument and executes the rest of the args as a command.
# It makes the `pipenv run flake8` command in the pre-commit hook work by circumventing
# pipenv entirely, which is too dumb to know it should use the system interpreter rather than
# creating a new venv.
- script: |
printf '%s\n%s' '#!/bin/bash' '"${@:2}"' > $(python.pythonLocation)/bin/pipenv \
&& chmod +x $(python.pythonLocation)/bin/pipenv
displayName: 'Mock pipenv binary'
- task: Cache@2
displayName: 'Restore pre-commit environment'
inputs:
key: pre-commit | "$(python.pythonLocation)" | 0 | .pre-commit-config.yaml
path: $(PRE_COMMIT_HOME)
# pre-commit's venv doesn't allow user installs - not that they're really needed anyway.
- script: export PIP_USER=0; pre-commit run --all-files
displayName: 'Run pre-commit hooks'
- script: coverage run -m xmlrunner
displayName: Run tests
- script: coverage report -m && coverage xml -o coverage.xml
displayName: Generate test coverage report
- task: PublishCodeCoverageResults@1
displayName: 'Publish Coverage Results'
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: coverage.xml
- task: PublishTestResults@2
condition: succeededOrFailed()
displayName: 'Publish Test Results'
inputs:
testResultsFiles: '**/TEST-*.xml'
testRunTitle: 'Bot Test Results'
- job: build
displayName: 'Build & Push Container'
dependsOn: 'test'
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
steps:
- task: Docker@2
displayName: 'Build & Push Container'
inputs:
containerRegistry: 'DockerHub'
repository: 'pythondiscord/bot'
command: 'buildAndPush'
Dockerfile: 'Dockerfile'
buildContext: '.'
tags: 'latest'
|