Skip to content

Latest commit

 

History

History
102 lines (84 loc) · 3.26 KB

File metadata and controls

102 lines (84 loc) · 3.26 KB

Create a new release with Github Actions

Automatic bumping of version

To execute cz bump in your CI, and push the new commit and the new tag, back to your master branch, we have to:

  1. Create a personal access token. Follow the instructions here. And copy the generated key
  2. Create a secret called PERSONAL_ACCESS_TOKEN, with the copied key, by going to your project repository and then Settings > Secrets > Add new secret.
  3. In your repository create a new file .github/workflows/bumpversion.yml with the following content.
name: Bump version

on:
  push:
    branches:
      - master  # another branch could be specified here

jobs:
  build:
    if: "!startsWith(github.event.head_commit.message, 'bump:')"
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.x']
    steps:
    - uses: actions/checkout@v2
      with:
        token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'
        fetch-depth: 0
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python --version
        python -m pip install -U commitizen
    - name: Create bump
      run: |
        git config --local user.email "action@github.com"
        git config --local user.name "GitHub Action"
        cz bump --yes
    - name: Push changes
      uses: Woile/github-push-action@master
      with:
        github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
        tags: "true"

Push to master and that's it.

Publishing a python package

Once the new tag is created, triggering an automatic publish command would be desired.

In order to do so, the crendetial needs to be added with the information of our PyPI account.

Instead of using username and password, we suggest using api token generated from PyPI.

After generate api token, use the token as the PyPI password and __token__ as the username.

Go to Settings > Secrets > Add new secret and add the secret: PYPI_PASSWORD.

Create a file in .github/workflows/pythonpublish.yaml with the following content:

name: Upload Python Package

on:
  push:
    tags:
      - '*' # Will trigger for every tag, alternative: 'v*'

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: Set up Python
      uses: actions/setup-python@v1
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        python -m pip install --pre -U poetry
        poetry --version
        poetry install
    - name: Build and publish
      env:
        PYPI_USERNAME: __token__
        PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
      run: |
        ./scripts/publish

Notice that we are calling a bash script in ./scripts/publish, you should configure it with your tools (twine, poetry, etc.). Check commitizen example You can also use pypa/gh-action-pypi-publish to publish your package.

Push the changes and that's it.