-
Notifications
You must be signed in to change notification settings - Fork 6
124 lines (110 loc) · 3.81 KB
/
release-pypi.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
name: Release raimitigations to Pypi
# trigger manually ("collaborator" or above permissions should be required)
on:
workflow_dispatch:
inputs:
releaseType:
type: choice
description: "Test or Prod PyPi"
options:
- Test
- Prod
required: true
bumpType:
type: choice
description: "Part of version number to bump"
options:
- major
- minor
- patch
- prerelease
- none
required: true
default: 'minor'
jobs:
release-pypi:
runs-on: ubuntu-latest
steps:
- name: Check Parameters
if: ${{ (github.event.inputs.bumpType != 'none') && (github.event.inputs.releaseType == 'Prod') }}
run: |
echo "If releaseType == 'Prod', then bumpType must be 'none'. Bump the version and send it to test.pypi first. Only then send it to PyPi."
exit 1
# -------------------
# Checkout code
- uses: actions/checkout@v2
with:
persist-credentials: false
fetch-depth: 0
# -------------------
# Setup environment in remote runner
- uses: actions/setup-python@v2
with:
python-version: 3.9
# -------------------
# Install basic packages (not associated with the repo)
- name: update and upgrade pip, setuptools, wheel and twine
run: |
pip install --upgrade pip
pip install --upgrade setuptools wheel twine pip-tools
pip install configparser semver
# -------------------
# Update the package version by bumping the version to the next
- name: Bump version
run: |
python bump_version.py ${{github.event.inputs.bumpType}}
# -------------------
# Install the package and all its dependencies
# Needs to do this after bumping the version, otherwise
# package.__version__ will point to the previous version
- name: Install current package
run: |
pip install --upgrade pip
pip install -e .[dev]
pip list
# -------------------
# Run tests before uploading to PyPi
- name: run tests
run: pytest
# -------------------
# Build wheel
- name: build wheel
run: python -m build
# -------------------
# Publish package to PyPi as ...
# ...a Test package (in test.pypi.org)
- name: Publish package to Test Pypi
if: ${{ github.event.inputs.releaseType == 'Test'}}
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/
# ...an official pip package
- name: Publish package to Pypi
if: ${{ github.event.inputs.releaseType == 'Prod'}}
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
# -------------------
# Commit the changes performed by the bump
# Also, tag the current commit with the version number
- name: commit new setup file
if: ${{ github.event.inputs.bumpType != 'none' }}
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git add setup.cfg
git commit -m "update version number"
VERSION=$(python bump_version.py 'none')
git tag -a $VERSION -m "Release $VERSION"
# -------------------
# Push the changes performed by bump2version to the current branch
- name: Push changes
if: ${{ github.event.inputs.bumpType != 'none' }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
tags: true