-
-
Notifications
You must be signed in to change notification settings - Fork 48
189 lines (178 loc) · 7.07 KB
/
deploy.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Build, Test & Deploy
on:
push:
branches:
- main
paths:
- "pyproject.toml"
- ".github/workflows/deploy.yml"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
generate-gh-release:
description: Generate a GH release and create a new tag
type: boolean
required: false
default: false
release-to-pypi-override:
description: Generate a release to PYPI even if the version in pyproject.toml is the same as main
type: boolean
required: false
default: false
run-integration-tests:
description: Run integration testing before generating release
type: boolean
required: false
default: true
jobs:
output_workflow_inputs:
name: Output Workflow Input Values
runs-on: ubuntu-latest
steps:
- run: |
echo "run-integration-tests = ${{ github.event.inputs.run-integration-tests }}"
echo "generate-gh-release = ${{ github.event.inputs.generate-gh-release }}"
echo "release-to-pypi-override = ${{ github.event.inputs.elease-to-pypi-override }}"
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v3
with:
python-version: '3.8'
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install Python dependencies
run: poetry install
- name: Linter
run: |
# Lint via flake8
printf "Running flake8 linter -------->\n"
printf "flake8 count for E9,F63,F7,F82: "
poetry run flake8 ./mkdocs_multirepo_plugin --count --select=E9,F63,F7,F82 --show-source --statistics
printf "flake8 count for max-complexity=10: "
poetry run flake8 ./mkdocs_multirepo_plugin --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Unittests
run: poetry run python3 -m unittest tests.unittests -v
integration-tests:
if: ${{ github.event.inputs.run-integration-tests == 'true' || github.event.inputs.run-integration-tests == '' }}
needs: unit-tests
name: Python ${{ matrix.python-version }} and Git ${{ matrix.git-version }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, '3.10', '3.11']
git-version: [2.17.0, 2.35.0, 2.37.1]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Git ${{ matrix.git-version }} from Source
run: |
sudo apt-get update
sudo apt-get install -y dh-autoreconf libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev install-info unzip
sudo apt-get -y install docbook2x
wget https://github.com/git/git/archive/refs/tags/v${{ matrix.git-version }}.zip && unzip v${{ matrix.git-version }}.zip
cd git-${{ matrix.git-version }}
make configure
./configure --prefix=/usr
make all
sudo make install
git --version
- name: Install Bats
run: ./__tests__/setup-bats.sh
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-in-project: true
- name: Install Package and Integration Test Deps
run: |
poetry build
pip install ./dist/*.whl
pip install -r integration-requirements.txt
- name: Integration Tests
run: ./__tests__/test-bats-ci.sh
publish-to-pypi:
if: ${{ always() && github.event.inputs.run-integration-tests != 'false' }}
needs: integration-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@master
with:
python-version: '3.10'
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Build Python distribution
run: |
pip install wheel
rm -rf dist
poetry build
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 14
- run: |
npm install semver
npm install toml
npm install changelog-parser
- name: Get the previous commit on main pyproject.toml
run: |
git show main~1:pyproject.toml > old_pyproject.toml
- name: Version Check
uses: actions/github-script@v6
id: generate-release
with:
script: |
const toml = require('toml')
const fs = require('fs').promises
const semver = require('semver')
var pyproject = toml.parse(await fs.readFile('pyproject.toml', 'utf8'))
var old_pyproject = toml.parse(await fs.readFile('old_pyproject.toml', 'utf8'))
if (semver.gte(old_pyproject.tool.poetry.version, pyproject.tool.poetry.version)) {
console.log(`the current package version is <= the version on main (${old_pyproject.tool.poetry.version} >= ${pyproject.tool.poetry.version})`)
return "false"
} else {
return "true"
}
result-encoding: string
- name: Publish a Python distribution to PyPI
if: ${{ steps.generate-release.outputs.result == 'true' || github.event.inputs.release-to-pypi-override == 'true' }}
uses: pypa/gh-action-pypi-publish@f3ebf87ba2883f1c40faf37d2bb42277f12179c8
with:
user: __token__
password: ${{ secrets.pypi_api_key }}
- name: Get changes from changelog
id: get-changes
uses: actions/github-script@v6
with:
script: |
const toml = require('toml')
const fs = require('fs').promises
const parseChangelog = require('changelog-parser')
var version = toml.parse(await fs.readFile('pyproject.toml', 'utf8')).tool.poetry.version
var changelog = await parseChangelog('CHANGELOG.md')
let result = {changes: changelog.versions[0].body, version: version}
console.log(result)
return result
- name: Create Release
if: ${{ steps.generate-release.outputs.result == 'true' || github.event.inputs.generate-gh-release == 'true' }}
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ fromJSON(steps.get-changes.outputs.result).version }}
release_name: Release v${{ fromJSON(steps.get-changes.outputs.result).version }}
body: |
Changes in this Release
${{ fromJSON(steps.get-changes.outputs.result).changes }}
draft: false
prerelease: false