Merge pull request #163 from dynatrace-oss/issue-162 #19
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
name: Build Test Release | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
# this works as an OR | |
branches: | |
- main | |
tags: | |
- "v*" | |
workflow_dispatch: | |
jobs: | |
check-line-endings: | |
name: Check CRLF line endings | |
runs-on: ubuntu-latest | |
timeout-minutes: 2 | |
steps: | |
- name: Checkout repository contents | |
uses: actions/checkout@v4 | |
- name: Use action to check for CRLF endings | |
uses: erclu/check-crlf@v1 | |
run-tests: | |
name: Run tests | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
needs: check-line-endings | |
steps: | |
- name: Checkout repository contents | |
uses: actions/checkout@v4 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Install poetry | |
run: | | |
pip install poetry | |
poetry install | |
- name: Run pytest tests | |
run: | | |
poetry run pytest | |
# Disabled by vduseev on 2024-02-21 | |
# because it's clear we are not using mypy here | |
#- name: Run mypy tests | |
# run: | | |
# bash -c '! poetry run mypy --strict dtcli | grep "Module has no attribute"' | |
- name: Run flake8 lint checker | |
run: | | |
poetry run flake8 dtcli | |
- name: Run test coverage report | |
run: | | |
poetry run pytest --cov . --cov-report html || true | |
build-package: | |
name: Build package | |
# | |
# Builds python package using poetry. | |
# | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
needs: run-tests | |
steps: | |
- name: Checkout repository contents | |
uses: actions/checkout@v4 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Install poetry | |
run: | | |
pip install poetry | |
poetry install | |
- name: Build package | |
run: | | |
poetry build | |
- name: Cache built package artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: package | |
path: | | |
dist/* | |
github-release: | |
name: Create GitHub release | |
# | |
# Creates GitHub release with binaries and packages. | |
# | |
# Only happens for tags. | |
# | |
if: startsWith(github.ref, 'refs/tags/') | |
runs-on: ubuntu-latest | |
needs: | |
- build-package | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Generate changelog | |
run: | | |
cat > CHANGELOG.md <<EOT | |
# CHANGELOG | |
**Release**: dt-cli (${GITHUB_REF#refs/tags/}) | |
# Changes | |
EOT | |
git log --format=format:"%ad: %s" --date=short >> CHANGELOG.md | |
- name: Download cached built package | |
uses: actions/download-artifact@v4 | |
with: | |
name: package | |
path: dist | |
- name: Create GitHub release | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: | | |
dist/* | |
LICENSE | |
body_path: CHANGELOG.md | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
publish-to-pypi: | |
name: Publish to PyPI | |
if: startsWith(github.ref, 'refs/tags/') | |
runs-on: ubuntu-latest | |
needs: | |
- build-package | |
- run-tests | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Install poetry | |
run: | | |
pip install poetry | |
poetry install | |
- name: Download cached built package | |
uses: actions/download-artifact@v4 | |
with: | |
name: package | |
path: dist | |
- name: Publish to PyPI | |
env: | |
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} | |
run: | | |
poetry publish --username __token__ --password $PYPI_TOKEN |