joaomcteixeira/taurenmd

View on GitHub
.github/workflows/version-bump-and-package.yml

Summary

Maintainability
Test Coverage
name: Package Build

on:
  push:
    branches:
      - master

jobs:
  bump-version:

    runs-on: ubuntu-latest
    if: "!startsWith(github.event.head_commit.message, '[SKIP]')"

    steps:

    - uses: actions/checkout@v2
      with:
        token: ${{ secrets.GA_TOKEN }}

    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.8'

    - name: Setup Git
      run: |
        git config user.name "joaomcteixeira"
        git config user.email 'joaomcteixeira@users.noreply.github.com'
        git remote set-url origin https://x-access-token:${{ secrets.GA_TOKEN }}@github.com/$GITHUB_REPOSITORY
        git checkout "${GITHUB_REF:11}"

    - name: Setup env variables
      run: |
        echo "SKIPBUMP=FALSE" >> $GITHUB_ENV

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install bump2version setuptools wheel twine

    - name: Bump Major Version
      env:
        COMMIT_MSG: ${{ github.event.head_commit.message }}
      run: |
        bump2version minor
        echo "SKIPBUMP=TRUE" >> $GITHUB_ENV
      if: "startsWith(github.event.head_commit.message, '[MAJOR]')"

    - name: Bump Minor Version
      env:
        COMMIT_MSG: ${{ github.event.head_commit.message }}
      run: |
        bump2version minor
        echo "SKIPBUMP=TRUE" >> $GITHUB_ENV
      if: "startsWith(github.event.head_commit.message, '[FEATURE]')"

    # Default action
    - name: Bump Patch Version
      env:
        COMMIT_MSG: ${{ github.event.head_commit.message }}
      run: |
        bump2version patch
      if: env.SKIPBUMP == 'FALSE'

    - name: Commit version change to master
      run: |
        git push --follow-tags

    - name: Build and publish
      env:
        TWINE_USERNAME: ${{ secrets.PYPI_USER }}
        TWINE_PASSWORD: ${{ secrets.PYPI_PASS }}
      run: |
        python setup.py sdist bdist_wheel
        twine upload dist/*