diff options
| -rw-r--r-- | azure-pipelines.yml | 107 | 
1 files changed, 63 insertions, 44 deletions
| diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 89205c1e..d44683ce 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,48 +1,67 @@  # https://aka.ms/yaml  jobs: -- job: test -  displayName: 'Lint & Test' - -  pool: -    vmImage: 'Ubuntu 16.04' - -  variables: -    PIP_CACHE_DIR: ".cache/pip" -    PIP_SRC: ".cache/src" -    PIPENV_CACHE_DIR: ".cache/pipenv" -    PIPENV_DONT_USE_PYENV: 1 -    PIPENV_HIDE_EMOJIS: 1 -    PIPENV_IGNORE_VIRTUALENVS: 1 -    PIPENV_NOSPIN: 1 - -  steps: -  - task: UsePythonVersion@0 -    displayName: 'Set Python version' -    inputs: -      versionSpec: '3.7.x' -      addToPath: true - -  - script: pip3 install pipenv -    displayName: 'Install pipenv' - -  - script: pipenv install --dev --deploy --system -    displayName: 'Install project using pipenv' - -  - script: python3 -m flake8 -    displayName: 'Run linter' - -- job: build -  displayName: 'Build & Push Container' -  condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) -  dependsOn: 'test' - -  steps: -  - task: Docker@2 +  - job: test +    displayName: 'Lint & Test' + +    pool: +      vmImage: 'Ubuntu 16.04' + +    variables: +      PIP_CACHE_DIR: ".cache/pip" +      PIP_SRC: ".cache/src" +      PIPENV_CACHE_DIR: ".cache/pipenv" +      PIPENV_DONT_USE_PYENV: 1 +      PIPENV_HIDE_EMOJIS: 1 +      PIPENV_IGNORE_VIRTUALENVS: 1 +      PIPENV_NOSPIN: 1 +      PRE_COMMIT_HOME: $(Pipeline.Workspace)/pre-commit-cache + +    steps: +      - task: UsePythonVersion@0 +        displayName: 'Set Python version' +        inputs: +          versionSpec: '3.7.x' +          addToPath: true + +      - script: pip3 install pipenv +        displayName: 'Install pipenv' + +      - script: pipenv install --dev --deploy --system +        displayName: 'Install project using pipenv' + +      # 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}"' > $(PythonVersion.pythonLocation)/bin/pipenv \ +          && chmod +x $(PythonVersion.pythonLocation)/bin/pipenv +        displayName: 'Mock pipenv binary' + +      - task: Cache@2 +        displayName: 'Restore pre-commit environment' +        inputs: +          key: pre-commit | "$(PythonVersion.pythonLocation)" | .pre-commit-config.yaml +          restoreKeys: | +            pre-commit | "$(PythonVersion.pythonLocation)" +          path: $(PRE_COMMIT_HOME) + +      - script: pre-commit run --all-files +        displayName: 'Run pre-commit hooks' + +  - job: build      displayName: 'Build & Push Container' -    inputs: -      containerRegistry: 'DockerHub' -      repository: 'pythondiscord/seasonalbot' -      command: 'buildAndPush' -      Dockerfile: '**/Dockerfile' -      tags: 'latest' +    condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) +    dependsOn: 'test' + +    steps: +      - task: Docker@2 +        displayName: 'Build & Push Container' +        inputs: +          containerRegistry: 'DockerHub' +          repository: 'pythondiscord/seasonalbot' +          command: 'buildAndPush' +          Dockerfile: '**/Dockerfile' +          tags: 'latest' | 
