From fd9550acdacfe8d63bf54f6a5d2675313e9d8ba4 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Fri, 6 Dec 2019 16:04:01 -0800 Subject: [PATCH] Add Azure Pipelines CI/CD --- .travis.yml | 4 + azure-pipelines.yml | 274 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/.travis.yml b/.travis.yml index de391a8a..4aa53def 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,7 @@ +branches: + except: + - azure + cache: pip: true directories: diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 00000000..fe2d6bd4 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,274 @@ +trigger: + tags: + include: + - v* + branches: + include: + - "*" + exclude: + - "travis" + +stages: + - stage: "Test" + jobs: + - job: Windows + pool: + vmImage: "vs2017-win2016" + strategy: + matrix: + Python36: + python.version: "3.6" + Python37: + python.version: "3.7" + Python38: + python.version: "3.8" + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: "$(python.version)" + - pwsh: | + choco install --yes --no-progress --pre tesseract + choco install --yes --no-progress python3 + choco install --yes --no-progress ghostscript + choco install --yes --no-progress qpdf + choco install --yes --no-progress pngquant + displayName: "Install system packages" + - pwsh: | + refreshenv + $env:path = "C:\Program Files\Tesseract-OCR;C:\Program Files\gs\gs9.50\bin;" + $env:path + pip install --upgrade pip wheel + pip install -r requirements/main.txt -r requirements/test.txt . + tesseract --version + qpdf --version + displayName: "Install Python packages" + - pwsh: | + refreshenv + $env:path = "C:\Program Files\Tesseract-OCR;C:\Program Files\gs\gs9.50\bin;" + $env:path + $env:pathext += ';.py' + # -n auto helps Windows + pytest -n auto --junitxml=test.xml --cov=ocrmypdf --cov-report=xml + displayName: "Test" + - task: PublishTestResults@2 + inputs: + testResultsFiles: "test.xml" + testRunTitle: "$(Agent.OS) - $(Build.DefinitionName) - Python $(python.version)" + condition: succeededOrFailed() + - task: PublishCodeCoverageResults@1 + inputs: + codeCoverageTool: Cobertura + summaryFileLocation: "$(System.DefaultWorkingDirectory)/**/coverage.xml" + - job: "Ubuntu_1804" + pool: + vmImage: "ubuntu-18.04" + strategy: + matrix: + Python36: + python.version: "3.6" + Python37: + python.version: "3.7" + Python38: + python.version: "3.8" + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: "$(python.version)" + - bash: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + python3-software-properties \ + curl \ + ghostscript \ + img2pdf \ + libexempi3 \ + libffi-dev \ + liblept5 \ + libsm6 libxext6 libxrender-dev \ + pngquant \ + poppler-utils \ + qpdf \ + tesseract-ocr \ + tesseract-ocr-deu \ + tesseract-ocr-eng \ + unpaper \ + zlib1g + displayName: "Install system packages" + - bash: | + curl https://bootstrap.pypa.io/get-pip.py | python3 + pip3 install -r requirements/main.txt -r requirements/test.txt . + displayName: "Install Python packages" + - bash: | + tesseract --version + qpdf --version + displayName: "Record versions" + - bash: | + # -n auto is slower on Linux and breaks on Python 3.8 + pytest -n0 --junitxml=test.xml --cov=ocrmypdf --cov-report=xml + displayName: "Test" + - task: PublishTestResults@2 + inputs: + testResultsFiles: "test.xml" + testRunTitle: "$(Agent.OS) - $(Build.DefinitionName) - Python $(python.version)" + condition: succeededOrFailed() + - task: PublishCodeCoverageResults@1 + inputs: + codeCoverageTool: Cobertura + summaryFileLocation: "$(System.DefaultWorkingDirectory)/**/coverage.xml" + - job: "Ubuntu_1604" + pool: + vmImage: "ubuntu-16.04" + strategy: + matrix: + Python36: + python.version: "3.6" + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: "$(python.version)" + - bash: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + software-properties-common + sudo add-apt-repository -y ppa:alex-p/tesseract-ocr + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + ghostscript \ + img2pdf \ + libexempi3 \ + libffi-dev \ + liblept5 \ + libsm6 libxext6 libxrender-dev \ + pngquant \ + poppler-utils \ + qpdf \ + tesseract-ocr \ + tesseract-ocr-deu \ + tesseract-ocr-eng \ + unpaper \ + zlib1g + displayName: "Install system packages" + - bash: | + curl https://bootstrap.pypa.io/get-pip.py | python3 + pip3 install -r requirements/main.txt -r requirements/test.txt . + displayName: "Install Python packages" + - bash: | + tesseract --version + qpdf --version + displayName: "Record versions" + - bash: | + # -n auto is slower on Linux and breaks on Python 3.8 + pytest -n0 --junitxml=test.xml --cov=ocrmypdf --cov-report=xml + displayName: "Test" + - task: PublishTestResults@2 + inputs: + testResultsFiles: "test.xml" + testRunTitle: "$(Agent.OS) - $(Build.DefinitionName) - Python $(python.version)" + condition: succeededOrFailed() + - task: PublishCodeCoverageResults@1 + inputs: + codeCoverageTool: Cobertura + summaryFileLocation: "$(System.DefaultWorkingDirectory)/**/coverage.xml" + - job: "macOS_Mojave" + pool: + vmImage: "macos-10.14" + strategy: + matrix: + Python37: + python.version: "3.7" + Python38: + python.version: "3.8" + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: "$(python.version)" + - bash: | + brew update + brew install \ + exempi \ + ghostscript \ + jbig2enc \ + leptonica \ + openjpeg \ + pngquant \ + qpdf \ + tesseract \ + unpaper + displayName: "Install system packages" + - bash: | + pip3 install --upgrade pip + pip3 install -r requirements/main.txt -r requirements/test.txt . + displayName: "Install Python packages" + - bash: | + tesseract --version + qpdf --version + displayName: "Record versions" + - bash: pytest -nauto --junitxml=test.xml --cov=ocrmypdf --cov-report=xml + displayName: "Test" + - task: PublishTestResults@2 + inputs: + testResultsFiles: "test.xml" + testRunTitle: "$(Agent.OS) - $(Build.DefinitionName) - Python $(python.version)" + condition: succeededOrFailed() + - task: PublishCodeCoverageResults@1 + inputs: + codeCoverageTool: Cobertura + summaryFileLocation: "$(System.DefaultWorkingDirectory)/**/coverage.xml" + + - stage: "Artifacts" + jobs: + - job: "sdist_wheel" + pool: + vmImage: "ubuntu-18.04" + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: "3.7" + - bash: | + python -m pip install --upgrade pip wheel + python setup.py sdist bdist_wheel + - publish: dist + artifact: sdist_wheel + + - stage: "Deploy" + jobs: + - deployment: "PyPI" + pool: + vmImage: "ubuntu-18.04" + environment: "deploy" + strategy: + runOnce: + deploy: + steps: + - download: current + artifact: sdist_wheel + - script: | + mkdir -p dist + mv $(Pipeline.Workspace)/sdist_wheel/* dist + displayName: "Move dist files" + - task: UsePythonVersion@0 + inputs: + versionSpec: "3.8" + architecture: x64 + - script: | + pip3 install --upgrade pip wheel twine + python setup.py sdist bdist_wheel + displayName: "Generate artifacts" + - script: | + cat <.pypirc + [distutils] + index-servers = + pypi + + [pypi] + username: __token__ + password: $(TOKEN_PYPI) + + FILE + displayName: "Generate PyPI auth file" + - script: | + python -m twine upload --config-file .pypirc dist/* + displayName: "Upload to PyPI" + condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/')) + - script: | + curl -X POST -d "token=$(TOKEN_RTD)" https://readthedocs.org/api/v2/webhook/pikepdf/39557/ + displayName: "Trigger ReadTheDocs" + condition: and(succeeded(), or(startsWith(variables['Build.SourceBranch'], 'refs/tags/'), startsWith(variables['Build.SourceBranch'], 'refs/heads/master')))