-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (104 loc) · 3.48 KB
/
python-package.yaml
File metadata and controls
119 lines (104 loc) · 3.48 KB
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
name: Python package
on:
workflow_call:
inputs:
python_version:
description: Python version to use.
type: string
required: false
default: "3.11"
lint_command:
description: Lint command.
type: string
required: false
default: |
pip install -r requirements.dev.txt && \
pycodestyle . && \
flake8 . && \
isort . --check
install_command:
description: Install dev dependencies command.
type: string
required: false
default: |
python -m pip install -r requirements.dev.txt
publish_to_pip:
description: True to publish to PIP.
type: boolean
default: true
required: false
publish_preview_releases_branch_name:
description: |
The branch name which should be used to publish dev release candidates.
Defaults to 'main' - means that all pushes to the main branches are published as dev
release, tagged with `0.0.1-dev-GH_ACTIONS_RUN_BUMBER` (ex: `0.0.1-dev-42`)
Set to `null` to prevent publishing dev preview releases.
type: string
default: main
required: false
secrets:
TWINE_USERNAME:
required: false
TWINE_PASSWORD:
required: false
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
if: inputs.lint_command
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- uses: actions/setup-python@v6
with:
python-version: ${{ inputs.python_version }}
cache: 'pip'
- name: Install dependencies
run: ${{ inputs.install_command }}
- name: Lint
run: ${{ inputs.lint_command }}
publish:
name: Publish
if: inputs.publish_to_pip && ( github.event_name == 'release' || github.event_name == 'workflow_dispatch' || ( github.event_name == 'push' && inputs.publish_preview_releases_branch_name ))
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-python-package-publish
cancel-in-progress: false
runs-on: ubuntu-latest
needs:
- lint
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- uses: actions/setup-python@v6
with:
python-version: ${{ inputs.python_version }}
cache: 'pip'
- name: Get app version
id: get_app_version
shell: bash
run: |
if [[ "$IS_PRODUCTION" == "true" ]]; then
version=$(echo "${{ github.ref_name }}" | sed -e 's/^v//')
else
version="0.0.1-dev-${{ github.run_number }}"
fi
echo "version=$version"
echo "version=$version" >> "$GITHUB_OUTPUT"
env:
IS_PRODUCTION: ${{ (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && github.ref_type == 'tag' && startsWith(github.ref_name, 'v')}}
- name: Install dependencies
env:
VERSION: ${{ steps.get_app_version.outputs.version }}
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME || '__token__' }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
VERSION: ${{ steps.get_app_version.outputs.version }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*