Skip to content

Commit f052a45

Browse files
ci: Update for Netcode Release Automation (#3828)
* Updated naming and changed behavior from making direct commit to creating a PR * re-enabled job trigger * test change added * corrected error * Updated CI regeneration scripts * Updated PR description validation check to exclude automations * corrected PR title * corrected CI typo * added temp bypass * Updated meta * typo * corrected regenerate scripts * test * Stashing changes before pulling origin * Updated flow to use trigger branch as base for releasing * Handling trigger branch detached head * excluding release branch from target branches * Revert "excluding release branch from target branches" This reverts commit ce462ce. * Revert "Handling trigger branch detached head" This reverts commit 921587b. * Revert "Updated flow to use trigger branch as base for releasing" This reverts commit 6e08459. * reverted changelog addition
1 parent 075c75a commit f052a45

File tree

13 files changed

+147
-75
lines changed

13 files changed

+147
-75
lines changed

.github/workflows/pr-description-validation.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ jobs:
2929
script: |
3030
const pr = context.payload.pull_request;
3131
const body = pr.body || '';
32+
33+
// List of users to skip description validation
34+
// This should be automations where we don't care that much about the description format
35+
const skipUsersPrefixes = [
36+
'unity-renovate',
37+
'svc-'
38+
];
39+
40+
// If PR author is in the skip list, exit early
41+
const author = pr.user.login;
42+
console.log(`PR author: ${author}`);
43+
if (skipUsersPrefixes.some(prefix => author.startsWith(prefix))) {
44+
console.log(`Skipping PR description check for user: ${author}`);
45+
return;
46+
}
3247
3348
// List of mandatory PR sections
3449
const requiredSections = [

.yamato/ngo-publish.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
ngo_release_preparation:
22
name: "NGO release preparation"
33
agent: { type: Unity::VM, flavor: b1.small, image: package-ci/ubuntu-22.04:v4 }
4-
#triggers:
5-
# recurring:
6-
# - branch: develop-2.0.0 # We make new releases from this branch
7-
# frequency: "10 ? * 1" # Runs every Sunday at 10:00 AM
4+
triggers:
5+
recurring:
6+
- branch: develop-2.0.0 # We make new releases from this branch
7+
frequency: "10 ? * 1" # Runs every Sunday at 10:00 AM
88
commands:
99
- pip install PyGithub
1010
- pip install GitPython

.yamato/project.metafile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ test_platforms:
8484
type: Unity::VM::osx
8585
image: package-ci/macos-13:v4
8686
flavor: m1.mac
87+
larger_flavor: m1.mac
8788
standalone: IOS
8889
base: mac
8990
architecture: arm64

Tools/CI/regenerate.bat

Lines changed: 0 additions & 2 deletions
This file was deleted.

Tools/CI/regenerate.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

Tools/regenerate-ci.cmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@echo off
2+
3+
cd /d "%~dp0.."
4+
dotnet run --project "Tools\CI\NGO.Cookbook.csproj" %*
5+
if %errorlevel% neq 0 exit /b %errorlevel%

Tools/regenerate-ci.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
set -e # fail on first error
4+
5+
SCRIPT_DIR=$(dirname "$0")
6+
dotnet run --project $SCRIPT_DIR/CI/NGO.Cookbook.csproj "$@"

Tools/scripts/ReleaseAutomation/release_config.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ def is_branch_present(self, branch_name):
2727
if ghe.status == 404:
2828
return False # Branch does not exist
2929
raise Exception(f"An error occurred with the GitHub API: {ghe.status}", data=ghe.data)
30+
31+
def create_pull_request(self, title, body, head, base):
32+
try:
33+
return self.repo.create_pull(title=title, body=body, head=head, base=base)
34+
35+
except GithubException as ghe:
36+
raise Exception(f"Failed to create pull request: {ghe.status}", ghe.data) from ghe
37+
38+
def request_reviews(self, pr, reviewers):
39+
if not reviewers:
40+
return
41+
42+
try:
43+
pr.create_review_request(reviewers=reviewers)
44+
except GithubException as ghe:
45+
raise Exception(f"Failed to request reviews: {ghe.status}", ghe.data) from ghe
46+
3047

3148
class ReleaseConfig:
3249
"""A simple class to hold all shared configuration."""
@@ -45,7 +62,17 @@ def __init__(self):
4562

4663
self.package_version = get_package_version_from_manifest(self.manifest_path)
4764
self.release_branch_name = f"release/{self.package_version}" # Branch from which we want to release
48-
self.commit_message = f"Updated changelog and package version for Netcode in anticipation of v{self.package_version} release"
65+
66+
self.release_commit_message = f"Updated changelog and package version for Netcode in anticipation of v{self.package_version} release"
67+
68+
self.pr_branch_name = f"netcode-update-after-{self.package_version}-release-branch-creation" # Branch from which we will create PR to default branch with relevant changes after release branch is created
69+
self.pr_commit_message = f"chore: Updated aspects of Netcode package in anticipation of v{self.package_version} release"
70+
self.pr_body = f"This PR was created in sync with branching of {self.release_branch_name}. It includes changes that should land on the default Netcode branch ({self.default_repo_branch}) to reflect the new state of the package after the v{self.package_version} release:\n" \
71+
f"1) Updated CHANGELOG.md by adding new [Unreleased] section template at the top and cleaning the Changelog for the current release.\n" \
72+
f"2) Updated package version in package.json by incrementing the patch version to signify the current state of the package.\n" \
73+
f"3) Updated package version in ValidationExceptions.json to match the new package version.\n\n" \
74+
f"Please review and merge this PR to keep the default branch up to date with the latest package state after the release. Those changes can land immediately OR after the release was finalized but make sure that the Changelog will be merged correctly as sometimes some discrepancies may be introduced due to new entries being introduced meantime\n"
75+
self.pr_reviewers = ["michal-chrobot"]
4976

5077
GITHUB_TOKEN_NAME = "NETCODE_GITHUB_TOKEN"
5178
YAMATO_API_KEY_NAME = "NETCODE_YAMATO_API_KEY"

Tools/scripts/ReleaseAutomation/run_release_preparation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
sys.path.insert(0, PARENT_DIR)
88

99
from ReleaseAutomation.release_config import ReleaseConfig
10-
from Utils.git_utils import create_branch_execute_commands_and_push
10+
from Utils.git_utils import create_release_branch
1111
from Utils.verifyReleaseConditions import verifyReleaseConditions
12-
from Utils.commitChangelogAndPackageVersionUpdates import commitChangelogAndPackageVersionUpdates
12+
from Utils.createPrAfterRelease import createPrAfterRelease
1313
from Utils.triggerYamatoJobsForReleasePreparation import trigger_release_preparation_jobs
1414

1515
def PrepareNetcodePackageForRelease():
@@ -27,13 +27,13 @@ def PrepareNetcodePackageForRelease():
2727

2828
try:
2929
print("\nStep 2: Creating release branch...")
30-
create_branch_execute_commands_and_push(config)
30+
create_release_branch(config)
3131

3232
print("\nStep 3: Triggering Yamato validation jobs...")
3333
trigger_release_preparation_jobs(config)
3434

35-
print("\nStep 4: Committing changelog and version updates...")
36-
commitChangelogAndPackageVersionUpdates(config)
35+
print("\nStep 4: Creating PR with needed changes to default branch...")
36+
createPrAfterRelease(config)
3737

3838
except Exception as e:
3939
print("\n--- ERROR: Netcode release process failed ---", file=sys.stderr)

Tools/scripts/Utils/commitChangelogAndPackageVersionUpdates.py renamed to Tools/scripts/Utils/createPrAfterRelease.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from Utils.general_utils import get_package_version_from_manifest, update_changelog, update_package_version_by_patch, update_validation_exceptions
2020
from Utils.git_utils import get_local_repo
2121

22-
def commitChangelogAndPackageVersionUpdates(config: ReleaseConfig):
22+
def createPrAfterRelease(config: ReleaseConfig):
2323
"""
2424
The function updates the changelog and package version of the package in anticipation of a new release.
2525
This means that it will
@@ -33,13 +33,26 @@ def commitChangelogAndPackageVersionUpdates(config: ReleaseConfig):
3333

3434
try:
3535
if not config.github_manager.is_branch_present(config.default_repo_branch):
36-
print(f"Branch '{config.default_repo_branch}' does not exist. Exiting.")
37-
sys.exit(1)
36+
raise Exception(f"Branch '{config.default_repo_branch}' does not exist. Exiting.")
37+
38+
author = Actor(config.commiter_name, config.commiter_email)
39+
committer = Actor(config.commiter_name, config.commiter_email)
3840

3941
repo = get_local_repo()
4042
repo.git.fetch('--prune', '--prune-tags')
43+
44+
# Check if there are uncommitted changes that would block checkout
45+
# Stash them if they exist to allow checkout to proceed
46+
has_uncommitted_changes = repo.is_dirty()
47+
if has_uncommitted_changes:
48+
print("Uncommitted changes detected. Stashing before checkout...")
49+
repo.git.stash('push', '-m', 'Auto-stash before checkout for release PR creation')
50+
4151
repo.git.checkout(config.default_repo_branch)
4252
repo.git.pull("origin", config.default_repo_branch)
53+
54+
# Create a new branch for the release changes PR to default branch
55+
repo.git.checkout('-b', config.pr_branch_name)
4356

4457
# Update the changelog file with adding new [Unreleased] section
4558
update_changelog(config.changelog_path, config.package_version, add_unreleased_template=True)
@@ -51,13 +64,14 @@ def commitChangelogAndPackageVersionUpdates(config: ReleaseConfig):
5164
repo.git.add(config.manifest_path)
5265
repo.git.add(config.validation_exceptions_path)
5366

54-
author = Actor(config.commiter_name, config.commiter_email)
55-
committer = Actor(config.commiter_name, config.commiter_email)
67+
repo.index.commit(config.pr_commit_message, author=author, committer=committer, skip_hooks=True)
68+
repo.git.push("origin", config.pr_branch_name)
5669

57-
repo.index.commit(config.commit_message, author=author, committer=committer, skip_hooks=True)
58-
repo.git.push("origin", config.default_repo_branch)
70+
github = config.github_manager
71+
pr = github.create_pull_request(title=config.pr_commit_message, body=config.pr_body, head=config.pr_branch_name, base=config.default_repo_branch)
72+
github.request_reviews(pr, config.pr_reviewers)
5973

60-
print(f"Successfully updated and pushed the changelog on branch: {config.default_repo_branch}")
74+
print(f"Successfully updated and created the PR targeting: {config.default_repo_branch}")
6175

6276
except GithubException as e:
6377
print(f"An error occurred with the GitHub API: {e.status}", file=sys.stderr)

0 commit comments

Comments
 (0)