Skip to content

Commit fca06b4

Browse files
authored
Merge pull request #86 from Woile/77-github-actions
GitHub actions to bump and publish
2 parents d69b138 + 1217216 commit fca06b4

File tree

5 files changed

+175
-5
lines changed

5 files changed

+175
-5
lines changed

.github/workflows/bumpversion.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Bump version
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
build:
10+
if: "!contains(github.event.head_commit.message, 'bump')"
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ['3.x']
15+
steps:
16+
- uses: actions/checkout@master
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v1
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Install dependencies
22+
run: |
23+
python --version
24+
python --version
25+
python -m pip install -U commitizen
26+
- name: Create bump
27+
run: |
28+
git config --local user.email "action@github.com"
29+
git config --local user.name "GitHub Action"
30+
git config --local push.followTags true
31+
cz bump --yes
32+
git tag
33+
- name: Push changes
34+
uses: Woile/github-push-action@master
35+
with:
36+
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
37+
tags: "true"

.github/workflows/pythonpublish.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Upload Python Package
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v1
13+
- name: Set up Python
14+
uses: actions/setup-python@v1
15+
with:
16+
python-version: '3.x'
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --pre -U poetry
20+
poetry --version
21+
poetry install
22+
- name: Build and publish
23+
env:
24+
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
25+
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
26+
run: |
27+
./scripts/publish

docs/tutorials/github_actions.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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.

scripts/deploy

Lines changed: 0 additions & 5 deletions
This file was deleted.

scripts/publish

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Publish to pypi
2+
poetry publish --build -u $PYPI_USERNAME -p $PYPI_PASSWORD
3+
4+
[ -z "${INPUT_GITHUB_TOKEN}" ] && {
5+
echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".';
6+
exit 1;
7+
};
8+
9+
remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/commitizen.git"
10+
11+
# Publish docs
12+
mkdocs gh-deploy --remote-name "${remote_repo}"

0 commit comments

Comments
 (0)