|
| 1 | +# taken and adapted from: |
| 2 | +# https://github.com/joaomcteixeira/python-project-skeleton/blob/master/.github/workflows/version-bump-and-package.yml |
| 3 | +name: Version bump |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + tags-ignore: |
| 10 | + - '*' |
| 11 | + |
| 12 | +jobs: |
| 13 | + |
| 14 | + version_bump: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + |
| 18 | + - name: Check commit message |
| 19 | + if: | |
| 20 | + (!startsWith(github.event.head_commit.message, '[MAJOR]')) && |
| 21 | + (!startsWith(github.event.head_commit.message, '[MINOR]')) && |
| 22 | + (!startsWith(github.event.head_commit.message, '[PATCH]')) |
| 23 | + run: exit 1 |
| 24 | + |
| 25 | + - uses: actions/checkout@v2 |
| 26 | + |
| 27 | + - name: Set up Python |
| 28 | + uses: actions/setup-python@v2 |
| 29 | + with: |
| 30 | + python-version: '3.7' |
| 31 | + |
| 32 | + - name: Setup Git |
| 33 | + run: | |
| 34 | + git config user.name "version_bump" |
| 35 | + git config user.email 'bipboup@imabot.com' |
| 36 | + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY |
| 37 | + git checkout "${GITHUB_REF:11}" |
| 38 | +
|
| 39 | + - name: Install dependencies |
| 40 | + run: | |
| 41 | + python -m pip install --upgrade pip |
| 42 | + pip install bump2version |
| 43 | +
|
| 44 | + - name: Bump Major Version |
| 45 | + env: |
| 46 | + COMMIT_MSG: ${{ github.event.head_commit.message }} |
| 47 | + run: | |
| 48 | + bump2version major |
| 49 | + if: startsWith(github.event.head_commit.message, '[MAJOR]') |
| 50 | + |
| 51 | + - name: Bump Minor Version |
| 52 | + env: |
| 53 | + COMMIT_MSG: ${{ github.event.head_commit.message }} |
| 54 | + run: | |
| 55 | + bump2version minor |
| 56 | + if: startsWith(github.event.head_commit.message, '[MINOR]') |
| 57 | + |
| 58 | + - name: Bump Patch Version |
| 59 | + env: |
| 60 | + COMMIT_MSG: ${{ github.event.head_commit.message }} |
| 61 | + run: | |
| 62 | + bump2version patch |
| 63 | + if: startsWith(github.event.head_commit.message, '[PATCH]') |
| 64 | + |
| 65 | + - name: Commit version change to main |
| 66 | + run: | |
| 67 | + git push --follow-tags |
| 68 | +
|
| 69 | + code_checks: |
| 70 | + needs: version_bump |
| 71 | + uses: ./.github/workflows/_code_checks.yml |
| 72 | + with: |
| 73 | + ref: main |
| 74 | + |
| 75 | + release: |
| 76 | + needs: code_checks |
| 77 | + runs-on: ubuntu-latest |
| 78 | + steps: |
| 79 | + |
| 80 | + - uses: actions/checkout@v2 |
| 81 | + with: |
| 82 | + ref: main |
| 83 | + fetch-depth: 0 # fetches entire history for all branches and tags |
| 84 | + |
| 85 | + - name: Changelog |
| 86 | + uses: Bullrich/generate-release-changelog@master |
| 87 | + id: changelog |
| 88 | + |
| 89 | + - name: Get latest tag |
| 90 | + id: get_latest_tag |
| 91 | + uses: WyriHaximus/github-action-get-previous-tag@v1 |
| 92 | + |
| 93 | + - name: Create GitHub Release |
| 94 | + uses: actions/create-release@v1 |
| 95 | + with: |
| 96 | + tag_name: ${{ steps.get_latest_tag.outputs.tag }} |
| 97 | + release_name: ${{ steps.get_latest_tag.outputs.tag }} |
| 98 | + body: ${{ steps.changelog.outputs.changelog }} |
| 99 | + env: |
| 100 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 101 | + |
| 102 | + publish_package: |
| 103 | + needs: release |
| 104 | + runs-on: ubuntu-latest |
| 105 | + steps: |
| 106 | + |
| 107 | + - uses: actions/checkout@v2 |
| 108 | + with: |
| 109 | + ref: main |
| 110 | + |
| 111 | + - name: Set up Python |
| 112 | + uses: actions/setup-python@v2 |
| 113 | + with: |
| 114 | + python-version: '3.8' |
| 115 | + |
| 116 | + - name: Build pypi package |
| 117 | + run: | |
| 118 | + python3 -m pip install -U setuptools twine wheel |
| 119 | + rm -rf dist |
| 120 | + python3 setup.py sdist |
| 121 | + python3 -m twine check dist/* |
| 122 | +
|
| 123 | + - name: Publish pypi package |
| 124 | + run: | |
| 125 | + ls -la |
| 126 | + python3 -m twine upload --verbose -u __token__ -p ${{ secrets.PYPI_API_TOKEN }} dist/* |
0 commit comments