Skip to content

Commit 7c83d11

Browse files
authored
Add python toolchain-script (#52)
* Add python toolchain-script * Release for 0.1.0-beta.11 * Add version file and update python releease script to correctly push on a release branch if on main * refactor script * refactor python script * Add space * Update script to match Go Script and clean up' * Change to correct file * Fix file path for defaults.py * Remove VAULT_ID * Remove GitHUB CLI Login as not needed * Make it two step release process * update path * Add readme for changelogs folder * Update readme * add v infront of tag * Update to match Go SDK and move files to root of repo * Fix function name * Add new line to end of files * Fix quotes * Update open file paths * Fix function naming * Add template files to correctly inject version/build numbers * Update to latest builds and version * Remove unnecessary variables * Edit Comment to be more accurate * Add spaces * Update to match Go SDK and fix templating * fix version and add recent changelog entry to the recent one * fix script * Fix release script * Fix comparison between build numbers * fix comparison to convert number to base 10 * Update python script to match latest go * Sync with latest changes in Go * Fix formatting * Fix more formatting issues * Update to only 1 changelog file and update script accordingly * Change changelog to release notes and update script accordingly * Update readme accordingly * Update variable name * Add new lines * Remove whiteline * Add newline
1 parent 64c13e4 commit 7c83d11

File tree

9 files changed

+183
-2
lines changed

9 files changed

+183
-2
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
release:
2+
src/release/scripts/release.sh
3+
4+
prep-release:
5+
src/release/scripts/prep-release.sh
6+
7+

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from sysconfig import get_platform
33
import platform
44
import os
5+
from src.release.version import SDK_VERSION
56

67
try:
78
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
@@ -43,7 +44,7 @@ def get_shared_library_data_to_include():
4344

4445
setup(
4546
name="onepassword",
46-
version="0.1.0-beta.11",
47+
version=SDK_VERSION,
4748
author="1Password",
4849
description="The 1Password Python SDK offers programmatic read access to your secrets in 1Password in an interface native to Python.",
4950
url="https://github.com/1Password/onepassword-sdk-python",

src/onepassword/defaults.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import platform
2+
from src.release.version import SDK_BUILD_NUMBER
23

34
SDK_LANGUAGE = "Python"
4-
SDK_VERSION = "0010011" # v0.1.0-beta.11
5+
SDK_VERSION = SDK_BUILD_NUMBER
56
DEFAULT_INTEGRATION_NAME = "Unknown"
67
DEFAULT_INTEGRATION_VERSION = "Unknown"
78
DEFAULT_REQUEST_LIBRARY = "net/http"

src/release/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## How to Prepare a Release for the Python SDK
2+
3+
Before running this script, the user must make sure that they have the write permissions to the Python SDK repository.
4+
5+
Step 1. Make any changes to the SDK as required on a feature branch or main branch.
6+
NOTE: If ran on a main branch, a release branch will be created.
7+
8+
Step 2. Go to the root of the repo and run
9+
```
10+
make prep-release
11+
```
12+
Follow the scripts instructions and the release has now been prepped.
13+
14+
Step 3. Ensure that the correct files have been updated - i.e. version/build files, release-notes has been updated. Suggest doing a `git diff` to see the changes.
15+
16+
Step 4. Ensure your GITHUB_TOKEN environment variable is set as this will allow you to create the tags/release and push it.
17+
18+
Step 5. If everything looks good, at the root of the repo, run:
19+
```
20+
make release
21+
```
22+
Step 6. Congratulations, you have released the newest Python SDK!

src/release/RELEASE-NOTES

Whitespace-only changes.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
3+
# Helper script to prepare a release for the Python SDK.
4+
5+
output_version_file="src/release/version.py"
6+
version_template_file="src/release/templates/version.tpl.py"
7+
8+
# Extracts the current build/version number for comparison and backup
9+
current_build=$(awk -F "['\"]" '/SDK_BUILD_NUMBER =/{print $2}' "$output_version_file")
10+
current_version=$(awk -F "['\"]" '/SDK_VERSION =/{print $2}' "$output_version_file")
11+
12+
# Function to execute upon exit
13+
cleanup() {
14+
echo "Performing cleanup tasks..."
15+
# Revert changes to file if any
16+
sed -e "s/{{ build }}/$current_build/" -e "s/{{ version }}/$current_version/" "$version_template_file" > "$output_version_file"
17+
exit 1
18+
}
19+
20+
# Set the trap to call the cleanup function on exit
21+
trap cleanup SIGINT
22+
23+
enforce_latest_code() {
24+
if [[ -n "$(git status --porcelain=v1)" ]]; then
25+
echo "ERROR: working directory is not clean."
26+
echo "Please stash your changes and try again."
27+
exit 1
28+
fi
29+
}
30+
31+
# Function to validate the version number format x.y.z(-beta.w)
32+
update_and_validate_version() {
33+
while true; do
34+
# Prompt the user to input the version number
35+
read -p "Enter the version number (format: x.y.z(-beta.w)): " version
36+
37+
# Validate the version number format
38+
if [[ "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-beta\.[0-9]+)?$ ]]; then
39+
if [[ "${current_version}" != "${version}" ]]; then
40+
# TODO: Check the less than case as well.
41+
echo "New version number is: ${version}"
42+
return 0
43+
else
44+
echo "Version hasn't changed."
45+
fi
46+
else
47+
echo "Invalid version number format: ${version}"
48+
echo "Please enter a version number in the 'x.y.z(-beta.w)' format."
49+
fi
50+
done
51+
}
52+
53+
# Function to validate the build number format.
54+
# SEMVER Format: Mmmppbb - 7 Digits
55+
update_and_validate_build() {
56+
while true; do
57+
# Prompt the user to input the build number
58+
read -p "Enter the build number (format: Mmmppbb): " build
59+
60+
# Validate the build number format
61+
if [[ "${build}" =~ ^[0-9]{7}$ ]]; then
62+
if (( 10#$current_build < 10#$build )); then
63+
# Write the valid build number to the file
64+
echo "New build number is: ${build}"
65+
return 0
66+
else
67+
echo "New build version should be higher than current build version."
68+
fi
69+
else
70+
echo "Invalid build number format: ${build}"
71+
echo "Please enter a build number in the 'Mmmppbb' format."
72+
fi
73+
done
74+
}
75+
76+
# Ensure working directory is clean
77+
enforce_latest_code
78+
79+
# Update and validate the version number
80+
update_and_validate_version
81+
82+
# Update and validate the build number
83+
update_and_validate_build
84+
85+
# Update version & build number in version.py
86+
sed -e "s/{{ build }}/$build/" -e "s/{{ version }}/$version/" "$version_template_file" > "$output_version_file"
87+
88+
printf "Press ENTER to edit the RELEASE-NOTES in your default editor...\n"
89+
read -r _ignore
90+
${EDITOR:-nano} "src/release/RELEASE-NOTES"
91+
92+
# Get Current Branch Name
93+
branch="$(git rev-parse --abbrev-ref HEAD)"
94+
95+
# if on main, then stash changes and create RC branch
96+
if [[ "${branch}" = "main" ]]; then
97+
branch=rc/"${version}"
98+
git stash
99+
git fetch origin
100+
git checkout -b "${branch}"
101+
git stash apply
102+
fi
103+
104+
# Add changes and commit/push to branch
105+
git add .
106+
git commit -S -m "Release v${version}"
107+
git push --set-upstream origin "${branch}"
108+
109+
echo "Release has been prepared..
110+
Make sure to double check version/build numbers in their appropriate files and
111+
changelog is correctly filled out.
112+
Once confirmed, run 'make release' to release the SDK!"
113+

src/release/scripts/release.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Helper script to release the Python SDK
4+
5+
set -e
6+
7+
# Read the contents of the files into variables
8+
version=$(awk -F "['\"]" '/SDK_VERSION =/{print $2}' "src/release/version.py")
9+
build=$(awk -F "['\"]" '/SDK_BUILD_NUMBER =/{print $2}' "src/release/version.py")
10+
release_notes=$(< src/release/RELEASE-NOTES)
11+
12+
13+
# Check if Github CLI is installed
14+
if ! command -v gh &> /dev/null; then
15+
echo "gh is not installed";\
16+
exit 1;\
17+
fi
18+
19+
# Ensure GITHUB_TOKEN env var is set
20+
if [ -z "${GITHUB_TOKEN}" ]; then
21+
echo "GITHUB_TOKEN environment variable is not set."
22+
exit 1
23+
fi
24+
25+
git tag -a -s "v${version}" -m "${version}"
26+
27+
# Push the tag to the branch
28+
git push origin tag "v${version}"
29+
30+
gh release create "v${version}" --title "Release ${version}" --notes "${release_notes}" --repo github.com/1Password/onepassword-sdk-python
31+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SDK_VERSION = "{{ version }}"
2+
SDK_BUILD_NUMBER = "{{ build }}"
3+

src/release/version.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SDK_VERSION = "0.1.0-beta.11"
2+
SDK_BUILD_NUMBER = "0010011"
3+

0 commit comments

Comments
 (0)