Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
New workflow that unifies PR and Release builds
Browse files Browse the repository at this point in the history
remove old
  • Loading branch information
qguyk committed Oct 13, 2021
1 parent 63f98df commit d38a338
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 75 deletions.
27 changes: 0 additions & 27 deletions .github/workflows/create-release.yml

This file was deleted.

153 changes: 153 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]
with:
password: ${{ secrets.PYPI_API_TOKEN }}
48 changes: 0 additions & 48 deletions .github/workflows/on-pull-request.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/publish-test-results.yml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit d38a338

Please sign in to comment.