|
| 1 | +## Create new release with Github Actions |
| 2 | + |
| 3 | +### Automatic bumping of version |
| 4 | + |
| 5 | +In order to execute `cz bump` in your CI, and push the new commit and |
| 6 | +the new tag, back to your master branch, we have to: |
| 7 | +1. Create a personal access token. [Follow the instructions here](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line#creating-a-token). And copy the generated key |
| 8 | +2. Create a secret called `PERSONAL_ACCESS_TOKEN`, with the copied key, by going to your |
| 9 | +project repository and then `Settings > Secrets > Add new secret`. |
| 10 | +3. In your repostiroy create a new file `.github/workflows/bumpversion.yml` |
| 11 | +with the following content. |
| 12 | + |
| 13 | +```yaml |
| 14 | +name: Bump version |
| 15 | + |
| 16 | +on: |
| 17 | + push: |
| 18 | + branches: |
| 19 | + - master # another branch could be specified here |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + if: "!contains(github.event.head_commit.message, 'bump')" |
| 24 | + runs-on: ubuntu-latest |
| 25 | + strategy: |
| 26 | + matrix: |
| 27 | + python-version: ['3.x'] |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@master |
| 30 | + - name: Set up Python ${{ matrix.python-version }} |
| 31 | + uses: actions/setup-python@v1 |
| 32 | + with: |
| 33 | + python-version: ${{ matrix.python-version }} |
| 34 | + - name: Install dependencies |
| 35 | + run: | |
| 36 | + python --version |
| 37 | + python --version |
| 38 | + python -m pip install -U commitizen |
| 39 | + - name: Create bump |
| 40 | + run: | |
| 41 | + git config --local user.email "action@github.com" |
| 42 | + git config --local user.name "GitHub Action" |
| 43 | + git config --local push.followTags true |
| 44 | + cz bump --yes |
| 45 | + git tag |
| 46 | + - name: Push changes |
| 47 | + uses: Woile/github-push-action@master |
| 48 | + with: |
| 49 | + github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 50 | + tags: "true" |
| 51 | +``` |
| 52 | +
|
| 53 | +Push to master and that's it. |
| 54 | +
|
| 55 | +### Publishing a python package |
| 56 | +
|
| 57 | +Once the new tag is created, triggering an automatic publish command would be desired. |
| 58 | +
|
| 59 | +In order to do so, first 2 secrets need to be added with the information |
| 60 | +of our pypi account. |
| 61 | +
|
| 62 | +Go to `Settings > Secrets > Add new secret` and add the secrets: `PYPI_USERNAME` and `PYPI_PASSWORD`. |
| 63 | + |
| 64 | +Create a file in `.github/workflows/pythonpublish.yaml` with the following content: |
| 65 | + |
| 66 | +```yaml |
| 67 | +name: Upload Python Package |
| 68 | +
|
| 69 | +on: |
| 70 | + push: |
| 71 | + tags: |
| 72 | + - '*' # Will trigger for every tag, alternative: 'v*' |
| 73 | +
|
| 74 | +jobs: |
| 75 | + deploy: |
| 76 | + runs-on: ubuntu-latest |
| 77 | + steps: |
| 78 | + - uses: actions/checkout@v1 |
| 79 | + - name: Set up Python |
| 80 | + uses: actions/setup-python@v1 |
| 81 | + with: |
| 82 | + python-version: '3.x' |
| 83 | + - name: Install dependencies |
| 84 | + run: | |
| 85 | + python -m pip install --pre -U poetry |
| 86 | + poetry --version |
| 87 | + poetry install |
| 88 | + - name: Build and publish |
| 89 | + env: |
| 90 | + PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} |
| 91 | + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} |
| 92 | + run: | |
| 93 | + ./scripts/publish |
| 94 | +``` |
| 95 | + |
| 96 | +Notice that we are calling a bash script in `./scripts/publish`, you should |
| 97 | +configure it with your tools (twine, poetry, etc). Check [commitizen example](https://github.com/Woile/commitizen/blob/master/scripts/deploy) |
| 98 | + |
| 99 | +Push the changes and that's it. |
0 commit comments