diff options
author | 2020-02-21 17:35:12 -0800 | |
---|---|---|
committer | 2020-02-21 22:35:11 -0800 | |
commit | ddaf1c29366399a61ae9aa1678293e342079f23f (patch) | |
tree | d94ca488d67f30ab4603e7f99e44457b0a61e375 | |
parent | CI: update agent to Ubuntu 18.04 (diff) |
CI: move lint & tests job into templates
Splitting steps into several files makes the YAML more maintainable.
-rw-r--r-- | azure-pipelines.yml | 96 | ||||
-rw-r--r-- | ci/build.yml | 35 | ||||
-rw-r--r-- | ci/lint-test.yml | 41 | ||||
-rw-r--r-- | ci/setup.yml | 18 |
4 files changed, 97 insertions, 93 deletions
diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c5f033d..1ccc04e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -8,99 +8,9 @@ jobs: vmImage: 'ubuntu-18.04' steps: - - task: ShellScript@2 - displayName: 'Check If Images Need to Be Built' - name: check - inputs: - scriptPath: scripts/check_dockerfiles.sh - disableAutoCwd: true - - # Without a login the following Docker build tasks won't add image tags. - - task: Docker@1 - displayName: 'Log into Docker Hub' - inputs: - command: login - containerregistrytype: 'Container Registry' - dockerRegistryEndpoint: 'DockerHub' - - # The venv image depends on this image. Build it if it can't be pulled - # from Docker Hub, which will be the case if the base Dockerfile has had - # changes. - - script: | - docker build \ - -f docker/base.Dockerfile \ - -t pythondiscord/snekbox-base:latest \ - . - displayName: 'Build Base Image' - condition: and(succeeded(), ne(variables['check.BASE_PULL'], True)) - - # The dev image is never pushed and therefore is always built. - - script: | - docker build \ - -f docker/venv.Dockerfile \ - -t pythondiscord/snekbox-venv:dev \ - --build-arg DEV=1 \ - . - displayName: 'Build Development Image' - - # The linter and all tests run inside this container. - - script: | - docker run \ - --tty \ - --detach \ - --name snekbox_test \ - --privileged \ - --network host \ - --hostname pdsnk-dev \ - -e PYTHONDONTWRITEBYTECODE=1 \ - -e PIPENV_PIPFILE="/snekbox/Pipfile" \ - -e ENV="${PWD}/scripts/.profile" \ - --volume "${PWD}":"${PWD}" \ - --workdir "${PWD}"\ - --entrypoint /bin/bash \ - pythondiscord/snekbox-venv:dev - displayName: 'Start Container' - - - script: | - docker exec snekbox_test /bin/bash -c \ - 'pipenv run lint --format junit-xml --output-file test-lint.xml' - displayName: 'Run Linter' - - - task: PublishTestResults@2 - displayName: 'Publish Lint Results' - condition: succeededOrFailed() - inputs: - testResultsFiles: '**/test-lint.xml' - testRunTitle: 'Lint Results' - - # Memory limit tests would fail if this isn't disabled. - - script: sudo swapoff -a - displayName: 'Disable Swap Memory' - - - script: | - docker exec snekbox_test /bin/bash -c \ - 'pipenv run coverage run -m xmlrunner' - displayName: 'Run Unit Tests' - - - task: PublishTestResults@2 - displayName: 'Publish Test Results' - condition: succeededOrFailed() - inputs: - testResultsFiles: '**/TEST-*.xml' - testRunTitle: 'Test Results' - - # Run report too because the XML report doesn't output to stdout. - - script: | - docker exec snekbox_test /bin/bash -c \ - 'pipenv run /bin/bash -c "coverage report && coverage xml"' - displayName: 'Generate Coverage Report' - - - task: PublishCodeCoverageResults@1 - displayName: 'Publish Coverage Results' - condition: succeededOrFailed() - inputs: - codeCoverageTool: Cobertura - summaryFileLocation: '**/coverage.xml' + - template: ci/build.yml + - template: ci/setup.yml + - template: ci/lint-test.yml # When a pull request, only perform this job if images need to be built. # It's always performed for non-PRs because the final image will always need diff --git a/ci/build.yml b/ci/build.yml new file mode 100644 index 0000000..139203e --- /dev/null +++ b/ci/build.yml @@ -0,0 +1,35 @@ +steps: + - task: ShellScript@2 + displayName: 'Check If Images Need to Be Built' + name: check + inputs: + scriptPath: scripts/check_dockerfiles.sh + disableAutoCwd: true + + # Without a login the following Docker build tasks won't add image tags. + - task: Docker@1 + displayName: 'Log into Docker Hub' + inputs: + command: login + containerregistrytype: 'Container Registry' + dockerRegistryEndpoint: 'DockerHub' + + # The venv image depends on this image. Build it if it can't be pulled + # from Docker Hub, which will be the case if the base Dockerfile has had + # changes. + - script: | + docker build \ + -f docker/base.Dockerfile \ + -t pythondiscord/snekbox-base:latest \ + . + displayName: 'Build Base Image' + condition: and(succeeded(), ne(variables['check.BASE_PULL'], True)) + + # The dev image is never pushed and therefore is always built. + - script: | + docker build \ + -f docker/venv.Dockerfile \ + -t pythondiscord/snekbox-venv:dev \ + --build-arg DEV=1 \ + . + displayName: 'Build Development Image' diff --git a/ci/lint-test.yml b/ci/lint-test.yml new file mode 100644 index 0000000..3c3eae6 --- /dev/null +++ b/ci/lint-test.yml @@ -0,0 +1,41 @@ +steps: + - script: | + docker exec snekbox_test /bin/bash -c \ + 'pipenv run lint --format junit-xml --output-file test-lint.xml' + displayName: 'Run Linter' + + - task: PublishTestResults@2 + displayName: 'Publish Lint Results' + condition: succeededOrFailed() + inputs: + testResultsFiles: '**/test-lint.xml' + testRunTitle: 'Lint Results' + + # Memory limit tests would fail if this isn't disabled. + - script: sudo swapoff -a + displayName: 'Disable Swap Memory' + + - script: | + docker exec snekbox_test /bin/bash -c \ + 'pipenv run coverage run -m xmlrunner' + displayName: 'Run Unit Tests' + + - task: PublishTestResults@2 + displayName: 'Publish Test Results' + condition: succeededOrFailed() + inputs: + testResultsFiles: '**/TEST-*.xml' + testRunTitle: 'Test Results' + + # Run report too because the XML report doesn't output to stdout. + - script: | + docker exec snekbox_test /bin/bash -c \ + 'pipenv run /bin/bash -c "coverage report && coverage xml"' + displayName: 'Generate Coverage Report' + + - task: PublishCodeCoverageResults@1 + displayName: 'Publish Coverage Results' + condition: succeededOrFailed() + inputs: + codeCoverageTool: Cobertura + summaryFileLocation: '**/coverage.xml' diff --git a/ci/setup.yml b/ci/setup.yml new file mode 100644 index 0000000..25530e7 --- /dev/null +++ b/ci/setup.yml @@ -0,0 +1,18 @@ +steps: + # The linter and all tests run inside this container. + - script: | + docker run \ + --tty \ + --detach \ + --name snekbox_test \ + --privileged \ + --network host \ + --hostname pdsnk-dev \ + -e PYTHONDONTWRITEBYTECODE=1 \ + -e PIPENV_PIPFILE="/snekbox/Pipfile" \ + -e ENV="${PWD}/scripts/.profile" \ + --volume "${PWD}":"${PWD}" \ + --workdir "${PWD}"\ + --entrypoint /bin/bash \ + pythondiscord/snekbox-venv:dev + displayName: 'Start Container' |