Skip to content

Commit

Permalink
Merge pull request #358 from flairNLP/pypi-release-workflow
Browse files Browse the repository at this point in the history
Add release workflow to automatically publish on PyPi
  • Loading branch information
MaxDall authored Mar 26, 2024
2 parents 07fc749 + 9d4d6a8 commit 76dd470
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches: [ master ]
pull_request:
workflow_call:

jobs:
black:
Expand Down
123 changes: 123 additions & 0 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# This release workflow was created using the following guide
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/

name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI

on:
release:
types:
- released

jobs:

test:
name: Test the latest release commit
uses: ./.github/workflows/tests.yml

lint:
name: Lint the latest release commit
uses: ./.github/workflows/lint.yml

build:
name: Build distribution 📦
needs:
- test
- lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'

- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build

- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/fundus

permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/

- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

- name: Sleep for 2 minutes
run: sleep 2m
shell: bash

test-distribution:
name: Install and test TestPyPi distribution
needs:
- publish-to-testpypi
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'

- name: Install package
run: >-
python3 -m
pip install
--index-url https://test.pypi.org/simple/
--extra-index-url https://pypi.org/simple/
fundus==${{ github.event.release.tag_name }}
publish-to-pypi:
name: Publish Python 🐍 distribution 📦 to PyPI
needs:
- test-distribution
runs-on: ubuntu-latest

environment:
name: pypi
url: https://pypi.org/p/fundus

permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

5 changes: 1 addition & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: tests

on:
push:
branches: [ master ]
pull_request:
workflow_call:

jobs:
pytest:
Expand Down

0 comments on commit 76dd470

Please sign in to comment.