Skip to content

Commit 3fbaab6

Browse files
set up auto package publishing
1 parent d4db2c8 commit 3fbaab6

File tree

10 files changed

+220
-8
lines changed

10 files changed

+220
-8
lines changed

.bumpversion.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[bumpversion]
2+
current_version = 0.1.1
3+
commit = True
4+
message =
5+
version bump {current_version} -> {new_version}
6+
tag = True
7+
tag_name = {new_version}
8+
tag_message =
9+
version bump {current_version} -> {new_version}
10+
11+
[bumpversion:file:gitlab_submodule/__version__.py]
12+
search = __version__ = '{current_version}'
13+
replace = __version__ = '{new_version}'
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
name: Code checks
22

33
on:
4-
push:
5-
branches: [ main ]
6-
pull_request:
4+
workflow_call:
5+
inputs:
6+
ref:
7+
required: false
8+
type: string
9+
default: default
710

811
jobs:
912
check:
@@ -12,24 +15,36 @@ jobs:
1215
strategy:
1316
fail-fast: false
1417
matrix:
15-
python-version: ["3.8", "3.9", "3.10"]
18+
python-version: ["3.7", "3.8", "3.9", "3.10"]
1619

1720
name: Check Python${{ matrix.python-version }}
1821

1922
steps:
20-
- uses: actions/checkout@v2
23+
- name: checkout current commit
24+
uses: actions/checkout@v2
25+
if: ${{ inputs.ref == 'default' }}
26+
27+
- name: checkout main
28+
uses: actions/checkout@v2
29+
with:
30+
ref: ${{ inputs.ref }}
31+
if: ${{ inputs.ref != 'default' }}
32+
2133
- name: install python
2234
uses: actions/setup-python@v2
2335
with:
2436
python-version: ${{ matrix.python-version }}
37+
2538
- name: install dependencies
2639
run: |
2740
python -m pip install --upgrade pip
2841
python -m pip install -r requirements_dev.txt
2942
pip install -r requirements.txt
43+
3044
- name: lint
3145
run: |
3246
make lint
47+
3348
- name: test
3449
run: |
3550
make test
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: PR code check
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
code_checks:
8+
uses: ./.github/workflows/_code_checks.yml
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: PR title check
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
- reopened
9+
- edited
10+
11+
jobs:
12+
pr_title_check:
13+
runs-on: ubuntu-latest
14+
name: Check PR title
15+
steps:
16+
- name: Check PR title
17+
uses: Slashgear/action-check-pr-title@v3.0.0
18+
with:
19+
regexp: '^((\[MAJOR\])|(\[MINOR\])|(\[PATCH\])).+$'

.github/workflows/release.yml

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

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea/
2+
*/__pycache__/
3+
*.egg-info/
4+
dist/

changelog_config.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"categories": [
3+
{
4+
"title": "## MAJOR",
5+
"labels": ["[MAJOR]"]
6+
},
7+
{
8+
"title": "## MINOR",
9+
"labels": ["[MINOR]"]
10+
},
11+
{
12+
"title": "## PATCH",
13+
"labels": ["[PATCH]"]
14+
}
15+
],
16+
"sort": "DESC"
17+
}

gitlab_submodule/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""List project submodules and get the commits they point to with python-gitlab
22
"""
33

4-
__version__ = '0.1.0'
4+
from gitlab_submodule.__version__ import __version__ as hardcoded_version
5+
6+
__version__ = hardcoded_version
7+
58
__all__ = [
69
'Submodule', 'Subproject',
710
'list_submodules',

gitlab_submodule/__version__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = '0.1.1'

setup.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import sys
2+
3+
sys.path[0:0] = ['gitlab_submodule']
4+
5+
from __version__ import __version__
6+
17
try:
28
from setuptools import setup
39
except ImportError:
@@ -9,7 +15,7 @@
915
'List project submodules and get the commits they point to '
1016
'with python-gitlab.',
1117
license='Apache License 2.0',
12-
version='0.1.0',
18+
version=__version__,
1319
author='Valentin François',
1420
maintainer='Valentin François',
1521
url='https://github.com/ValentinFrancois/python-gitlab-submodule',
@@ -18,4 +24,4 @@
1824
'python-gitlab>=3.0.0',
1925
'giturlparse>=0.10.0'
2026
]
21-
)
27+
)

0 commit comments

Comments
 (0)