Skip to content

Commit 2a638c4

Browse files
author
Jesse
authored
Automate deploys to Pypi (#48)
Signed-off-by: Jesse Whitehouse <[email protected]>
1 parent 4891db0 commit 2a638c4

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

.github/workflows/publish-test.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Publish to PyPI [Test]
2+
on: [push]
3+
jobs:
4+
test-pypi:
5+
name: Create patch version number and push to test-pypi
6+
runs-on: ubuntu-latest
7+
steps:
8+
#----------------------------------------------
9+
# check-out repo and set-up python
10+
#----------------------------------------------
11+
- name: Check out repository
12+
uses: actions/checkout@v2
13+
- name: Set up python
14+
id: setup-python
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.9
18+
#----------------------------------------------
19+
# ----- install & configure poetry -----
20+
#----------------------------------------------
21+
- name: Install Poetry
22+
uses: snok/install-poetry@v1
23+
with:
24+
virtualenvs-create: true
25+
virtualenvs-in-project: true
26+
installer-parallel: true
27+
#----------------------------------------------
28+
# load cached venv if cache exists
29+
#----------------------------------------------
30+
- name: Load cached venv
31+
id: cached-poetry-dependencies
32+
uses: actions/cache@v2
33+
with:
34+
path: .venv
35+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ github.event.repository.name }}-${{ hashFiles('**/poetry.lock') }}
36+
#----------------------------------------------
37+
# install dependencies if cache does not exist
38+
#----------------------------------------------
39+
- name: Install dependencies
40+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
41+
run: poetry install --no-interaction --no-root
42+
#----------------------------------------------
43+
# Get the current version and increment it (test-pypi requires a unique version number)
44+
#----------------------------------------------
45+
- name: Get next version
46+
uses: reecetech/[email protected]
47+
id: version
48+
with:
49+
scheme: semver
50+
increment: patch
51+
#----------------------------------------------
52+
# Tell poetry to update the version number
53+
#----------------------------------------------
54+
- name: Update pyproject.toml
55+
run: poetry version ${{ steps.version.outputs.major-version }}.${{ steps.version.outputs.minor-version }}.dev$(date +%s)
56+
#----------------------------------------------
57+
# Attempt push to test-pypi
58+
#----------------------------------------------
59+
- name: Build and publish to pypi
60+
uses: JRubics/[email protected]
61+
with:
62+
pypi_token: ${{ secrets.TEST_PYPI_TOKEN }}
63+
repository_name: "testpypi"
64+
repository_url: "https://test.pypi.org/legacy/"

.github/workflows/publish.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Publish to PyPI [Production]
2+
on:
3+
release:
4+
types: [published]
5+
jobs:
6+
publish:
7+
name: Publish
8+
runs-on: ubuntu-latest
9+
steps:
10+
#----------------------------------------------
11+
# check-out repo and set-up python
12+
#----------------------------------------------
13+
- name: Check out repository
14+
uses: actions/checkout@v2
15+
- name: Set up python
16+
id: setup-python
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: 3.9
20+
#----------------------------------------------
21+
# ----- install & configure poetry -----
22+
#----------------------------------------------
23+
- name: Install Poetry
24+
uses: snok/install-poetry@v1
25+
with:
26+
virtualenvs-create: true
27+
virtualenvs-in-project: true
28+
installer-parallel: true
29+
#----------------------------------------------
30+
# load cached venv if cache exists
31+
#----------------------------------------------
32+
- name: Load cached venv
33+
id: cached-poetry-dependencies
34+
uses: actions/cache@v2
35+
with:
36+
path: .venv
37+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ github.event.repository.name }}-${{ hashFiles('**/poetry.lock') }}
38+
#----------------------------------------------
39+
# install dependencies if cache does not exist
40+
#----------------------------------------------
41+
- name: Install dependencies
42+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
43+
run: poetry install --no-interaction --no-root
44+
#------------------------------------------------------------------------------------------------
45+
# Here we use version-increment to fetch the latest tagged version (we won't increment it though)
46+
#------------------------------------------------------------------------------------------------
47+
- name: Get next version
48+
uses: reecetech/[email protected]
49+
id: version
50+
with:
51+
scheme: semver
52+
increment: patch
53+
#-----------------------------------------------------------------------------
54+
# Tell poetry to use the `current-version` that was found by the previous step
55+
#-----------------------------------------------------------------------------
56+
- name: Update pyproject.toml
57+
run: poetry version ${{ steps.version.outputs.current-version }}
58+
#----------------------------------------------
59+
# Attempt push to test-pypi
60+
#----------------------------------------------
61+
- name: Build and publish to pypi
62+
uses: JRubics/[email protected]
63+
with:
64+
pypi_token: ${{ secrets.PROD_PYPI_TOKEN }}

0 commit comments

Comments
 (0)