diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..54ad6b0 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,7 @@ +## Description + +Add a short description of the change. If this is related to an issue, please add a reference to the issue. + +## CHANGELOG + +* [CHANGED] Describe your change here. Look at CHANGELOG.md to see the format. diff --git a/.github/worflows/test.yml b/.github/worflows/test.yml deleted file mode 100644 index 53d6127..0000000 --- a/.github/worflows/test.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Python package - -on: [push] - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - # You can use PyPy versions in python-version. - # For example, pypy-2.7 and pypy-3.8 - matrix: - python-version: ["2.7", "3.6", "3.7", "3.8", "3.9"] - - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - # You can test your matrix by printing the current Python version - - name: Display Python version - run: python -c "import sys; print(sys.version)" - - name: install deps - run: python setup.py install - - name: test - run: python -m unittest diff --git a/.github/workflows/gh-release.yml b/.github/workflows/gh-release.yml new file mode 100644 index 0000000..8e73854 --- /dev/null +++ b/.github/workflows/gh-release.yml @@ -0,0 +1,34 @@ +name: Github Release + +on: + push: + branches: [ master ] + +jobs: + create-release: + name: Create Release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Setup git + run: | + git config user.email "developers@messagebird.com" + git config user.name "MessageBird CI" + - name: Prepare description + run: | + awk '/^## / { if (p) { exit }; { p=1; next } } p && NF' CHANGELOG.md > CHANGELOG.tmp + - name: Prepare tag + run: | + export TAG=$(awk '/^## / {print $2}' CHANGELOG.md) + echo "TAG=$TAG" >> $GITHUB_ENV + - name: Create Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.TAG }} + release_name: Version ${{ env.TAG }} + body_path: CHANGELOG.tmp + draft: false + prerelease: false diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..5d08ac8 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,27 @@ +name: Python release + +on: + push: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Build package + run: python -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..febacd8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,71 @@ +name: Release + +on: + pull_request_target: + # Do not remove types labels to avoid security issue, see link for more info: + # https://securitylab.github.com/research/github-actions-preventing-pwn-requests/#:~:text=Add%20a%20condition%20to%20the,to%20the%20target%20repository: + types: [ labeled ] + branches: + - master + +jobs: + prepare-release: + name: Prepare release + runs-on: ubuntu-latest + + steps: + - name: Set major release + if: ${{ github.event.label.name == 'release-major' }} + run: echo "RELEASE=major" >> $GITHUB_ENV + - name: Set minor release + if: ${{ github.event.label.name == 'release-minor' }} + run: echo "RELEASE=minor" >> $GITHUB_ENV + - name: Set patch release + if: ${{ github.event.label.name == 'release-patch' }} + run: echo "RELEASE=patch" >> $GITHUB_ENV + - name: Check release env + run: | + if [[ -z "${{ env.RELEASE }}" ]]; + then + echo "You need to set a release label on PRs to the main branch" + exit 1 + else + exit 0 + fi + - name: Install semver-tool + run: | + export DIR=$(mktemp -d) + cd $DIR + curl https://github.com/fsaintjacques/semver-tool/archive/3.2.0.tar.gz -L -o semver.tar.gz + tar -xvf semver.tar.gz + sudo cp semver-tool-3.2.0/src/semver /usr/local/bin + - name: Bump version + run: | + 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]*") + export NEW_VERSION=$(semver bump ${{ env.RELEASE }} $CURRENT) + echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + - name: Prepare CHANGELOG + run: | + echo "${{ github.event.pull_request.body }}" | csplit -s - "/##/" + echo "# Changelog + ## ${{ env.VERSION }} + " >> CHANGELOG.tmp + grep "^*" xx01 >> CHANGELOG.tmp + grep -v "^# " CHANGELOG.md >> CHANGELOG.tmp + cp CHANGELOG.tmp CHANGELOG.md + - name: Prepare version.py + run: | + sed -i "s|VERSION = '[^']*'|VERSION = '${{ env.VERSION }}'|" messagebird/version.py + - name: Commit changes + run: | + git config --global user.email "developers@messagebird.com" + git config --global user.name "MessageBird CI" + git add CHANGELOG.md messagebird/version.py + git commit -m "Bump to version ${{ env.VERSION }}" + - name: Push + run: git push diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..aa0e240 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Changelog + +## 2.0.0 + +* [FIXED] Encoding issue when JSON is serialized. +* [ADDED] Voice recording deletion API. +* [ADDED] Verify create email. +* [CHANGED] Drop python 2 support. diff --git a/messagebird/client.py b/messagebird/client.py index 3f5318b..de5b9a7 100644 --- a/messagebird/client.py +++ b/messagebird/client.py @@ -23,11 +23,11 @@ from messagebird.voice_transcription import VoiceTranscriptionsList, VoiceTranscriptionsView from messagebird.call_flow import CallFlow, CallFlowList, CallFlowNumberList from messagebird.number import Number, NumberList +from messagebird.version import VERSION ENDPOINT = 'https://rest.messagebird.com' -CLIENT_VERSION = '2.0.0' PYTHON_VERSION = '%d.%d.%d' % (sys.version_info[0], sys.version_info[1], sys.version_info[2]) -USER_AGENT = 'MessageBird/ApiClient/%s Python/%s' % (CLIENT_VERSION, PYTHON_VERSION) +USER_AGENT = 'MessageBird/ApiClient/%s Python/%s' % (VERSION, PYTHON_VERSION) REST_TYPE = 'rest' CONVERSATION_API_ROOT = 'https://conversations.messagebird.com/v1/' @@ -62,7 +62,6 @@ def __init__(self, errorMessage): super(SignleErrorException, self).__init__(errorMessage) - class Client(object): def __init__(self, access_key, http_client=None): self.access_key = access_key @@ -290,7 +289,7 @@ def verify_create_email(self, recipient, originator, params=None): if params is None: params = {} params.update({ - 'type' : 'email', + 'type': 'email', 'recipient': recipient, 'originator': originator }) diff --git a/messagebird/version.py b/messagebird/version.py new file mode 100644 index 0000000..204a96f --- /dev/null +++ b/messagebird/version.py @@ -0,0 +1 @@ +VERSION = '2.0.0' diff --git a/setup.py b/setup.py index da5fba9..8438849 100644 --- a/setup.py +++ b/setup.py @@ -1,21 +1,28 @@ -from os import path +import os +import re from setuptools import setup from io import open +with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'messagebird/version.py'), 'r') as fd: + VERSION = re.search(r'^VERSION = [\']([^\']*)[\']', + fd.read(), re.MULTILINE).group(1) + +if not VERSION: + raise RuntimeError('Ensure `VERSION` is correctly set in ./messagebird/version.py') + with open('README.md', encoding='utf-8') as f: description = f.read() setup( name = 'messagebird', packages = ['messagebird'], - version = '2.0.0', + version = VERSION, description = "MessageBird's REST API", author = 'MessageBird', author_email = 'support@messagebird.com', long_description = description, long_description_content_type = 'text/markdown', url = 'https://github.com/messagebird/python-rest-api', - download_url = 'https://github.com/messagebird/python-rest-api/tarball/2.0.0', keywords = ['messagebird', 'sms'], install_requires = ['requests>=2.4.1', 'python-dateutil>=2.6.0', 'pyjwt>=2.1.0'], extras_require = {