Skip to content

Commit

Permalink
Merge with remote
Browse files Browse the repository at this point in the history
  • Loading branch information
RoaCode committed Oct 24, 2024
1 parent 8448175 commit c349371
Show file tree
Hide file tree
Showing 65 changed files with 11,575 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/tek-repo-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: tek-repo-lint
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
workflow_call:
# IMPORTANT: Any new jobs need to be added to the check-repo-lint-passed job to ensure they correctly gate code changes
jobs:
enforce-community-standards:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
filename:
- .github/CODEOWNERS
- README.@(md|rst)
- CODE_OF_CONDUCT.@(md|rst)
- CONTRIBUTING.@(md|rst)
- LICENSE.@(md|rst)
- SECURITY.@(md|rst)
- .github/ISSUE_TEMPLATE/bug_report.yml
- .github/ISSUE_TEMPLATE/feature_request.yml
- .github/PULL_REQUEST_TEMPLATE.md
- .github/dependabot.yml
- .github/workflows/codeql-analysis.yml
steps:
- uses: actions/checkout@v4
- name: Ensure ${{ matrix.filename }} exists
uses: andstor/file-existence-action@v3
with:
files: ${{ matrix.filename }}
ignore_case: false
follow_symbolic_links: false
fail: true # Set the step to fail if the file doesn't exist
# Check that all jobs passed
check-repo-lint-passed:
if: ${{ !cancelled() }}
needs: [enforce-community-standards]
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
70 changes: 70 additions & 0 deletions scripts/check_unreleased_changelog_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""This script will check for unreleased entries in the CHANGELOG.md file.
It will exit with a non-zero exit code if there are no unreleased entries.
It will also copy the necessary files into the template directory to properly render the CHANGELOG
and Release Notes.
"""

import pathlib
import re
import shutil

CHANGELOG_FILEPATH = pathlib.Path(__file__).parent.parent / "CHANGELOG.md"
TEMPLATE_CHANGELOG_FILEPATH = (
pathlib.Path(__file__).parent.parent
/ "python_semantic_release_templates"
/ ".previous_changelog_for_template.md"
)
TEMPLATE_RELEASE_NOTES_FILEPATH = (
pathlib.Path(__file__).parent.parent
/ "python_semantic_release_templates"
/ ".previous_release_notes_for_template.md"
)


def main() -> None:
"""Check for entries in the Unreleased section of the CHANGELOG.md file.
Raises:
SystemExit: Indicates no new entries were found.
"""
release_notes_content = ""
found_entries = False
with CHANGELOG_FILEPATH.open(mode="r", encoding="utf-8") as changelog_file:
tracking_unreleased = False
tracking_entries = False
for line in changelog_file:
if line.startswith(("___", "---")):
tracking_unreleased = False
tracking_entries = False
if tracking_unreleased:
release_notes_content += line
if line.startswith("## Unreleased"):
tracking_unreleased = True
if tracking_unreleased and line.startswith(
(
"### Added\n",
"### Changed\n",
"### Deprecated\n",
"### Removed\n",
"### Fixed\n",
"### Security\n",
)
):
tracking_entries = True
if tracking_entries and not found_entries:
found_entries = bool(re.match(r"^- \w+", line))

if not found_entries:
msg = f"No unreleased entries were found in {CHANGELOG_FILEPATH}."
raise SystemExit(msg)

# Copy the files to the correct location
shutil.copy(CHANGELOG_FILEPATH, TEMPLATE_CHANGELOG_FILEPATH)
with TEMPLATE_RELEASE_NOTES_FILEPATH.open("w", encoding="utf-8") as template_release_notes:
template_release_notes.write(release_notes_content.strip() + "\n")


if __name__ == "__main__":
main()
40 changes: 40 additions & 0 deletions scripts/create_post_version_for_testpypi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Create a post-release version for test.pypi.org."""

import argparse

