Skip to content

Commit 1023682

Browse files
authored
Support twine (#26)
* Added twine example * Refactored cloudsmith cli example
1 parent b9f8595 commit 1023682

13 files changed

+245
-37
lines changed

.circleci/test-deploy.yml

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
test-authenticate_with_oidc:
2727
docker:
2828
- image: cimg/base:current
29+
resource_class: small
2930
steps:
3031
- checkout
3132
- cloudsmith-circleci/authenticate_with_oidc:
@@ -53,6 +54,7 @@ jobs:
5354
test-set_env_vars_for_pip:
5455
docker:
5556
- image: cimg/python:3.9
57+
resource_class: small
5658
steps:
5759
- checkout
5860
- cloudsmith-circleci/set_env_vars_for_pip:
@@ -73,19 +75,82 @@ jobs:
7375
fi
7476
echo "All tests passed."
7577
76-
test-upload_python_package:
78+
test-set_env_vars_for_twine:
7779
docker:
7880
- image: cimg/python:3.9
81+
resource_class: small
7982
steps:
8083
- checkout
84+
- cloudsmith-circleci/set_env_vars_for_twine:
85+
repository: "circleci-orb-testing"
86+
service_account: "circleci-orb-testing"
8187
- run:
82-
name: Prepare distribution
83-
command: python setup.py sdist
88+
name: Assert environment variables have been set
89+
command: |
90+
if [ $CLOUDSMITH_TWINE_REPOSITORY_URL != "https://python.cloudsmith.io/financial-times/circleci-orb-testing/" ]
91+
then
92+
echo "Test failed: CLOUDSMITH_TWINE_REPOSITORY_URL has not been set correctly."
93+
exit 1
94+
fi
95+
if [ $CLOUDSMITH_TWINE_USERNAME != "circleci-orb-testing" ]
96+
then
97+
echo "Test failed: CLOUDSMITH_TWINE_USERNAME has not been set correctly."
98+
exit 1
99+
fi
100+
if [ -z $CLOUDSMITH_TWINE_PASSWORD ]
101+
then
102+
echo "Test failed: CLOUDSMITH_TWINE_PASSWORD has not been set."
103+
exit 1
104+
fi
105+
echo "All tests passed."
106+
107+
test-upload_package_using_twine:
108+
docker:
109+
- image: cimg/python:3.9
110+
resource_class: small
111+
steps:
112+
- checkout
113+
- run: python -m ensurepip --upgrade
114+
- run:
115+
name: Build source and wheel distributions
116+
command: |
117+
python -m pip install build --upgrade --user
118+
python -m build
119+
working_directory: .circleci/simplepkg-py
120+
- run:
121+
name: Install twine
122+
command: |
123+
python -m pip install twine --upgrade --user
124+
- cloudsmith-circleci/set_env_vars_for_twine:
125+
repository: "circleci-orb-testing"
126+
service_account: "circleci-orb-testing"
127+
- run:
128+
name: twine upload package to Cloudsmith
129+
command: |
130+
twine upload \
131+
--username $CLOUDSMITH_TWINE_USERNAME \
132+
--password $CLOUDSMITH_TWINE_PASSWORD \
133+
--repository-url $CLOUDSMITH_TWINE_REPOSITORY_URL \
134+
dist/*
135+
working_directory: .circleci/simplepkg-py
136+
137+
test-upload_package_using_cli:
138+
docker:
139+
- image: cimg/python:3.9
140+
resource_class: small
141+
steps:
142+
- checkout
143+
- run: python -m ensurepip --upgrade
144+
- run:
145+
name: Build source and wheel distributions
146+
command: |
147+
python -m pip install build --upgrade --user
148+
python -m build
84149
working_directory: .circleci/simplepkg-py
85150
- cloudsmith-circleci/upload_python_package:
86151
repository: "circleci-orb-testing"
87152
service_account: "circleci-orb-testing"
88-
package_path: .circleci/simplepkg-py/dist/simplepkg-0.0.1.tar.gz
153+
dist_dir: .circleci/simplepkg-py/dist
89154

90155
workflows:
91156
test-deploy:
@@ -98,9 +163,17 @@ workflows:
98163
- test-set_env_vars_for_pip:
99164
context: circleci-orb-publishing
100165
filters: *filters
101-
- test-upload_python_package:
166+
- test-set_env_vars_for_twine:
102167
context: circleci-orb-publishing
103168
filters: *filters
169+
- test-upload_package_using_twine:
170+
context: circleci-orb-publishing
171+
filters: *filters
172+
- test-upload_package_using_cli:
173+
context: circleci-orb-publishing
174+
filters: *filters
175+
requires:
176+
- test-upload_package_using_twine
104177
# The orb must be re-packed for publishing, and saved to the workspace.
105178
- orb-tools/pack:
106179
filters: *release-filters
@@ -113,7 +186,9 @@ workflows:
113186
- orb-tools/pack
114187
- test-authenticate_with_oidc
115188
- test-set_env_vars_for_pip
116-
- test-upload_python_package
189+
- test-set_env_vars_for_twine
190+
- test-upload_package_using_twine
191+
- test-upload_package_using_cli
117192
# Use a context to hold your publishing token.
118193
context: circleci-orb-publishing
119194
filters: *release-filters

src/@orb.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
version: 2.1
22

33
description: >
4-
An orb that allows you to use Cloudsmith in your CircleCI pipelines
5-
# What will your orb allow users to accomplish?
6-
# Descriptions should be short, simple, and informative.
7-
8-
# This information will be displayed in the orb registry and is not mandatory.
4+
Install packages from and publish packages to Cloudsmith using short-lived OIDC credentials
95
display:
10-
home_url: "https://github.com/Financial-Times/cloudsmith-circleci-orb"
11-
source_url: "https://github.com/Financial-Times/cloudsmith-circleci-orb"
12-
13-
# If your orb requires other orbs, you can import them like this. Otherwise remove the "orbs" stanza.
14-
# orbs:
15-
# hello: circleci/[email protected]
6+
home_url: "https://github.com/ft-circleci-orbs/cloudsmith-circleci-orb"
7+
source_url: "https://github.com/ft-circleci-orbs/cloudsmith-circleci-orb"

src/commands/authenticate_with_oidc.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
description:
22
Utility command to authenticate with Cloudsmith using OpenID Connect (OIDC) and if successful generate a short-lived
3-
OIDC token for use in subsequent requests to cloudsmith. The token is valid for up to 2 hours.
4-
5-
The environment variables CLOUDSMITH_SERVICE_ACCOUNT and CLOUDSMITH_OIDC_TOKEN are set.
3+
OIDC token for use in subsequent requests to cloudsmith. The token is valid for up to 2 hours. On completion the
4+
environment variables CLOUDSMITH_SERVICE_ACCOUNT and CLOUDSMITH_OIDC_TOKEN are set.
65
parameters:
76
service_account:
87
description: The identity/slug of the Cloudsmith service account to use when authenticating

src/commands/set_env_vars_for_pip.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
description:
2-
Authenticates to Cloudsmith and generates a pip index url string which is assigned to the CLOUDSMITH_PIP_INDEX_URL environment variable.
2+
Generate temporary Cloudsmith credentials using OIDC and construct a pip index URL string for a specific Cloudsmith
3+
repository and service account. On completion the command sets the CLOUDSMITH_PIP_INDEX_URL environment variable for
4+
use with pip. The index url includes Cloudsmith authentication credentials generated using OIDC.
35
parameters:
46
repository:
57
description: The identity/slug of the Cloudsmith repository
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
description:
2+
Generate temporary Cloudsmith credentials using OIDC and construct a repository URL for a specific Cloudsmith
3+
repository and service account. On completion the command sets the CLOUDSMITH_TWINE_REPOSITORY_URL,
4+
CLOUDSMITH_TWINE_USERNAME and CLOUDSMITH_TWINE_PASSWORD environment variables for use with twine.
5+
parameters:
6+
repository:
7+
description: The identity/slug of the Cloudsmith repository
8+
type: string
9+
service_account:
10+
description: The identity/slug of the Cloudsmith service account to use when authenticating with OIDC
11+
type: string
12+
steps:
13+
- authenticate_with_oidc:
14+
service_account: <<parameters.service_account>>
15+
- run:
16+
name: Cloudsmith - Configure domains
17+
command: <<include(scripts/configure_cloudsmith_domains.sh)>>
18+
- run:
19+
name: Cloudsmith - Configure repository
20+
command: |
21+
echo "export CLOUDSMITH_REPOSITORY=\"<<parameters.repository>>\"" >> $BASH_ENV
22+
echo "CLOUDSMITH_REPOSITORY=<<parameters.repository>>"
23+
- run:
24+
name: Cloudsmith - Set CLOUDSMITH_TWINE environment variables
25+
command: <<include(scripts/set_env_vars_for_twine.sh)>>
Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
description:
2-
Upload a python package to a Cloudsmith repository using the Cloudsmith CLI
2+
Generate temporary Cloudsmith credentials using OIDC and upload a python package to a Cloudsmith repository using the
3+
Cloudsmith CLI.
34
parameters:
45
repository:
56
description: The identity/slug of the Cloudsmith repository
67
type: string
78
service_account:
89
description: The identity/slug of the Cloudsmith service account to use when authenticating
910
type: string
10-
package_path:
11-
description: The location of the package files to upload
11+
dist_dir:
12+
description: The distribution directory where package source distribution and wheel files are located
1213
type: string
14+
default: "dist"
1315
steps:
1416
- run:
1517
name: Cloudsmith - Install CLI
1618
command: |
1719
python -m ensurepip --upgrade
1820
19-
echo ""
2021
echo "Installing cloudsmith-cli using pip ..."
2122
22-
python -m pip install cloudsmith-cli==1.1.1 --upgrade --user --extra-index-url=https://dl.cloudsmith.io/public/cloudsmith/cli/python/index/
23+
python -m pip install cloudsmith-cli --upgrade --user --extra-index-url=https://dl.cloudsmith.io/public/cloudsmith/cli/python/index/
2324
2425
echo ""
2526
echo "Cloudsmith CLI installed OK."
@@ -28,12 +29,39 @@ steps:
2829
- authenticate_with_oidc:
2930
service_account: <<parameters.service_account>>
3031
- run:
31-
name: Cloudsmith - Upload package
32+
name: Cloudsmith - Check dist_dir exists
3233
command: |
33-
echo ""
34-
echo "Uploading package <<parameters.package_path>> to Cloudsmith repository $CLOUDSMITH_ORGANISATION/<<parameters.repository>> ..."
34+
if [ -d "<<parameters.dist_dir>>" ]; then
35+
echo "<<parameters.dist_dir>> is a valid directory"
36+
else
37+
echo "<<parameters.dist_dir>> is not a directory"
38+
exit 1
39+
fi
40+
- run:
41+
name: Cloudsmith - Upload source distribution(s)
42+
command: |
43+
for filename in <<parameters.dist_dir>>/*.tar.gz
44+
do
45+
[ -f "$filename" ] || continue
3546
36-
cloudsmith push python --verbose --api-key "$CLOUDSMITH_OIDC_TOKEN" "$CLOUDSMITH_ORGANISATION/<<parameters.repository>>" "<<parameters.package_path>>"
47+
echo "Uploading source distribution $filename to Cloudsmith repository $CLOUDSMITH_ORGANISATION/<<parameters.repository>> ..."
3748
38-
echo ""
39-
echo "Package upload and synchronisation completed OK."
49+
cloudsmith push python --verbose --api-key "$CLOUDSMITH_OIDC_TOKEN" "$CLOUDSMITH_ORGANISATION/<<parameters.repository>>" "$filename"
50+
51+
echo ""
52+
echo "Package upload and synchronisation completed OK."
53+
done
54+
- run:
55+
name: Cloudsmith - Upload wheel distribution(s)
56+
command: |
57+
for filename in <<parameters.dist_dir>>/*.whl
58+
do
59+
[ -f "$filename" ] || continue
60+
61+
echo "Uploading wheel $filename to Cloudsmith repository $CLOUDSMITH_ORGANISATION/<<parameters.repository>> ..."
62+
63+
cloudsmith push python --verbose --api-key "$CLOUDSMITH_OIDC_TOKEN" "$CLOUDSMITH_ORGANISATION/<<parameters.repository>>" "$filename"
64+
65+
echo ""
66+
echo "Package upload and synchronisation completed OK."
67+
done
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ usage:
1010
- image: cimg/python:3.9
1111
steps:
1212
- checkout
13+
- run: python -m ensurepip --upgrade
1314
- ft-cloudsmith/set_env_vars_for_pip:
1415
repository: "your-repository-id"
1516
service_account: "your-service-account-id"

src/examples/pip_install_package.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
description: >
2-
Pip install a package from Cloudsmith.
2+
Install a package from Cloudsmith using pip.
33
usage:
44
version: 2.1
55
orbs:
@@ -10,6 +10,7 @@ usage:
1010
- image: cimg/python:3.9
1111
steps:
1212
- checkout
13+
- run: python -m ensurepip --upgrade
1314
- ft-cloudsmith/set_env_vars_for_pip:
1415
repository: "your-repository-id"
1516
service_account: "your-service-account-id"

src/examples/pip_install_requirements.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
description: >
2-
Pip install requirements from Cloudsmith.
2+
Install requirements from Cloudsmith using pip.
33
usage:
44
version: 2.1
55
orbs:
@@ -10,6 +10,7 @@ usage:
1010
- image: cimg/python:3.9
1111
steps:
1212
- checkout
13+
- run: python -m ensurepip --upgrade
1314
- ft-cloudsmith/set_env_vars_for_pip:
1415
repository: "your-repository-id"
1516
service_account: "your-service-account-id"
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
description: >
2-
Upload a python package to Cloudsmith.
2+
Upload a python package to Cloudsmith using the Cloudsmith CLI.
33
usage:
44
version: 2.1
55
orbs:
@@ -10,11 +10,15 @@ usage:
1010
- image: cimg/python:3.9
1111
steps:
1212
- checkout
13-
- run: python setup.py bdist_wheel --universal
13+
- run: python -m ensurepip --upgrade
14+
- run:
15+
name: Build source and wheel distributions
16+
command: |
17+
python -m pip install build --upgrade --user
18+
python -m build
1419
- ft-cloudsmith/upload_python_package:
1520
repository: "your-repository-id"
1621
service_account: "your-service-account"
17-
package_path: dist/your-package-0.0.1.tar.gz
1822
workflows:
1923
main:
2024
jobs:

0 commit comments

Comments
 (0)