diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml deleted file mode 100644 index 1ac4208..0000000 --- a/.github/workflows/create-release.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: release-version -on: - workflow_dispatch: - release: - types: [created] - -jobs: - publish: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v1 - with: - python-version: 3.8 - - uses: Gr1N/setup-poetry@v4 - - name: Build package - run: | - export RELEASE_VERSION="${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - poetry version ${RELEASE_VERSION} - poetry build - - name: Upload assets - run: | - RELEASE_VERSION="${GITHUB_REF#refs/*/}" - gh release upload ${RELEASE_VERSION} ./dist/*.tar.gz ./dist/*-py3-none-any.whl - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..770cce5 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,153 @@ +name: Main + +on: + pull_request: + branches: [ main ] + + workflow_dispatch: + inputs: + version: + description: 'Release Version' + required: false + default: '' + +env: + # make sure the poetry creates the venv inside the workspace under .venv + POETRY_VIRTUALENVS_IN_PROJECT: true + +jobs: + Build: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.project-version.outputs.version }} + env: + JUNIT_REPORT_PATH: pytest-junit-report + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v1 + with: + python-version: 3.7 + + - name: Setup pip Cache + id: cache-pip + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: pip + + - name: Bootstrap poetry + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade virtualenv + pip install poetry + [ -d pytest-cov-report ] || mkdir -p pytest-cov-report + [ -d ${JUNIT_REPORT_PATH} ] || mkdir -p ${JUNIT_REPORT_PATH} + + - name: Setup venv Cache + id: cache-python + uses: actions/cache@v2 + with: + path: .venv + key: poetry-${{ hashFiles('poetry.lock') }} + restore-keys: | + poetry- + + - name: Set up the project + run: poetry install + + - name: Check formatting + run: poetry run poe check-format + + - name: Check linting + run: poetry run poe lint + + - name: Test + run: poetry run poe test --junitxml=${JUNIT_REPORT_PATH}/report.xml --cov=pytest-cov-report --cov-report=xml + + - name: Build + run: poetry build + + - name: Upload dist + uses: actions/upload-artifact@v2 + with: + name: dist + path: | + dist/*.tar.gz + dist/*.whl + retention-days: 3 + + - name: Get version from project + id: project-version + run: echo ::set-output name=version::$(poetry version -s) + + - name: Collect PyTest report + id: collect-pytest-reports + if: always() + uses: actions/upload-artifact@v2 + with: + name: pytest-report + path: ${{ env.JUNIT_REPORT_PATH }} + + - name: Collect PyTest coverage report + id: collect-pytest-cov-reports + if: always() + uses: actions/upload-artifact@v2 + with: + name: pytest-cov-report + path: pytest-cov-report + + - name: Display JUnit results + if: > + always() && + github.event.sender.login != 'dependabot[bot]' && + ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository ) + uses: EnricoMi/publish-unit-test-result-action@v1 + with: + files: ${{env.JUNIT_REPORT_PATH}}/*.xml + + + Release: + needs: [Build] + environment: PyPI Deployment + runs-on: ubuntu-latest + if: github.event.inputs.version != '' && github.event.inputs.version == needs.Build.outputs.version + steps: + + - uses: actions/checkout@v2 + - uses: actions/download-artifact@v2 + + - name: Version release logic + id: version-logic + env: + RELEASE_VERSION: ${{ needs.Build.outputs.version }} + run: | + if [[ "$RELEASE_VERSION" == *"-"* ]] + then + echo '::set-output name=GITHUB_EXTRA_FLAG::-p' + echo '::set-output name=CHANGLOG_VERSION::Unreleased' + else + echo '::set-output name=GITHUB_EXTRA_FLAG::' + echo "::set-output name=CHANGLOG_VERSION::${RELEASE_VERSION}" + fi + + - name: Extract version changelog + id: extracted-changelog + uses: talshani/keep-a-changelog-extract@v0.0.1 + with: + version: ${{ steps.version-logic.outputs.CHANGLOG_VERSION }} + + - name: Create GitHub release + run: | + gh release create v${RELEASE_VERSION} ${EXTRA_FLAG} --notes "${RELEASE_NOTES}" \ + dist/*.tar.gz \ + dist/*.whl + env: + RELEASE_NOTES: ${{ steps.extracted-changelog.outputs.body }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_VERSION: ${{ needs.Build.outputs.version }} + EXTRA_FLAG: ${{ steps.version-logic.outputs.GITHUB_EXTRA_FLAG }} + + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@v1.4.2 + with: + password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/on-pull-request.yml b/.github/workflows/on-pull-request.yml deleted file mode 100644 index 438a986..0000000 --- a/.github/workflows/on-pull-request.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: on-pull-request -on: [workflow_dispatch,pull_request] -jobs: - build-n-test: - env: - POETRY_CACHE_FOLDER: '/home/runner/.cache/pypoetry/virtualenvs' - JUNIT_REPORT_PATH: reports/junit - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v1 - with: - python-version: 3.8 - - uses: Gr1N/setup-poetry@v4 - - uses: actions/cache@v2 - with: - path: | - ${{ env.POETRY_CACHE_FOLDER }} - key: poetry-pr-${{ runner.os }}-${{ hashFiles('poetry.lock') }} - - - run: poetry install - - - id: check - run: poetry run poe check - - - id: collect-pytest-reports - if: always() - uses: actions/upload-artifact@v2 - with: - name: pytest-report - path: ${{env.JUNIT_REPORT_PATH}} - - uses: codecov/codecov-action@v1 - name: Upload coverage to codecov - with: - files: ./coverage.xml - flags: unittests - fail_ci_if_error: true - - id: collect-pytest-cov-reports - if: always() - uses: actions/upload-artifact@v2 - with: - name: pytest-cov-report - path: reports/cov - - name: Display JUnit results - if: always() - uses: EnricoMi/publish-unit-test-result-action@v1 - with: - files: ${{env.JUNIT_REPORT_PATH}}/*.xml diff --git a/.github/workflows/publish-test-results.yml b/.github/workflows/publish-test-results.yml new file mode 100644 index 0000000..b58c82a --- /dev/null +++ b/.github/workflows/publish-test-results.yml @@ -0,0 +1,39 @@ +name: Publish Unit Test Results + +on: + workflow_run: + workflows: ["Main"] + types: + - completed + +jobs: + unit-test-results: + name: Unit Test Results + runs-on: ubuntu-latest + if: > + github.event.workflow_run.conclusion != 'skipped' && ( + github.event.sender.login == 'dependabot[bot]' || + github.event.workflow_run.head_repository.full_name != github.repository + ) + + steps: + - name: Download and Extract Artifacts + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: | + mkdir -p artifacts && cd artifacts + + artifacts_url=${{ github.event.workflow_run.artifacts_url }} + + gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact + do + IFS=$'\t' read name url <<< "$artifact" + gh api $url > "$name.zip" + unzip -d "$name" "$name.zip" + done + + - name: Publish Unit Test Results + uses: EnricoMi/publish-unit-test-result-action@v1 + with: + commit: ${{ github.event.workflow_run.head_sha }} + files: "artifacts/**/*.xml" \ No newline at end of file