from poetry.core.constraints.version import Version


def parse_arguments() -> argparse.Namespace:
"""Parse the command line arguments.
Returns:
The parsed Namespace.
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--version",
required=True,
type=Version.parse,
action="store",
dest="version",
help="Provide the current, latest version of the package",
)

return parser.parse_args()


def main() -> None:
"""Create and print a post-release version string for test.pypi.org."""
args = parse_arguments()
version: Version = args.version

new_post_release_num = 1
if version.post:
new_post_release_num += version.post.number

print(f"{'.'.join(str(x) for x in version.parts)}.post{new_post_release_num}")


if __name__ == "__main__":
main()
54 changes: 54 additions & 0 deletions scripts/project_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""This script modifies or gets the current project version in the pyproject.toml file."""

import argparse
import pathlib

import tomli
import tomli_w

from poetry.core.constraints.version import Version

PYPROJECT_FILE = pathlib.Path(f"{pathlib.Path(__file__).parent}/../pyproject.toml")


def parse_arguments() -> argparse.Namespace:
"""Parse the command line arguments.
Returns:
The parsed Namespace.
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--set-version",
required=False,
type=Version.parse,
action="store",
dest="set_version",
help="Provide the version to write to the pyproject.toml file",
)

return parser.parse_args()


def main() -> None:
"""Modify or get the project version."""
args = parse_arguments()
new_version: Version = args.set_version

# Read in the current data
with open(PYPROJECT_FILE, "rb") as file_handle:
pyproject_data = tomli.load(file_handle)

if new_version:
# Modify the version value
pyproject_data["tool"]["poetry"]["version"] = new_version.to_string()

# Write back the data to the file
with open(PYPROJECT_FILE, "wb") as file_handle:
tomli_w.dump(pyproject_data, file_handle)
else:
print(pyproject_data["tool"]["poetry"]["version"])


if __name__ == "__main__":
main()
76 changes: 76 additions & 0 deletions scripts/pypi_latest_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""Get the latest version from the index server."""

import argparse
import json

import requests

from poetry.core.constraints.version import Version


def parse_arguments() -> argparse.Namespace:
"""Parse the command line arguments.
Returns:
The parsed Namespace.
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--package",
required=True,
action="store",
dest="package",
help="Provide the package to get the latest version for",
)
parser.add_argument(
"--index",
action="store",
dest="index",
choices=["pypi", "test.pypi"],
default="pypi",
help="Provide the index to query for the latest version, one of (pypi|test.pypi)",
)

return parser.parse_args()


def get_latest_version(package_name: str, index: str) -> str:
"""Get the latest version of the provided package.
Args:
package_name: The name of the package to get the latest version of.
index: The index to check for the package, one of (pypi|test.pypi).
Returns:
A string containing the latest version of the package from the given index.
Raises:
SystemExit: Indicates there were no versions for the package.
"""
# This code mirrors code found in src/tm_devices/helpers/functions.py,
# in the check_for_update() function.
# If this code is updated, the helper function should be updated too.
url = f"https://{index}.org/pypi/{package_name}/json"
try:
response = requests.get(url, timeout=10)
releases = json.loads(response.text)["releases"]
version_list = sorted(releases, key=Version.parse, reverse=True)
latest_version = version_list[0]
except (IndexError, json.decoder.JSONDecodeError) as error:
msg = f"There were no versions found for the {package_name} package."
raise SystemExit(msg) from error

return latest_version


def main() -> None:
"""Get the latest version of the provided package."""
args = parse_arguments()
package = args.package
index = args.index
latest_version = get_latest_version(package, index)
print(latest_version)


if __name__ == "__main__":
main()
10 changes: 10 additions & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
maison<2.0.0
poetry
poetry-core
poetry-plugin-export
pre-commit
requests
toml-sort
tomli
tomli_w
yamlfix
Loading

0 comments on commit c349371

Please sign in to comment.