Skip to content
Draft
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
22 changes: 22 additions & 0 deletions .yamato/ngo-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ngo_release_preparation:
name: "NGO release preparation"
agent: { type: Unity::VM, flavor: b1.small, image: package-ci/ubuntu-22.04:v4 }
triggers:
recurring:
- branch: develop-2.0.0 # We make new releases from this branch
frequency: weekly # Run at some point every Saturday. Note that it's restricted to every 4th Saturday inside the script
rerun: always
commands:
- pip install PyGithub
- pip install GitPython
# This script checks if requirements for automated release preparations are fulfilled.
# It checks if it's the correct time to run the release automation (every 4th week, end of Netcode sprint), if there is anything in the CHANGELOG to release and if the release branch wasnb't already created.
- python Tools/scripts/ReleaseAutomation/verifyNetcodeReleaseConditions.py
# If the conditions are met, this script branches off, runs release.py that will set up Wrench, regenerate recipes, clean changelog etc and pushes the new release branch.
# By doing this we ensure that package is potentially release ready. Note that package version is already always corresponding to current package state
- python Tools/scripts/ReleaseAutomation/netcodeReleaseBranchCreation.py
# We still need to manually set up Packageworks but this script will already trigger required jobs so we don't need to wait for them.
# Additionally it will also trigger multiple builds with different configurations that we can use for Playtesting
- python Tools/scripts/ReleaseAutomation/triggerYamatoJobsForNetcodeReleaseValidation.py
# If the conditions are met, it will commit changelog update and patch package version bump (to reflect current state of the package on main branch)
- python Tools/scripts/ReleaseAutomation/commitNetcodeChangelogAndPackageVersionUpdates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""
Creates a pull request to update the changelog for a new release using the GitHub API.
Quite often the changelog gets distorted between the time we branch for the release and the time we will branch back.
To mitigate this we want to create changelog update PR straight away and merge it fast while proceeding with the release.

This script performs the following actions:
1. Reads the package version from the package.json file and updates the CHANGELOG.md file while also cleaning it from empty sections.
2. Updates the package version in the package.json file by incrementing the patch version to represent the current package state.
3. Commits the change and pushes to the branch.

Requirements:
- A GITHUB TOKEN with 'repo' scope must be available as an environment variable.
"""
#!/usr/bin/env python3
import os
import sys
from github import GithubException

UTILS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../Utils'))
sys.path.insert(0, UTILS_DIR)
from general_utils import get_package_version_from_manifest, update_changelog, update_package_version_by_patch # nopep8
from git_utils import get_local_repo, GithubUtils # nopep8
from config import getNetcodePackageName, getPackageManifestPath, getNetcodeGithubRepo, getDefaultRepoBranch, getPackageChangelogPath # nopep8

def updateNetcodeChangelogAndPackageVersionAndPush():
"""
The function updates the changelog and package version for NGO in anticipation of a new release.
This means that it will clean and update the changelog for the current package version, then it will add new Unreleased section template at the top
and finally it will update the package version in the package.json file by incrementing the patch version to signify the current state of the package.

