This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
153 lines (129 loc) · 4.37 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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 }}