Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
ci: python script to check version
Browse files Browse the repository at this point in the history
  • Loading branch information
AH-dark committed Sep 22, 2024
1 parent ccf5bc4 commit 8a0d319
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
91 changes: 91 additions & 0 deletions latest-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import subprocess
import requests
from dataclasses import dataclass
from dataclasses_json import dataclass_json
from typing import Any, List, Optional


@dataclass_json
@dataclass
class Packages:
full: str
no_content: Optional[str]
new_bundled: Optional[str]
partial: Optional[bool]
rollback: Optional[bool]


@dataclass_json
@dataclass
class Offer:
response: str
download: str
locale: str
packages: Packages
current: str
version: str
php_version: str
mysql_version: str
new_bundled: Optional[str]
partial_version: Optional[bool]
new_files: Optional[bool] = None


@dataclass_json
@dataclass
class WordPressVersionCheck:
offers: List[Offer]
translations: List[Any]


def get_latest_version():
url = "https://api.wordpress.org/core/version-check/1.7/"
response = requests.get(url)
response.raise_for_status() # Check if the request was successful
data = response.json()

# Deserialize JSON data directly into WordPressVersionCheck object
version_info = WordPressVersionCheck.from_dict(data)

# Print out the latest version information
latest_offer = version_info.offers[0]

return latest_offer.version


def compare_current_version(latest_version):
# Compare the current version with the latest version
with open(".current-version", "r+") as file:
content = file.read()

if content != latest_version:
# Write the latest version to the file
file.truncate(0)
file.seek(0)
file.write(latest_version)

return True
else:
return False


def git_commit(version):
# Add changes to the staging area
subprocess.run(["git", "add", ".current-version"], check=True)

# Commit the changes with the provided commit message
subprocess.run(
["git", "commit", "-m", f"Update WordPress to version {version}"],
check=True,
)

print("Commit successful!")


if __name__ == "__main__":
version = get_latest_version()
is_update = compare_current_version(version)
if is_update:
git_commit(version)

print(is_update)
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests
dataclasses-json

0 comments on commit 8a0d319

Please sign in to comment.