Skip to content

Commit

Permalink
Manifest rebase script updates (zephyrproject-rtos#21)
Browse files Browse the repository at this point in the history
- Add pr_comment.py script which spoots out the tag info for both the
zephyr and zephyr-intel repos to be pasted into the respective PRs.

- Remove a duplicate line from the tag_manifest.py script.

- Use rebase branch name to get date stamp
It's preferable for the tag datestamp to match the branch datestamp to
help avoid confusion in the PR. i.e. Tag date doesn't match branch date
= confusing. So make 'em match. Extract the datestamp from the branch
 name.

In the event the branch is created the same day as tagging happens, can
just run without passing the branch.

Generally should not run the tagging before the branch is created, to
avoid mismatched branch and tag date mismatch.

Signed-off-by: Connor Graydon <connor.graydon@intel.com>

Signed-off-by: Connor Graydon <connor.graydon@intel.com>
  • Loading branch information
cjgraydon authored Sep 19, 2022
1 parent 1cb2ec0 commit bb05a55
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 10 deletions.
50 changes: 50 additions & 0 deletions src/scripts/pr_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
""" Generate the PR comments for the tagging
This scrip generates the PR comment to be added to both the zephyr and
zephyr-intel_PRs for the manifest update.
Working dir should be same as for tag_manifest.py.
This needs to run AFTER the tagging script.
Takes an argument of the tag that was pushed. i.e. zephyr-3.1.99-intel-20220902
Currently just splats the text to the screen for copy and paste. Will eventually
just push the comments to the respective PRs.
"""

import os
import sys
import argparse
from git import Repo
from git import Git


os.system("clear")


# Create the parser and add arguments
parser = argparse.ArgumentParser()
parser.add_argument(dest='tag', help="tag to create PR comments for")

# Parse and print the results
args = parser.parse_args()
print(args.tag)


tag = args.tag

# For testing
#tag = 'zephyr-3.1.99-intel-20220902'
#tag = "fmos-self-test"

workspace = "/srv/build/manifest" # or whatever your workdir is

for repo_name in ['zephyr', 'zephyr-intel']:
repo_path = os.path.join(workspace, repo_name)
repo = Repo(repo_path)
tags = repo.tags
for thing in tags:
if tag == thing.name:
print(f"{repo_name.title()} {thing.commit} has been tagged as {thing.name}")
52 changes: 42 additions & 10 deletions src/scripts/tag_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,26 @@
Working dir is set to /srv/buid/manifest. Change to your liking.
It takes an argument of the path to your ssh key for git repo access in the
format of:
Script takes two arguments. First is the path to your ssh key for git repo
access in the format of:
python3 tag_manifest.py /path/to/your/key/key_name
The second argument is the rebase branch name, if there is one. There should
pretty much always be one. The script takes that branch name and extracts the
date stamp portion for use in creating the tag. This way the tag and the rebase
branch datestamp match. This will match the PR information for easier
backtracking should we need to revert. Pass the branch like so....
python3 tag_manifest.py /path/to/your/key/key_name -b <branch name>
i.e.
python3 tag_manifest.py /path/to/your/key/key_name -b main-intel-20220916
If you do not pass a rebase branch name, the current date will be used. If you
use this THE SAME DAY as the rebase branch creation, all is well. If the branch
was created a day or more prior, pass the branch name in.
If the tag already exists on one or both of the remote repos, the script will
notify and exit.
Expand All @@ -27,8 +42,8 @@
TODO:
- Error checking
- Better arg parsing
- reuse of repos, rather than blind nuke
- Find rebase branches, get the most recent, and prompt for use, else generate.
- Reuse of repos, rather than blind nuke
- Deal with corner cases like tag on one repo, but not on other
- Allow passing in of working dir or use cwd.
Expand Down Expand Up @@ -82,7 +97,6 @@ def clone_repo(workspace, repo, git_ssh_identity_file):
print("Done.")



def tag_repo(tag, repos):

# Note that local_repo here is not the checked out repo dir. It's just
Expand Down Expand Up @@ -115,7 +129,6 @@ def tag_repo(tag, repos):
else:
ref_name = "main"
local_tags = local_repo.tags
local_tags = local_repo.tags
if tag in local_tags:
print(f"{repo.name.title()}: {tag} tag exists locally but not on remote. Using it.")
else:
Expand All @@ -125,7 +138,7 @@ def tag_repo(tag, repos):
return


def create_tag(workspace, repo):
def create_tag(workspace, repo, rebase_branch):

# Tag format:
# zephyr-3.1.99-intel-yyymmdd
Expand All @@ -134,7 +147,17 @@ def create_tag(workspace, repo):
PREFIX = repo.name + '-'
SUFFIX = "intel"

date_stamp = datetime.today().strftime('%Y%m%d')
# If we didn't pass in a rebase branch, generate today's date. If we have a
# rebase branch already, we take the date_stamp from that so the tag date
# matches the branch date. This makes finding correct version easier in
# case we have to restore from a tag.

if rebase_branch == "":
date_stamp = datetime.today().strftime('%Y%m%d')
else:
date_stamp = rebase_branch.split('-')[2]

print(f"Date Stamp: {date_stamp}")

repo_dir = os.path.join(workspace, repo.name)
os.chdir(repo_dir)
Expand Down Expand Up @@ -192,13 +215,22 @@ def push_tag(tag, repos):
# Create the parser and add arguments
parser = argparse.ArgumentParser()
parser.add_argument(dest='key_path', help="/path/to/key/key_name")
parser.add_argument('-b', '--branch',
required = False , dest='rbranch',
help="i.e. main-intel-20220916")

# Parse and print the results
args = parser.parse_args()
print(args.key_path)
print(f"Key Path: {args.key_path}")
print(f"Rebase Branch: {args.rbranch}")

git_ssh_identity_file = args.key_path

if args.rbranch:
rebase_branch = args.rbranch
else:
rebase_branch = ""

workspace = "/srv/build/manifest" # or whatever your workdir is

repo_list = [['zephyr', 'main-intel'], ['zephyr-intel', 'main']]
Expand Down Expand Up @@ -226,7 +258,7 @@ def push_tag(tag, repos):
clone_repo(workspace, repo, git_ssh_identity_file)

# Create the tag
tag = create_tag(workspace, zephyr_repo)
tag = create_tag(workspace, zephyr_repo, rebase_branch)
tag_repo(tag, repos)

# Make this better. Like don't just quit if y/n not selected.
Expand Down

0 comments on commit bb05a55

Please sign in to comment.