Skip to content

Commit 3ce3fd0

Browse files
author
khanh.nguyen
committed
Add python release workflow
1 parent 6c2e30a commit 3ce3fd0

File tree

8 files changed

+147
-33
lines changed

8 files changed

+147
-33
lines changed

.github/worflows/test.yml

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

.github/workflows/gh-release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Github Release
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
7+
jobs:
8+
create-release:
9+
name: Create Release
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
- name: Setup git
15+
run: |
16+
git config user.email "[email protected]"
17+
git config user.name "MessageBird CI"
18+
- name: Prepare description
19+
run: |
20+
csplit -s CHANGELOG.md "/##/" {1}
21+
cat xx01 > CHANGELOG.tmp
22+
- name: Prepare tag
23+
run: |
24+
export TAG=$(head -1 CHANGELOG.tmp | cut -d' ' -f2)
25+
echo "TAG=$TAG" >> $GITHUB_ENV
26+
- name: Create Release
27+
uses: actions/create-release@v1
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
with:
31+
tag_name: ${{ env.TAG }}
32+
release_name: ${{ env.TAG }}
33+
body_path: CHANGELOG.tmp
34+
draft: false
35+
prerelease: false

.github/workflows/publish.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Python release
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Set up Python
14+
uses: actions/setup-python@v3
15+
with:
16+
python-version: '3.x'
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install build
21+
- name: Build package
22+
run: python -m build
23+
- name: Publish package
24+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
25+
with:
26+
user: __token__
27+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/release.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Release
2+
3+
on:
4+
pull_request:
5+
types: [ labeled ]
6+
branches:
7+
- master
8+
9+
jobs:
10+
prepare-release:
11+
name: Prepare release
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Set major release
16+
if: ${{ github.event.label.name == 'release-major' }}
17+
run: echo "RELEASE=major" >> $GITHUB_ENV
18+
- name: Set minor release
19+
if: ${{ github.event.label.name == 'release-minor' }}
20+
run: echo "RELEASE=minor" >> $GITHUB_ENV
21+
- name: Set patch release
22+
if: ${{ github.event.label.name == 'release-patch' }}
23+
run: echo "RELEASE=patch" >> $GITHUB_ENV
24+
- name: Check release env
25+
run: |
26+
if [[ -z "${{ env.RELEASE }}" ]];
27+
then
28+
echo "You need to set a release label on PRs to the main branch"
29+
exit 1
30+
else
31+
exit 0
32+
fi
33+
- name: Install semver-tool
34+
run: |
35+
export DIR=$(mktemp -d)
36+
cd $DIR
37+
curl https://github.com/fsaintjacques/semver-tool/archive/3.2.0.tar.gz -L -o semver.tar.gz
38+
tar -xvf semver.tar.gz
39+
sudo cp semver-tool-3.2.0/src/semver /usr/local/bin
40+
- name: Bump version
41+
run: |
42+
export CURRENT=$(curl -s https://pypi.org/simple/messagebird/ | grep -o "messagebird-[0-9]*\.[0-9]*\.[0-9]*\.tar\.gz" | tail -1 | grep -o "[0-9]*\.[0-9]*\.[0-9]*")
43+
export NEW_VERSION=$(semver bump ${{ env.RELEASE }} $CURRENT)
44+
echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV
45+
- name: Checkout code
46+
uses: actions/checkout@v2
47+
- name: Setup git
48+
run: |
49+
git config user.email "[email protected]"
50+
git config user.name "MessageBird CI"
51+
git fetch
52+
git checkout ${{ github.event.pull_request.head.ref }}
53+
- name: Prepare CHANGELOG
54+
run: |
55+
echo "${{ github.event.pull_request.body }}" | csplit -s - "/##/"
56+
echo "# Changelog
57+
## ${{ env.VERSION }}
58+
" >> CHANGELOG.tmp
59+
grep "^*" xx01 >> CHANGELOG.tmp
60+
grep -v "^# " CHANGELOG.md >> CHANGELOG.tmp
61+
cp CHANGELOG.tmp CHANGELOG.md
62+
- name: Prepare version.py
63+
run: |
64+
sed -i "s|STRING = '[^']*'|STRING = '${{ env.VERSION }}'|" messagebird/version.py
65+
- name: Commit changes
66+
run: |
67+
git add CHANGELOG.md lib/messagebird/version.rb
68+
git commit -m "Bump to version ${{ env.VERSION }}"
69+
- name: Push
70+
run: git push

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Changelog

messagebird/client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
from messagebird.voice_transcription import VoiceTranscriptionsList, VoiceTranscriptionsView
2424
from messagebird.call_flow import CallFlow, CallFlowList, CallFlowNumberList
2525
from messagebird.number import Number, NumberList
26+
from messagebird.version import VERSION
2627

2728
ENDPOINT = 'https://rest.messagebird.com'
28-
CLIENT_VERSION = '2.0.0'
2929
PYTHON_VERSION = '%d.%d.%d' % (sys.version_info[0], sys.version_info[1], sys.version_info[2])
30-
USER_AGENT = 'MessageBird/ApiClient/%s Python/%s' % (CLIENT_VERSION, PYTHON_VERSION)
30+
USER_AGENT = 'MessageBird/ApiClient/%s Python/%s' % (VERSION, PYTHON_VERSION)
3131
REST_TYPE = 'rest'
3232

3333
CONVERSATION_API_ROOT = 'https://conversations.messagebird.com/v1/'
@@ -62,7 +62,6 @@ def __init__(self, errorMessage):
6262
super(SignleErrorException, self).__init__(errorMessage)
6363

6464

65-
6665
class Client(object):
6766
def __init__(self, access_key, http_client=None):
6867
self.access_key = access_key
@@ -290,7 +289,7 @@ def verify_create_email(self, recipient, originator, params=None):
290289
if params is None:
291290
params = {}
292291
params.update({
293-
'type' : 'email',
292+
'type': 'email',
294293
'recipient': recipient,
295294
'originator': originator
296295
})

messagebird/version.py

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

setup.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
from os import path
1+
import os
2+
import re
23
from setuptools import setup
34
from io import open
45

6+
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'messagebird/version.py'), 'r') as fd:
7+
VERSION = re.search(r'^VERSION = [\']([^\']*)[\']',
8+
fd.read(), re.MULTILINE).group(1)
9+
10+
if not VERSION:
11+
raise RuntimeError('Ensure `VERSION` is correctly set in ./messagebird/version.py')
12+
513
with open('README.md', encoding='utf-8') as f:
614
description = f.read()
715

816
setup(
917
name = 'messagebird',
1018
packages = ['messagebird'],
11-
version = '2.0.0',
19+
version = VERSION,
1220
description = "MessageBird's REST API",
1321
author = 'MessageBird',
1422
author_email = '[email protected]',

0 commit comments

Comments
 (0)