Skip to content

Commit ea5044d

Browse files
committed
Create script to update repo skeleton #80
Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent 7a22968 commit ea5044d

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

etc/scripts/update_skeleton.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) nexB Inc. and others. All rights reserved.
5+
# ScanCode is a trademark of nexB Inc.
6+
# SPDX-License-Identifier: Apache-2.0
7+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
8+
# See https://github.com/nexB/skeleton for support or download.
9+
# See https://aboutcode.org for more information about nexB OSS projects.
10+
#
11+
12+
from pathlib import Path
13+
import os
14+
import subprocess
15+
16+
import click
17+
18+
19+
NEXB_PUBLIC_REPO_NAMES=[
20+
"aboutcode-toolkit",
21+
"ahocode",
22+
"bitcode",
23+
"clearcode-toolkit",
24+
"commoncode",
25+
"container-inspector",
26+
"debian-inspector",
27+
"deltacode",
28+
"elf-inspector",
29+
"extractcode",
30+
"fetchcode",
31+
"gemfileparser2",
32+
"gh-issue-sandbox",
33+
"go-inspector",
34+
"heritedcode",
35+
"license-expression",
36+
"license_copyright_pipeline",
37+
"nuget-inspector",
38+
"pip-requirements-parser",
39+
"plugincode",
40+
"purldb",
41+
"pygmars",
42+
"python-inspector",
43+
"sanexml",
44+
"saneyaml",
45+
"scancode-analyzer",
46+
"scancode-toolkit-contrib",
47+
"scancode-toolkit-reference-scans",
48+
"thirdparty-toolkit",
49+
"tracecode-toolkit",
50+
"tracecode-toolkit-strace",
51+
"turbo-spdx",
52+
"typecode",
53+
"univers",
54+
]
55+
56+
57+
@click.command()
58+
@click.help_option("-h", "--help")
59+
def update_skeleton_files(repo_names=NEXB_PUBLIC_REPO_NAMES):
60+
"""
61+
Update project files of nexB projects that use the skeleton
62+
63+
This script will:
64+
- Clone the repo
65+
- Add the skeleton repo as a new origin
66+
- Create a new branch named "update-skeleton-files"
67+
- Merge in the new skeleton files into the "update-skeleton-files" branch
68+
69+
The user will need to save merge commit messages that pop up when running
70+
this script in addition to resolving the merge conflicts on repos that have
71+
them.
72+
"""
73+
74+
# Create working directory
75+
work_dir_path = Path("/tmp/update_skeleton/")
76+
if not os.path.exists(work_dir_path):
77+
os.makedirs(work_dir_path, exist_ok=True)
78+
79+
for repo_name in repo_names:
80+
# Move to work directory
81+
os.chdir(work_dir_path)
82+
83+
# Clone repo
84+
repo_git = f"git@github.com:nexB/{repo_name}.git"
85+
subprocess.run(["git", "clone", repo_git])
86+
87+
# Go into cloned repo
88+
os.chdir(work_dir_path / repo_name)
89+
90+
# Add skeleton as an origin
91+
subprocess.run(["git", "remote", "add", "skeleton", "git@github.com:nexB/skeleton.git"])
92+
93+
# Fetch skeleton files
94+
subprocess.run(["git", "fetch", "skeleton"])
95+
96+
# Create and checkout new branch
97+
subprocess.run(["git", "checkout", "-b", "update-skeleton-files"])
98+
99+
# Merge skeleton files into the repo
100+
subprocess.run(["git", "merge", "skeleton/main", "--allow-unrelated-histories"])
101+
102+
103+
if __name__ == "__main__":
104+
update_skeleton_files()

0 commit comments

Comments
 (0)