Repository: richcat-dev/richcat (language: python)

Issue:
PyPIへの登録をGithub Actionsで行うようにする



Discussion / hints:

Fix patch:
diff --git a/.github/workflows/act-playground.yml b/.github/workflows/act-playground.yml
deleted file mode 100644
index 6d978b0..0000000
--- a/.github/workflows/act-playground.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-name: act playground
-
-on:
-  pull_request:
-
-jobs:
-  act_prayground:
-    runs-on: ubuntu-latest
-
-    steps:
-      - name: test
-        run: echo "hello act"
diff --git a/.github/workflows/sphinx-build.yml b/.github/workflows/sphinx-build.yml
index 8f895b1..fb10d36 100644
--- a/.github/workflows/sphinx-build.yml
+++ b/.github/workflows/sphinx-build.yml
@@ -24,7 +24,7 @@ jobs:
 
       - name: Build
         run: |
-          make publicbuild
+          make sphinx-deploy
 
       - name: Deploy
         uses: peaceiris/actions-gh-pages@v3
diff --git a/.github/workflows/upload-to-pypi.yml b/.github/workflows/upload-to-pypi.yml
new file mode 100644
index 0000000..bef9517
--- /dev/null
+++ b/.github/workflows/upload-to-pypi.yml
@@ -0,0 +1,78 @@
+name: Upload to PyPI
+
+on:
+  push:
+    tags:
+      - v*
+
+jobs:
+  check_version:
+    runs-on: ubuntu-latest
+
+    outputs:
+      version: ${{ steps.get_version_in_branch.outputs.version_in_branch }}
+      version_matched: ${{ steps.compare_version.outputs.matched }}
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+
+      - name: Set up Python
+        uses: actions/setup-python@v2
+        with:
+          python-version: 3.7
+
+      - name: Extract richcat version from branch name
+        id: get_version_in_branch
+        run: echo "::set-output name=version_in_branch::$(echo ${GITHUB_REF#refs/tags/} | sed 's/v//')"
+
+      - name: Get richcat version from code
+        id: get_version_in_code
+        run: echo "::set-output name=version_in_code::$(python ./scripts/get_version.py)"
+
+      - name: Compare version
+        id: compare_version
+        run: echo "::set-output name=matched::$([[ ${{ steps.get_version_in_branch.outputs.version_in_branch }} == ${{ steps.get_version_in_code.outputs.version_in_code }} ]]; echo $?)"
+
+  release_richcat:
+    runs-on: ubuntu-latest
+    needs: check_version
+    if: ${{ needs.check_version.outputs.version_matched == 0 }}
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+
+      - name: Set up Python
+        uses: actions/setup-python@v2
+        with:
+          python-version: 3.7
+
+      - name: Install dependencies
+        run: |
+          python -m pip install --upgrade pip
+          python -m pip install wheel twine
+
+      - name: Build
+        run: |
+          rm -rf ./richcat.egg-info/ dist/
+          python setup.py bdist_wheel
+
+      - name: Publish package to PyPI
+        id: upload
+        if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
+        uses: pypa/gh-action-pypi-publish@release/v1
+        with:
+          user: __token__
+          password: ${{ secrets.PYPI_API_TOKEN }}
+
+      - name: Create release
+        if: steps.upload.conclusion == 'success'
+        uses: actions/create-release@v1
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        with:
+          tag_name: v${{ needs.check_version.outputs.version }}
+          release_name: Release v${{ needs.check_version.outputs.version }}
+          draft: false
+          prerelease: false
diff --git a/.gitignore b/.gitignore
index 889376c..b5a20ce 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,7 @@ share/python-wheels/
 .installed.cfg
 *.egg
 MANIFEST
+.pypirc
 
 # PyInstaller
 #  Usually these files are written by a python script from a template
diff --git a/.pypirc.sample b/.pypirc.sample
new file mode 100644
index 0000000..7b0e741
--- /dev/null
+++ b/.pypirc.sample
@@ -0,0 +1,14 @@
+[distutils]
+index-servers =
+  pypi
+  testpypi
+
+[pypi]
+repository: https://upload.pypi.org/legacy/
+username: 
+password: 
+
+[testpypi]
+repository: https://test.pypi.org/legacy/
+username: 
+password: 
\ No newline at end of file
diff --git a/README.md b/README.md
index cd0c791..373429f 100644
--- a/README.md
+++ b/README.md
@@ -109,7 +109,7 @@ You can update `richcat` API documentation with the following command.
 
 ```
 $ cd ~
-$ make apidoc
+$ make sphinx-apidoc
 ```
 
 ## Contributors
diff --git a/docker-compose.yml b/docker-compose.yml
index 7f349aa..6d09c31 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -16,3 +16,12 @@ services:
         target: "/var/run/docker.sock"
     command: bash -c "pip install -e /home && make apidoc && make autobuild"
     tty: true
+  richcat-play:
+    build: ./richcat-play-env
+    image: richcat-play
+    container_name: richcat-play
+    volumes:
+      - type: bind
+        source: "./"
+        target: "/home/"
+    tty: true
diff --git a/richcat-play-env/.bashrc b/richcat-play-env/.bashrc
new file mode 100644
index 0000000..5a29a6e
--- /dev/null
+++ b/richcat-play-env/.bashrc
@@ -0,0 +1,5 @@
+# Colorize prompt
+export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
+
+# Set less command options
+export LESS="-F -g -i -M -R -S -w -X -z-4"
\ No newline at end of file
diff --git a/richcat-play-env/Dockerfile b/richcat-play-env/Dockerfile
new file mode 100644
index 0000000..a1f5e3a
--- /dev/null
+++ b/richcat-play-env/Dockerfile
@@ -0,0 +1,17 @@
+# Base image
+FROM python:3.7
+
+# Environment
+ENV HOME /home
+WORKDIR $HOME
+COPY .bashrc requirements.txt $HOME/
+
+# Installl commands
+RUN apt-get update && apt-get upgrade -y \
+    && apt-get install -y \
+    less
+
+# Install Python libraries
+RUN pip install --upgrade pip \
+    && pip install -r $HOME/requirements.txt \
+    && pip install -i https://test.pypi.org/simple/ richcat
\ No newline at end of file
diff --git a/richcat-play-env/requirements.txt b/richcat-play-env/requirements.txt
new file mode 100644
index 0000000..147672b
--- /dev/null
+++ b/richcat-play-env/requirements.txt
@@ -0,0 +1,10 @@
+# Base libraries
+rich
+
+# For Sphinx
+sphinx
+sphinx-autobuild
+sphinx_rtd_theme
+
+# Testing
+pytest
\ No newline at end of file
diff --git a/richcat/__information__.py b/richcat/__information__.py
index e24e6ad..2d731d3 100644
--- a/richcat/__information__.py
+++ b/richcat/__information__.py
@@ -1,6 +1,6 @@
-__copyright__    = 'Copyright (C) 2020 Yuta Yamamoto, Shotaro Kataoka'
-__version__      = '0.4.1'
-__license__      = 'MIT'
-__author__       = 'Yuta Yamamoto, Shotaro Kataoka'
+__copyright__ = 'Copyright (C) 2020 Yuta Yamamoto, Shotaro Kataoka'
+__version__ = '0.4.2'
+__license__ = 'MIT'
+__author__ = 'Yuta Yamamoto, Shotaro Kataoka'
 __author_email__ = 'automatuX78@gmail.com'
-__url__          = 'https://github.com/richcat-dev/richcat'
+__url__ = 'https://github.com/richcat-dev/richcat'
diff --git a/scripts/get_version.py b/scripts/get_version.py
new file mode 100644
index 0000000..b9c3eba
--- /dev/null
+++ b/scripts/get_version.py
@@ -0,0 +1,6 @@
+import re
+
+with open('./richcat/__information__.py', 'r') as f:
+    init_text = f.read()
+    _version = re.search(r'__version__\s*=\s*[\'\"](.+?)[\'\"]', init_text).group(1)
+    print(_version)


Test patch:
diff --git a/.github/workflows/upload-to-testpypi.yml b/.github/workflows/upload-to-testpypi.yml
new file mode 100644
index 0000000..d4aab18
--- /dev/null
+++ b/.github/workflows/upload-to-testpypi.yml
@@ -0,0 +1,67 @@
+name: Upload to TestPyPI
+
+on:
+  push:
+    branches:
+      - release/v*
+
+jobs:
+  check_version:
+    runs-on: ubuntu-latest
+
+    outputs:
+      version_matched: ${{ steps.compare_version.outputs.matched }}
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+
+      - name: Set up Python
+        uses: actions/setup-python@v2
+        with:
+          python-version: 3.7
+
+      - name: Extract richcat version from branch name
+        id: get_version_in_branch
+        env:
+          BRANCH_NAME: ${{github.head_ref}}
+        run: echo "::set-output name=version_in_branch::$(echo $BRANCH_NAME | cut -d '/' -f 2 | sed 's/v//')"
+
+      - name: Get richcat version from code
+        id: get_version_in_code
+        run: echo "::set-output name=version_in_code::$(python ./scripts/get_version.py)"
+
+      - name: Compare version
+        id: compare_version
+        run: echo "::set-output name=matched::$([[ ${{ steps.get_version_in_branch.outputs.version_in_branch }} == ${{ steps.get_version_in_code.outputs.version_in_code }} ]]; echo $?)"
+
+  upload_to_testpypi:
+    runs-on: ubuntu-latest
+    needs: check_version
+    if: ${{ needs.check_version.outputs.version_matched == 0 }}
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+
+      - name: Set up Python
+        uses: actions/setup-python@v2
+        with:
+          python-version: 3.7
+
+      - name: Install dependencies
+        run: |
+          python -m pip install --upgrade pip
+          python -m pip install wheel twine
+
+      - name: Build
+        run: |
+          rm -rf ./richcat.egg-info/ dist/
+          python setup.py bdist_wheel
+
+      - name: Publish package to TestPyPI
+        uses: pypa/gh-action-pypi-publish@release/v1
+        with:
+          user: __token__
+          password: ${{ secrets.PYPI_API_TOKEN }}
+          repository_url: https://test.pypi.org/legacy/