Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .github/workflows/autotag.yaml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/autotest.yml

This file was deleted.

46 changes: 0 additions & 46 deletions .github/workflows/triage_issues.yml

This file was deleted.

32 changes: 31 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,35 @@
"coverage-gutters.showLineCoverage": true,
"python.testing.pytestArgs": [
"tests"
]
],
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/*.pyc": {
"when": "$(basename).py"
},
"**/__pycache__": true,
"**/app.egg-info": true,
"**/env": true,
"**/.env.dist": true,
"**/*.log": true,
"**/.0": true
},
"workbench.colorCustomizations": {
"tab.activeBorder": "#ff0000",
"tab.unfocusedActiveBorder": "#000000",
"tab.activeBackground": "#045980"
},
"workbench.editor.wrapTabs": true,
"debug.toolBarLocation": "docked",
"python.formatting.provider": "autopep8",
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"python.REPL.enableREPLSmartSend": false
}
298 changes: 245 additions & 53 deletions README.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions __version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# coding: utf-8

__title__ = 'enpm611-ghactions'
__version__ = '1.4.0'
__author__ = 'ENPM611'
__url__ = 'https://github.com/enpm611/github-actions'
__description__ = ("Exercise to use GitHub Actions for CI/CD task.")
25 changes: 0 additions & 25 deletions app/string_utils.py

This file was deleted.

15 changes: 0 additions & 15 deletions config/issue-rules.yml

This file was deleted.

50 changes: 50 additions & 0 deletions deployment_scripts/update_release_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@


import os
import re
from datetime import datetime
from pathlib import Path


def get_current_version() -> str:
# Read version file
VERSION_FILE = Path("__version__.py")
version_text = VERSION_FILE.read_text()
# Extract current version string
match = re.search(r"__version__\s*=\s*['\"](\d+\.\d+\.\d+)['\"]", version_text)
if not match:
raise ValueError("Could not find __version__ in file.")
return match.group(1)


def update_release_notes() -> None:

# Read the environment variables that were passed in from
# the GitHub Action workflow.
pr_title: str = os.environ.get("PR_TITLE", "").strip()
pr_body: str = os.environ.get("PR_BODY", "").strip()
# Check for missing environment variables
if not pr_title:
raise ValueError("PR_TITLE environment variable is missing.")

# Get current version from version file
version: str = get_current_version()

# Create release note entry
date_str: str = datetime.utcnow().strftime("%Y-%m-%d")
entry_lines: list[str] = [
"",
f"## Release Notes — v{version} — {pr_title} ({date_str})",
"",
pr_body,
"",
]

# Append to README
with open("README.md", "a", encoding="utf-8") as f:
f.write("\n".join(entry_lines))

print("README updated with release notes.")

if __name__ == "__main__":
update_release_notes()
70 changes: 70 additions & 0 deletions deployment_scripts/update_version_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

"""
Bumps the version number in the `__version__.py` file when a Pull
Request is created.
"""


import re
import os
from pathlib import Path
from typing import Any, Literal


def get_current_version(version_text:str) -> str:
# Extract current version string
match = re.search(r"__version__\s*=\s*['\"](\d+\.\d+\.\d+)['\"]", version_text)
if not match:
raise ValueError("Could not find __version__ in file.")
return match.group(1)

def get_release_type() -> Literal["patch", "minor", "major"]:
""" Determine the type of release based on the PR title """

# Read release title from env
pr_title: str = os.environ.get("PR_TITLE", "").strip()
# Determine release type based on terms in title
if "minor" in pr_title.lower():
return "minor"
elif "major" in pr_title.lower():
return "major"
else:
return "patch"

def bump_version():

# Read version file
VERSION_FILE = Path("__version__.py")
version_text = VERSION_FILE.read_text()

old_version: str = get_current_version(version_text)
major, minor, patch = map(int, old_version.split("."))

# Increment based on the requested level
level: Literal['patch', 'minor', 'major'] = get_release_type()
if level == "patch":
patch += 1
elif level == "minor":
minor += 1
patch = 0
elif level == "major":
major += 1
minor = 0
patch = 0
else:
raise ValueError("level must be 'major', 'minor', or 'patch'")

new_version = f"{major}.{minor}.{patch}"

# Replace the version string in the file
new_text = version_text.replace(old_version,new_version)

VERSION_FILE.write_text(new_text)
print(f"Version bumped to {new_version}")
return new_version




if __name__ == "__main__":
bump_version()
3 changes: 3 additions & 0 deletions docs/github_actions_exercises.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pytest==8.3.3
textdistance==4.6.3
pytest==8.3.3
69 changes: 69 additions & 0 deletions spacedelivery/delivery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import math
from typing import Callable


class DeliveryMode:
NORMAL = 1
TURBO = 2
HYPERJUMP = 3


MODE_SPEED = {
DeliveryMode.NORMAL: 10, # light-minutes per hour
DeliveryMode.TURBO: 25,
DeliveryMode.HYPERJUMP: 100,
}

# Planet distances from “Galactic Pizza Hub” in light-minutes
PLANET_DISTANCE = {
"Mercury": 3,
"Venus": 2,
"Earth": 0.5,
"Mars": 4,
"Jupiter": 25,
"Saturn": 50,
"Neptune": 200,
}


def estimate_delivery_time(
planet: str,
mode: int = DeliveryMode.NORMAL,
surge_load: float = 1.0,
weather_delay_fn: Callable[[], float] = lambda: 0.0,
) -> float:
"""
Estimate total delivery time in hours.

- `planet`: destination planet name
- `mode`: delivery mode speed multiplier
- `surge_load`: factor (>=1); simulates high-order load
- `weather_delay_fn`: returns number of hours to add (stochastic)
"""

if planet not in PLANET_DISTANCE:
raise ValueError(f"Unknown destination: {planet}")

if surge_load < 1:
raise ValueError("surge_load must be >= 1")

if mode not in MODE_SPEED:
raise ValueError("Invalid delivery mode")

distance = PLANET_DISTANCE[planet] # light-minutes

# Base time
speed = MODE_SPEED[mode]
travel_time = distance / speed

# If distance is extremely large, apply nonlinear fatigue penalty
if distance > 100:
travel_time *= 1.2 # 20% fatigue penalty

# Weather delay (provided by injected function)
weather_delay = weather_delay_fn()
if weather_delay < 0:
raise ValueError("weather_delay_fn returned negative delay")

total_time = (travel_time * surge_load) + weather_delay
return round(total_time, 2)
Loading