-
Notifications
You must be signed in to change notification settings - Fork 1
57 lines (54 loc) · 2.23 KB
/
publish_to_pypi.yml
File metadata and controls
57 lines (54 loc) · 2.23 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
name: Publish Python Distributions to PyPI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches: [ "master" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build-n-publish:
name: Build and publish python distributions to PyPI
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@master
with:
ref: 'master'
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install dependencies for version check
run: pip install requests packaging build
- name: Get local version
id: get_local_version
run: |
local_version=$(grep -m1 version pyproject.toml | sed 's/.*= "\(.*\)"/\1/')
echo "local_version=$local_version" >> $GITHUB_OUTPUT
- name: Get PyPI version
id: get_pypi_version
run: |
pypi_version=$(python -c "import requests; print(requests.get('https://pypi.org/pypi/cereeberus/json').json()['info']['version'])")
echo "pypi_version=$pypi_version" >> $GITHUB_OUTPUT
- name: Check if version is incremented
id: check_version
run: |
if python -c "from packaging.version import parse; print(parse('${{ steps.get_local_version.outputs.local_version }}') > parse('${{ steps.get_pypi_version.outputs.pypi_version }}'))" | grep -q True; then
echo "publish=true" >> $GITHUB_OUTPUT
else
echo "publish=false" >> $GITHUB_OUTPUT
fi
- name: Install package for testing
run: pip install .
- name: Run tests
run: make tests
- name: Build a binary wheel and a source tarball
run: |
python -m build --sdist --wheel --outdir dist/
- name: Publish distribution 📦 to PyPI
if: steps.check_version.outputs.publish == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI }}