3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Github Actions 使ったらPypiへのリリースがめちゃくちゃ楽になった

Last updated at Posted at 2021-02-20

Github Actions 使ったらめちゃくちゃ楽になった

Python Packageのリリース (Pypi)

https://github.com/tys-hiroshi/backlogprocessing を例に挙げると、

今まで、setup.cfg ファイルのversion パラメータを修正し、
以下のコマンドをUbuntuで叩いていた。

pipenv shell
pipenv install --dev twine
python3 setup.py sdist --formats=zip
twine upload dist/*

GithubからCloneしてこないといけないし、Releaseできる環境が常にあるわけではないので、
それなりにしんどい作業だった。

.github/workflows/[名前は何でも良いよ].yml

を作成し、以下のように記載すると、PypiへReleaseできる。

PYPI_API_TOKEN は Pypiで発行したAPI TokenをGithubのSecretsに登録すること!

name: Upload pypi package release

on:
  # Trigger the workflow on push or pull request,
  # but only for the master branch
  push:
    branches:
      - master
  release:
    types:
      - created

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install pipenv
        pip install wheel
    - name: Build
      run: |
        python3 setup.py sdist --formats=zip
    - name: Publish a Python distribution to PyPI
      if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release'
      uses: pypa/gh-action-pypi-publish@master
      with:
        user: __token__
        password: ${{ secrets.PYPI_API_TOKEN }}

Thank you for Reference:

3
2
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?