Skip to content

Commit 7f9b5b4

Browse files
committed
ci: Create build and release pipeline for Tern
This commit makes changes to package Tern and upload it to PyPI after each new release version. Specifically, the following changes are relevant: 1) Add a pypi_deploy job+workflow to config.yml that will only trigger on GitHub version tags. The pypi_deploy job installs package requirements and creates a ~/.pypirc file with PyPI credentials (via circleci private environment variables). The value of these env. variables is not accessible by forked repositories but care should be taken when merging PRs to check if any forked repositories are making changes to .circleci/config.yml in a bad-faith attempt to expose their values. pypi_deploy goes on to package tern using setup.py and then pushes the package to PyPI using twine. 2) Add a VerifyVersion custom command to setup.py. The VerifyVersion command 'verify' is called in .circleci/config.yml to make sure that the git tag ($CIRCLE_TAG) matches the version of the project according to tern/__init__.py before packaging Tern and pushing to PyPI. If not, return a helpful error message that highlights the discrepancy between the git tag and Version declared in tern/__init__.py and do not push to PyPI. 3) Add a setup.cfg file to utilize the pbr module. The pbr module will allow for a cleaner setup.py file and does a lot of the work that setup.py was previously doing for us. This commit moves most of the code previously in setup.py to an INI-like setup.cfg file and removes the custom parsing functions (_read_long_desc() and _get_requirements()). Using pbr is preferred for easier and cleaner setuptools package management. Resolves tern-tools#287 Resolves tern-tools#211 Signed-off-by: Rose Judge <[email protected]>
1 parent bd8cdcf commit 7f9b5b4

File tree

4 files changed

+97
-40
lines changed

4 files changed

+97
-40
lines changed

.circleci/config.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ commands:
1515
- checkout
1616
- run: pyenv global 3.6.5
1717
- run: pip install --upgrade pip
18+
create_pypirc:
19+
steps:
20+
- run:
21+
name: Create pypirc file
22+
command: |
23+
echo -e "[pypi]" >> ~/.pypirc
24+
echo -e "username = $R_PYPI_UN" >> ~/.pypirc
25+
echo -e "password = $PYPI_PW" >> ~/.pypiruc
1826
1927
jobs:
2028
# linting using Prospector
@@ -58,12 +66,34 @@ jobs:
5866
- setup
5967
- run: pip install .
6068
- run: tern -l report -i photon:3.0
69+
# Deploy to PyPi
70+
pypi_deploy:
71+
executor: ubuntu1604
72+
steps:
73+
- setup
74+
- run: pip install .
75+
- run: pip install twine
76+
# make sure git tag matches release version
77+
- run: python setup.py verify
78+
- create_pypirc
79+
- run: python setup.py sdist
80+
- run: twine upload dist/*
81+
6182
workflows:
62-
# run a full functional test for photonOS
6383
version: 2
6484
PRs:
6585
jobs:
6686
- linting
6787
- commit_check
6888
- security
6989
- test_changes
90+
Release:
91+
jobs:
92+
- pypi_deploy:
93+
filters:
94+
# ignore all commits on any branch by default
95+
branches:
96+
ignore: /.*/
97+
# only run on version tags
98+
tags:
99+
only: /^v[0-9]+(\.[0-9]+)*$/

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
include tern/command_lib/*.yml
22
include tern/tools/fs_hash.sh
33
recursive-include tern/scripts *.sh *.list
4+
prune ci
5+
prune tests

setup.cfg

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2019 VMware, Inc. All Rights Reserved.
5+
# SPDX-License-Identifier: BSD-2-Clause
6+
7+
[metadata]
8+
name = tern
9+
author = VMware Inc
10+
author-email = nishak@vmware.com
11+
summary = An inspection tool to find the OSS compliance metadata of the packages installed in a container image.
12+
description-file = README.md
13+
description-content-type = text/markdown; charset=UTF-8
14+
home-page = https://github.com/vmware/tern/
15+
project_urls =
16+
Documentation = https://github.com/vmware/tern/tree/master/docs
17+
Source Code = https://github.com/vmware/tern
18+
Issues = https://github.com/vmware/tern/issues
19+
license = BSD-2.0
20+
keywords =
21+
Distribution
22+
Container
23+
Cloud-Native
24+
classifier =
25+
Development Status :: 3 - Alpha
26+
Environment :: Console
27+
Intended Audience :: Developers
28+
License :: OSI Approved :: BSD License
29+
Natural Language :: English
30+
Operating System :: POSIX
31+
Operating System :: POSIX :: Linux
32+
Programming Language :: Python :: 3.6
33+
Programming Language :: Python :: 3.7
34+
Programming Language :: Python :: Implementation :: CPython
35+
Topic :: Software Development
36+
37+
[files]
38+
packages =
39+
tern
40+
41+
[options]
42+
include_package_data = True
43+
44+
[entry_points]
45+
console_scripts =
46+
tern = tern.__main__:main

setup.py

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,31 @@
44
# Copyright (c) 2019 VMware, Inc. All Rights Reserved.
55
# SPDX-License-Identifier: BSD-2-Clause
66

7-
from setuptools import setup, find_packages
7+
import os
8+
import sys
89

910
from tern import Version
11+
from setuptools.command.install import install
12+
from setuptools import setup
1013

1114

12-
def _read_long_desc():
13-
with open("README.md") as fp:
14-
return fp.read()
15+
class VerifyVersion(install):
16+
"""Run a custom verify command"""
17+
description = "Verify that the git tag matches current release version."
1518

16-
17-
def _get_requirements():
18-
19-
with open("requirements.txt") as fp:
20-
return [requirement for requirement in fp]
19+
def run(self):
20+
tag = os.getenv('CIRCLE_TAG')
21+
if tag.lstrip('v') != Version:
22+
info = "Git tag {0} does not match Tern version {1}".format(
23+
tag, Version)
24+
sys.exit(info)
2125

2226

2327
setup(
24-
name="tern",
25-
version=Version,
26-
author="VMWare Inc",
27-
author_email="[email protected]",
28-
url="https://github.com/vmware/tern/",
29-
description=("An inspection tool to find the OSS compliance metadata of"
30-
" the packages installed in a container image."),
31-
long_descrition=_read_long_desc(),
32-
long_description_content_type='text/markdown',
33-
license="BSD-2.0",
34-
keywords="Distribution, Container, Cloud-Native",
35-
classifiers=[
36-
'Development Status :: 3 - Alpha',
37-
'Intended Audience :: Developers',
38-
'License :: OSI Approved :: BSD License',
39-
'Natural Language :: English',
40-
'Operating System :: POSIX',
41-
'Operating System :: POSIX :: Linux',
42-
'Operating System :: MacOS :: MacOS X',
43-
'Programming Language :: Python :: 3.6',
44-
'Programming Language :: Python :: Implementation :: CPython',
45-
'Topic :: Software Development'
46-
],
47-
include_package_data=True,
48-
packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*",
49-
"tests"]),
50-
install_requires=_get_requirements(),
28+
setup_requires=['pbr'],
29+
pbr=True,
5130
test_suite="tests.runtests",
52-
entry_points={
53-
"console_scripts": ["tern = tern.__main__:main"]
54-
},
31+
cmdclass={
32+
"verify": VerifyVersion,
33+
}
5534
)

0 commit comments

Comments
 (0)