This assumes that at the same time you already branched off for the release. Otherwise it may be confusing
"""

ngo_package_name = getNetcodePackageName()
ngo_manifest_path = getPackageManifestPath()
ngo_changelog_path = getPackageChangelogPath()
ngo_package_version = get_package_version_from_manifest(ngo_manifest_path)
ngo_github_repo = getNetcodeGithubRepo()
ngo_default_repo_branch_to_push_to = getDefaultRepoBranch() # The branch to which the changes will be pushed. For our purposes it's a default repo branch.
ngo_github_token = os.environ.get("GITHUB_TOKEN")

print(f"Using branch: {ngo_default_repo_branch_to_push_to} for pushing changes")

if not os.path.exists(ngo_manifest_path):
print(f" Path does not exist: {ngo_manifest_path}")
sys.exit(1)

if not os.path.exists(ngo_changelog_path):
print(f" Path does not exist: {ngo_changelog_path}")
sys.exit(1)

if ngo_package_version is None:
print(f"Package version not found at {ngo_manifest_path}")
sys.exit(1)

if not ngo_github_token:
print("Error: GITHUB_TOKEN environment variable not set.", file=sys.stderr)
sys.exit(1)

try:
# Initialize PyGithub and get the repository object
GithubUtils(ngo_github_token, ngo_github_repo)

commit_message = f"Updated changelog and package version for NGO in anticipation of v{ngo_package_version} release"

repo = get_local_repo()
repo.git.fetch()
repo.git.checkout(ngo_default_repo_branch_to_push_to)
repo.git.pull("origin", ngo_default_repo_branch_to_push_to)

# Update the changelog file with adding new [Unreleased] section
update_changelog(ngo_changelog_path, ngo_package_version, ngo_package_name, add_unreleased_template=True)
# Update the package version by patch to represent the "current package state" after release
update_package_version_by_patch(ngo_manifest_path)

repo.git.add(ngo_changelog_path)
repo.git.add(ngo_manifest_path)
repo.index.commit(commit_message, skip_hooks=True)
repo.git.push("origin", ngo_default_repo_branch_to_push_to)

print(f"Successfully updated and pushed the changelog on branch: {ngo_default_repo_branch_to_push_to}")

except GithubException as e:
print(f"An error occurred with the GitHub API: {e.status}", file=sys.stderr)
print(f"Error details: {e.data}", file=sys.stderr)
sys.exit(1)
except Exception as e:
print(f"An unexpected error occurred: {e}", file=sys.stderr)
sys.exit(1)

if __name__ == "__main__":
updateNetcodeChangelogAndPackageVersionAndPush()
53 changes: 53 additions & 0 deletions Tools/scripts/ReleaseAutomation/netcodeReleaseBranchCreation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
This script automates the creation of a release branch for the NGO package.

It performs the following steps:
1. Creates a new release branch named 'release/<version>'.
2. Executes the release.py script that prepares branch for release by
updating changelog and ValidationExceptions.
3. Commits all changes made by the script.
4. Pushes the new branch to the remote repository.
"""
#!/usr/bin/env python3
import sys
import os

UTILS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../Utils'))
sys.path.insert(0, UTILS_DIR)
from general_utils import get_package_version_from_manifest # nopep8
from git_utils import create_branch_execute_commands_and_push # nopep8
from config import getPackageManifestPath, getNetcodeReleaseBranchName, getNetcodeGithubRepo # nopep8

def createToolsReleaseBranch():
"""
Creates a new release branch for the NGO package.
It also runs release.py script that prepares the branch for release by updating the changelog, ValidationExceptions etc
"""

ngo_manifest_path = getPackageManifestPath()
ngo_package_version = get_package_version_from_manifest(ngo_manifest_path)
ngo_github_repo = getNetcodeGithubRepo()
ngo_release_branch_name = getNetcodeReleaseBranchName(ngo_package_version)
ngo_github_token = os.environ.get("GITHUB_TOKEN")

if not os.path.exists(ngo_manifest_path):
print(f" Path does not exist: {ngo_manifest_path}")
sys.exit(1)

if ngo_package_version is None:
print(f"Package version not found at {ngo_manifest_path}")
sys.exit(1)

if not ngo_github_token:
print("Error: GITHUB_TOKEN environment variable not set.", file=sys.stderr)
sys.exit(1)

commit_message = f"Preparing Netcode package of version {ngo_package_version} for the release"
command_to_run_on_release_branch = ['python', 'Tools/scripts/release.py']

create_branch_execute_commands_and_push(ngo_github_token, ngo_github_repo, ngo_release_branch_name, commit_message, command_to_run_on_release_branch)



if __name__ == "__main__":
createToolsReleaseBranch()
Loading
Loading