Skip to content

Commit 9c8476c

Browse files
nqkdevkhanh.nguyen
and
khanh.nguyen
authored
Add python release workflow and release JWT webhook signature (#81)
* Add python release workflow * Fix changelog preparation release step * Use gh to checkout PR * Fixed CHANGELOG.md and added pull request template * Removed download_url Co-authored-by: khanh.nguyen <[email protected]>
1 parent c55e184 commit 9c8476c

File tree

9 files changed

+161
-34
lines changed

9 files changed

+161
-34
lines changed

Diff for: .github/pull_request_template.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Description
2+
3+
Add a short description of the change. If this is related to an issue, please add a reference to the issue.
4+
5+
## CHANGELOG
6+
7+
* [CHANGED] Describe your change here. Look at CHANGELOG.md to see the format.

Diff for: .github/worflows/test.yml

-27
This file was deleted.

Diff for: .github/workflows/gh-release.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
awk '/^## / { if (p) { exit }; { p=1; next } } p && NF' CHANGELOG.md > CHANGELOG.tmp
21+
- name: Prepare tag
22+
run: |
23+
export TAG=$(awk '/^## / {print $2}' CHANGELOG.md)
24+
echo "TAG=$TAG" >> $GITHUB_ENV
25+
- name: Create Release
26+
uses: actions/create-release@v1
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
with:
30+
tag_name: ${{ env.TAG }}
31+
release_name: Version ${{ env.TAG }}
32+
body_path: CHANGELOG.tmp
33+
draft: false
34+
prerelease: false

Diff for: .github/workflows/publish.yml

+27
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 }}

Diff for: .github/workflows/release.yml

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

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
3+
## 2.0.0
4+
5+
* [FIXED] Encoding issue when JSON is serialized.
6+
* [ADDED] Voice recording deletion API.
7+
* [ADDED] Verify create email.
8+
* [CHANGED] Drop python 2 support.

Diff for: messagebird/client.py

+3-4
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
})

Diff for: messagebird/version.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERSION = '2.0.0'

Diff for: setup.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
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]',
1523
long_description = description,
1624
long_description_content_type = 'text/markdown',
1725
url = 'https://github.com/messagebird/python-rest-api',
18-
download_url = 'https://github.com/messagebird/python-rest-api/tarball/2.0.0',
1926
keywords = ['messagebird', 'sms'],
2027
install_requires = ['requests>=2.4.1', 'python-dateutil>=2.6.0', 'pyjwt>=2.1.0'],
2128
extras_require = {

0 commit comments

Comments
 (0)