diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 5195b7c68600c44336661612ec50f6c69162f73b..33deb11b99fceeaabea22d115e77fc46339697de 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -20,3 +20,32 @@ jobs:
       - run: make black
         if: matrix.python-version != '2.7'
       - run: PYTHONPATH=$GITHUB_WORKSPACE py.test -m "not hw_raspberrypi and not mqtt"
+  publish:
+    name: Publish to PyPI
+    runs-on: ubuntu-18.04
+    needs: test
+    strategy:
+      matrix:
+        python-version: ["2.7", "3.6"]
+    steps:
+      - uses: actions/checkout@v2
+      - uses: actions/setup-python@v2
+      - run: pip install black
+        if: matrix.python-version != '2.7'
+      - run: pip install -r requirements.txt
+      - run: make schema
+      - run: make black
+        if: matrix.python-version != '2.7'
+      - run: pip install build
+      - run: build --wheel --outdir dist/ .
+        if: matrix.python-version == '2.7'
+      - run: build --sdist --wheel --outdir dist/ .
+        if: matrix.python-version == '3.6'
+      - uses: pypa/gh-action-pypi-publish@master
+        with:
+          password: test
+          repository_url: https://test.pypi.org/legacy/
+      - uses: pypa/gh-action-pypi-publish@master
+        if: startsWith(github.ref, 'refs/tags')
+        with:
+          password: ${{ secrets.PYPI_API_TOKEN }}