Skip to content

Commit 3dbbea3

Browse files
authored
Merge pull request googleapis#2837 from dhermes/push-on-tag
Adding helpers to push to PyPI on tags.
2 parents b5f03ea + 10e6d00 commit 3dbbea3

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

circle.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ general:
2121
branches:
2222
ignore:
2323
- gh-pages
24+
25+
deployment:
26+
release:
27+
tag: /(([a-z]+)-)?([0-9]+)\.([0-9]+)\.([0-9]+)/
28+
owner: GoogleCloudPlatform
29+
commands:
30+
- pip install --upgrade twine
31+
- ./scripts/circleci_twine_upload.sh

scripts/circleci_tagged_pkg.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Helper to determine package from tag.
16+
17+
Get the current package directory corresponding to the Circle Tag.
18+
"""
19+
20+
from __future__ import print_function
21+
22+
import os
23+
import re
24+
import sys
25+
26+
27+
RE_TXT = r'^((?P<pkg>[a-z]+)-)?([0-9]+)\.([0-9]+)\.([0-9]+)$'
28+
TAG_RE = re.compile(RE_TXT)
29+
TAG_ENV = 'CIRCLE_TAG'
30+
ERROR_MSG = '%s env. var. not set' % (TAG_ENV,)
31+
BAD_TAG_MSG = 'Invalid tag name: %s. Expected ' + RE_TXT
32+
_SCRIPTS_DIR = os.path.dirname(__file__)
33+
ROOT_DIR = os.path.abspath(os.path.join(_SCRIPTS_DIR, '..'))
34+
35+
36+
def main():
37+
"""Get the current package directory.
38+
39+
Prints the package directory out so callers can consume it.
40+
"""
41+
if TAG_ENV not in os.environ:
42+
print(ERROR_MSG, file=sys.stderr)
43+
sys.exit(1)
44+
45+
tag_name = os.environ[TAG_ENV]
46+
match = TAG_RE.match(tag_name)
47+
if match is None:
48+
print(BAD_TAG_MSG % (tag_name,), file=sys.stderr)
49+
sys.exit(1)
50+
51+
pkg_name = match.group('pkg')
52+
if pkg_name is None:
53+
print(ROOT_DIR)
54+
else:
55+
pkg_dir = pkg_name.replace('-', '_')
56+
print(os.path.join(ROOT_DIR, pkg_dir))
57+
58+
59+
if __name__ == '__main__':
60+
main()

scripts/circleci_twine_upload.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# Copyright 2016 Google Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -ev
18+
19+
# H/T: http://stackoverflow.com/a/246128/1068170
20+
SCRIPT="$(dirname "${BASH_SOURCE[0]}")/circleci_tagged_pkg.py"
21+
# Determine the package directory being deploying on this tag.
22+
PKG_DIR="$(python ${SCRIPT})"
23+
24+
# Move into the package, build the distribution and upload.
25+
cd ${PKG_DIR}
26+
python setup.py sdist bdist_wheel
27+
twine upload dist/*

0 commit comments

Comments
 (0)