Skip to content

Commit e85fcd6

Browse files
authored
Automated releases + FDK version header (#82)
* user agent added * fixing header assignment * fix pep8 check * auto-release * chmod +x to release image script * fix rebase conflicts * remove version placement from headers.py
1 parent a42ea43 commit e85fcd6

7 files changed

Lines changed: 40 additions & 6 deletions

File tree

fdk/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
FN_HTTP_PREFIX = "Fn-Http-H-"
2525
FN_HTTP_STATUS = "Fn-Http-Status"
2626
FN_DEADLINE = "fn-deadline"
27+
FN_FDK_VERSION = "Fn-Fdk-Version"
2728
FN_HTTP_REQUEST_URL = "fn-http-request-url"
2829
FN_CALL_ID = "fn-call-id"
2930
FN_HTTP_METHOD = "fn-http-method"

fdk/headers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ def encap_headers(headers, status=None):
3131
if headers is not None:
3232
for k, v in headers.items():
3333
if (k == constants.CONTENT_TYPE or
34+
k == constants.FN_FDK_VERSION or
3435
k.startswith(constants.FN_HTTP_PREFIX)):
3536
new_headers[k] = v
3637
else:
3738
new_headers[constants.FN_HTTP_PREFIX + k] = v
3839

3940
if status is not None:
4041
new_headers[constants.FN_HTTP_STATUS] = str(status)
42+
4143
return new_headers

fdk/response.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# under the License.
1414

1515
from fdk import context
16+
from fdk import constants
17+
from fdk import version
1618

1719

1820
class Response(object):
@@ -37,6 +39,7 @@ def __init__(self, ctx: context.InvokeContext,
3739
self.response_data = response_data if response_data else ""
3840
if headers is None:
3941
headers = {}
42+
headers.update({constants.FN_FDK_VERSION: version.VERSION})
4043
ctx.SetResponseHeaders(headers, status_code)
4144
self.ctx = ctx
4245

fdk/tests/test_http_stream.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from fdk import constants
2020
from fdk import event_handler
2121
from fdk import fixtures
22+
from fdk import version
2223

2324
from fdk.tests import funcs
2425

@@ -32,6 +33,7 @@ async def test_override_content_type():
3233
assert 200 == status
3334
assert "OK" == content
3435
assert "application/json" in headers.get("Content-Type")
36+
assert version.VERSION == headers.get(constants.FN_FDK_VERSION)
3537

3638

3739
@pytest.mark.asyncio

fdk/version.py

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

release.sh

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
2+
set -ex
23

4+
# ensure working dir is clean
5+
git status
6+
if [[ -z $(git status -s) ]]
7+
then
8+
echo "tree is clean"
9+
else
10+
echo "tree is dirty, please commit changes before running this"
11+
exit 1
12+
fi
313

4-
git checkout -b v${FDK_VERSION}-stable
5-
git push origin v${FDK_VERSION}-stable
6-
PBR_VERSION=${FDK_VERSION} python setup.py sdist bdist_wheel
7-
twine upload dist/fdk-${FDK_VERSION}*
8-
git checkout master
14+
git pull
15+
16+
version_file="fdk/version.py"
17+
current_version=$(grep -m1 -Eo "[0-9]+\.[0-9]+\.[0-9]+" ${version_file})
18+
new_version=$(docker run --rm marcelocorreia/semver semver -c -i patch ${current_version})
19+
20+
echo "Current version: $current_version"
21+
echo "New version: $new_version"
22+
23+
sed -i '' -e 's/'"$current_version"'/'"$new_version"'/g' fdk/version.py
24+
25+
PBR_VERSION=${new_version} python setup.py sdist bdist_wheel
26+
twine upload -u ${FN_PYPI_USER} -p ${FN_PYPI_PSWD} dist/fdk-${new_version}*
27+
28+
tag="$new_version"
29+
git add -u
30+
git commit -m "FDK Python: $new_version release [skip ci]"
31+
git tag -f -a $tag -m "version $new_version"
32+
git push
33+
git push origin $tag

release_images.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)