Skip to content
Closed
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
26 changes: 26 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Deploy to GitHub Pages

on:
push:
branches: ["main"]

permissions:
contents: read
pages: write
id-token: write

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Upload static site
uses: actions/upload-pages-artifact@v2
with:
path: .

- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Add Release Notes to README

on:
pull_request:
types: [opened]

jobs:
update_readme:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Increase version number
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
python deployment/update_version_number.py

- name: Update release notes
env:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_BODY: ${{ github.event.pull_request.body }}
run: |
python deployment/update_release_notes.py

- name: Commit changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git commit -m "Add release notes for PR #${{ github.event.pull_request.number }}" || echo "No changes to commit"
git push
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Python CI Pipeline

on:
push:
branches: ["development"]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install Dependencies
run: pip install -r requirements.txt

- name: Run tests
run: pytest -q
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
}
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,35 @@ After you created the file and copied the action above, push the change to the r
* **Task C**: Add a test case to either test file and push your changes to your repository. Check the run of the action to see what status is finishes with.

* **Task D**: You will notice that the action shows a red x after it has completed its run. Investigate why that action failed. Resolve the issue and push to the repository to trigger the action again.




Task 1

Automated testing on commit

a) Create a new branch called `test` and push it to the repository. Then create a PR for that branch.
b) Observe the test results. If there is a bug, update the test case to match the value that is returned by the function.
c) Push the updated code. Observe the test results.



Task 2

Add release notes to README

a) Create a new branch called `release` and push it to the repository.
b) Then create a PR for that branch and add a bulleted list of changes.
b) Check that the release notes are added to the `README.md` file.


Task 3

Deploy on merge

a) Create a new branch called `deploy1` and push it to the repository. Then create a PR for that branch.
b) Merge the PR into `main`.
c) Navigate to the deployed app
d) Change the app title and create a new PR. Merge the PR into `main`. Navigate to the deployed app again.Observe the changes.

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.3.8'
__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.

50 changes: 50 additions & 0 deletions deployment/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/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: 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
Loading
Loading