Skip to content

Commit cd28bd8

Browse files
authored
Add automated releasing, reset version to v0.1.0 (#40)
1 parent 9fe6273 commit cd28bd8

12 files changed

+194
-166
lines changed

.codeclimate.yml

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ plugins:
4242
# Markdown
4343
markdownlint:
4444
enabled: true
45+
checks:
46+
# Disable checks that conflict with our preferred changelog format
47+
MD022:
48+
enabled: false
49+
MD032:
50+
enabled: false
4551
issue_override:
4652
severity: info # Should be redundant as CC says markdownlint defaults to
4753
# info already, but including it here to remind us it's so

CHANGELOG.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9-
## [8.0.0] - 2022-09-08
9+
## [0.1.0] - 2023-02-14
1010

1111
### Added
12-
1312
- Add support for Role Memberships endpoint
1413
[conjur-api-python#30](https://github.com/cyberark/conjur-api-python/pull/33)
1514
- Add support for Check Privilege endpoint
@@ -36,14 +35,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3635
[conjur-api-python#19](https://github.com/cyberark/conjur-api-python/pull/19)
3736

3837
### Changed
39-
4038
- Include system truststore certs even if cert_file config is present
4139
[conjur-api-python#37](https://github.com/cyberark/conjur-api-python/pull/37)
4240
- Abstract authentication flow into new `AuthenticationStrategyInterface`
4341
[conjur-api-python#20](https://github.com/cyberark/conjur-api-python/pull/20)
4442
- Store API key in `CreditentialsData` object
4543
[conjur-api-python#23](https://github.com/cyberark/conjur-api-python/pull/23)
4644

47-
48-
[Unreleased]: https://github.com/cyberark/conjur-api-python/compare/v8.0.0...HEAD
49-
[8.0.0]: https://github.com/cyberark/conjur-api-python/releases/tag/v8.0.0
45+
[Unreleased]: https://github.com/cyberark/conjur-api-python/compare/v0.1.0...HEAD
46+
[0.1.0]: https://github.com/cyberark/conjur-api-python/releases/tag/v0.1.0

CONTRIBUTING.md

+34-18
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,40 @@ The connection parameters to Conjur are:
111111

112112
## Releases
113113

114-
This section describes the requirements for releasing a Conjur python SDK.
115-
116-
### Checklist
117-
118-
1. Create a release branch from main
119-
2. Verify that all changes related to the version are applied to `README`,`CHANGELOG` and `NOTICES` files
120-
3. Verify that Jenkins Pipeline is green
121-
4. Bump the version in `conjur_api.__init__.py` file
122-
5. Merge the branch into main
123-
6. Create and push a tag using the following naming convention: v<version_number>, for example `v8.1.0`
124-
7. Follow the Jenkins Pipeline and verify that it's green and that `Publish to PyPI` step ended successfully
125-
8. Log into https://pypi.org and verify that the package uploaded successfully
126-
9. Import the package locally by running `pip install conjur-api==<version_number>`, for example
127-
`pip install conjur-api==8.1.0`
128-
10. Create a release page from the tag.
129-
[Click here for assistance](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository)
130-
11. On the releases page, write all the changes affecting this version (This can be taken from the changelog)
131-
12. Update all stakeholders that the release was completed successfully
114+
Releases should be created by maintainers only. To create and promote a release, follow the instructions in this section.
115+
116+
### Update the changelog and notices
117+
118+
**NOTE:** If the Changelog and NOTICES.txt are already up-to-date, skip this
119+
step and promote the desired release build from the main branch.
120+
121+
1. Create a new branch for the version bump.
122+
1. Based on the changelog content, determine the new version number and update.
123+
1. Review the git log and ensure the [changelog](CHANGELOG.md) contains all
124+
relevant recent changes with references to GitHub issues or PRs, if possible.
125+
1. Review the changes since the last tag, and if the dependencies have changed
126+
revise the [NOTICES](NOTICES.txt) to correctly capture the included
127+
dependencies and their licenses / copyrights.
128+
1. Commit these changes - `Bump version to x.y.z` is an acceptable commit
129+
message - and open a PR for review.
130+
131+
### Release and Promote
132+
133+
1. Merging into the main branch will automatically trigger a release build.
134+
If successful, this release can be promoted at a later time.
135+
1. Jenkins build parameters can be utilized to promote a successful release
136+
or manually trigger aditional releases as needed.
137+
1. Reference the [internal automated release doc](https://github.com/conjurinc/docs/blob/master/reference/infrastructure/automated_releases.md#release-and-promotion-process)
138+
for releasing and promoting.
139+
140+
### Manual Verification
141+
142+
1. Log into [PyPI](https://pypi.org)and verify that the package uploaded successfully
143+
1. Import the package locally by running `pip install conjur-api==<version_number>`,
144+
for example `pip install conjur-api==0.0.5`
145+
1. Verify git release page from the tag.
146+
[Click here for assistance](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository)
147+
132148

133149
## Contributing workflow
134150

Jenkinsfile

+70-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
#!/usr/bin/env groovy
22

3+
// Automated release, promotion and dependencies
4+
properties([
5+
// Include the automated release parameters for the build
6+
release.addParams(),
7+
// Dependencies of the project that should trigger builds
8+
// dependencies([ ])
9+
])
10+
11+
// Performs release promotion. No other stages will be run
12+
if (params.MODE == "PROMOTE") {
13+
release.promote(params.VERSION_TO_PROMOTE) { sourceVersion, targetVersion, assetDirectory ->
14+
// Any assets from sourceVersion Github release are available in assetDirectory
15+
// Any version number updates from sourceVersion to targetVersion occur here
16+
// Any publishing of targetVersion artifacts occur here
17+
// Anything added to assetDirectory will be attached to the Github Release
18+
19+
// Publish target version.
20+
sh "summon -e production ./ci/publish/publish_package ${targetVersion}"
21+
}
22+
return
23+
}
24+
325
pipeline {
426
agent { label 'executor-v2' }
527

@@ -8,13 +30,48 @@ pipeline {
830
buildDiscarder(logRotator(numToKeepStr: '30'))
931
}
1032

33+
environment {
34+
// Sets the MODE to the specified or autocalculated value as appropriate
35+
MODE = release.canonicalizeMode()
36+
}
37+
1138
triggers {
1239
cron(getDailyCronString())
1340
}
41+
1442
stages {
15-
stage('Linting') {
43+
// Aborts any builds triggered by another project that wouldn't include any changes
44+
stage ("Skip build if triggering job didn't create a release") {
45+
when {
46+
expression {
47+
MODE == "SKIP"
48+
}
49+
}
50+
steps {
51+
script {
52+
currentBuild.result = 'ABORTED'
53+
error("Aborting build because this build was triggered from upstream, but no release was built")
54+
}
55+
}
56+
}
57+
58+
stage('Validate') {
59+
parallel {
60+
stage('Changelog') {
61+
steps { sh './ci/test/parse-changelog.sh' }
62+
}
63+
stage('Linting') {
1664
steps { sh './ci/test/test_linting.sh' }
65+
}
1766
}
67+
}
68+
69+
// Generates a VERSION file based on the current build number and latest version in CHANGELOG.md
70+
stage('Validate changelog and set version') {
71+
steps {
72+
updateVersion("CHANGELOG.md", "${BUILD_NUMBER}")
73+
}
74+
}
1875

1976
stage('Unit tests') {
2077
steps {
@@ -55,27 +112,25 @@ pipeline {
55112
}
56113
}
57114

58-
stage('Publish to PyPI') {
59-
steps {
60-
echo 'Check if publish is required'
61-
sh 'summon -e production ./ci/publish/run_is_publish_required'
62-
63-
echo 'Publish to PyPi'
64-
sh 'summon -e production ./ci/publish/publish_package'
65-
}
115+
stage('Release') {
66116
when {
67-
tag "v*"
117+
expression {
118+
MODE == "RELEASE"
119+
}
120+
}
121+
122+
steps {
123+
release { billOfMaterialsDirectory, assetDirectory, toolsDirectory ->
124+
// Publish release artifacts to all the appropriate locations
125+
// Copy any artifacts to assetDirectory to attach them to the Github release
126+
}
68127
}
69128
}
70129
}
130+
71131
post {
72132
always {
73133
cleanupAndNotify(currentBuild.currentResult)
74134
}
75-
unsuccessful {
76-
script {
77-
cleanupAndNotify(currentBuild.currentResult, notify_team_teams = 'Secrets Manager HQ')
78-
}
79-
}
80135
}
81136
}

ci/publish/Dockerfile.publish

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:20.04
1+
FROM ubuntu:23.04
22
ENV INSTALL_DIR=/opt/conjur-api-python3
33
ENV DEBIAN_FRONTEND noninteractive
44
RUN apt-get update && \

ci/publish/build_publish_container

-5
This file was deleted.

ci/publish/is_publish_required

-60
This file was deleted.

ci/publish/publish_package

+65-31
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,71 @@
11
#!/bin/bash -e
22

3-
CURRENT_DIR=$(pwd)
3+
main() {
4+
TWINE_REPOSITORY_URL="https://upload.pypi.org/legacy/"
5+
replace_version="$1"
46

5-
REQUIRED_VARS=( "TWINE_REPOSITORY_URL"
6-
"TWINE_USERNAME"
7-
"TWINE_PASSWORD" )
7+
check_required_vars
8+
update_version
9+
build_publish_container
10+
publish_to_pypi
11+
}
812

9-
# Sanity check
10-
for required_var in "${REQUIRED_VARS[@]}"; do
11-
if [[ "${!required_var}" == "" ]]; then
12-
echo "ERROR: '$required_var' not set!"
13+
check_required_vars() {
14+
REQUIRED_VARS=( "TWINE_USERNAME"
15+
"TWINE_PASSWORD" )
16+
17+
for required_var in "${REQUIRED_VARS[@]}"; do
18+
if [[ "${!required_var}" == "" ]]; then
19+
echo "ERROR: '$required_var' not set! Ensure you are running this script with Summon."
20+
exit 1
21+
fi
22+
done
23+
}
24+
25+
update_version() {
26+
if [ -z "$replace_version" ]; then
27+
echo "No version argument supplied"
1328
exit 1
29+
else
30+
echo "Updating module to version $replace_version"
31+
local path="./conjur_api/__init__.py"
32+
local sed_expr="s/__version__ =.+/__version__ = \"$replace_version\"/"
33+
34+
if [[ "$OSTYPE" == "darwin"* ]]; then
35+
sed -E -i "" -e "$sed_expr" "$path"
36+
else
37+
sed -E -i -e "$sed_expr" "$path"
38+
fi
1439
fi
15-
done
16-
17-
echo "Publishing to PyPI..."
18-
rm -rf $CURRENT_DIR/dist/
19-
docker run --rm \
20-
-t \
21-
-e TWINE_REPOSITORY_URL \
22-
-e TWINE_USERNAME \
23-
-e TWINE_PASSWORD \
24-
-v "$(pwd):/opt/conjur-api-python3" \
25-
conjur-api-python3-publish bash -exc "
26-
echo 'Installing new versions of pip and wheel...'
27-
/usr/bin/env pip3 install --upgrade pip wheel
28-
29-
echo 'Building distributable package...'
30-
/usr/bin/env python3 -m build
31-
32-
echo 'Testing artifacts in dist/*'
33-
/usr/bin/env twine check dist/*
34-
35-
echo 'Publishing package to \$TWINE_REPOSITORY_URL using account '\$TWINE_USERNAME'...'
36-
/usr/bin/env twine upload --repository $TWINE_REPOSITORY_URL dist/*
37-
"
40+
}
41+
42+
build_publish_container() {
43+
docker build -f ./ci/publish/Dockerfile.publish \
44+
-t conjur-api-python3-publish \
45+
.
46+
}
47+
48+
publish_to_pypi() {
49+
echo "Publishing to PyPI..."
50+
rm -rf ./dist/
51+
docker run --rm \
52+
-t \
53+
-e TWINE_REPOSITORY_URL \
54+
-e TWINE_USERNAME \
55+
-e TWINE_PASSWORD \
56+
conjur-api-python3-publish bash -exc "
57+
echo 'Installing new versions of pip and wheel...'
58+
/usr/bin/env pip3 install --upgrade pip wheel
59+
60+
echo 'Building distributable package...'
61+
/usr/bin/env python3 -m build
62+
63+
echo 'Testing artifacts in dist/*'
64+
/usr/bin/env twine check dist/*
65+
66+
echo 'Publishing package to '\$TWINE_REPOSITORY_URL' using account '\$TWINE_USERNAME'...'
67+
/usr/bin/env twine upload --skip-existing --repository-url $TWINE_REPOSITORY_URL dist/*
68+
"
69+
}
70+
71+
main "$@"

0 commit comments

Comments
 (0)