Skip to content

Commit

Permalink
Merge pull request #447 from chinapandaman/PPF-446
Browse files Browse the repository at this point in the history
PPF-446: create deploy script
  • Loading branch information
chinapandaman authored Jan 16, 2024
2 parents 422488d + bad1caf commit 110d4f8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ generate-new-pdf-samples:

compare-pdf-diffs:
bash ./scripts/pdf_diffs.sh

deploy:
bash ./scripts/create_release.sh
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pylint
pypdf
pytest
reportlab
requests
41 changes: 41 additions & 0 deletions scripts/create_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
"""Creates a GitHub release."""

import re
import sys

import requests

if __name__ == "__main__":
with open("PyPDFForm/__init__.py", encoding="utf8") as f:
version = re.search(r'__version__ = "(.*?)"', f.read()).group(1)

latest_version = sys.argv[1].replace("(", "").replace(")", "")
print(f"Latest deployed version: v{latest_version}.")
if latest_version == version:
sys.exit(f"v{latest_version} is already deployed.")

print(f"Bumping to: v{version}")
token = input("Enter GitHub Token: ")

url = "https://api.github.com/repos/chinapandaman/PyPDFForm/releases"
headers = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {token}",
}
body = {
"tag_name": f"v{version}",
"name": f"v{version}",
"generate_release_notes": True,
}

response = requests.post(
url=url,
headers=headers,
json=body,
)

if response.status_code == 201:
print(f"Successfully deployed v{version}.")
else:
print(f"Failed deploying v{version}. Status code: {response.status_code}.")
7 changes: 7 additions & 0 deletions scripts/create_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if [[ "$VIRTUAL_ENV" == "" ]]; then
source "./venv/bin/activate"
fi

echo "Fetching deployed versions..."
LATEST=$(pip index versions PyPDFForm | grep -oP '\(.*?\)')
python ./scripts/create_release.py "$LATEST"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
with open("README.md", mode="r", encoding="utf-8") as fh:
long_description = fh.read()

dev_dependencies = ["coverage", "jsonschema", "pylint", "pytest", "pudb"]
dev_dependencies = ["coverage", "jsonschema", "pylint", "pytest", "pudb", "requests"]

with open("requirements.txt", mode="r", encoding="utf-8") as requirements:
dependencies = [
Expand Down

0 comments on commit 110d4f8

Please sign in to comment.