Skip to content

Commit

Permalink
initial git repo tool POC
Browse files Browse the repository at this point in the history
  • Loading branch information
kbroch-rivosinc committed Nov 6, 2024
1 parent bd88ffe commit 8170caa
Show file tree
Hide file tree
Showing 12 changed files with 564 additions and 0 deletions.
43 changes: 43 additions & 0 deletions projects/rvi-repo-manifest/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

ORGS := \
riscv-collab \
riscv-software-src \
riscv \
riscv-non-isa \
riscv-admin \
riscv-software-src \
riscv-collab \
riscv-android-src

TOOL := ./generate-manifests.sh
BUILD_DIR := generated
ALL_ORGS_XML := all-rvi-orgs.xml

ORGS_XML := $(addsuffix .xml, $(ORGS))

.PHONY: build-xml build-all-rvi-orgs-xml

default: build-all-rvi-orgs-xml

build-xml:
$(MAKE) $(ORGS_XML)

build-all-rvi-orgs-xml: build-xml
@echo '<?xml version="1.0" encoding="UTF-8"?>' > $(BUILD_DIR)/$(ALL_ORGS_XML)
@echo '<manifest>' >> $(BUILD_DIR)/$(ALL_ORGS_XML)
@for item in $(ORGS_XML); do echo " <include name=\"$$item\" />" >> $(BUILD_DIR)/$(ALL_ORGS_XML); done
@echo '</manifest>' >> $(BUILD_DIR)/$(ALL_ORGS_XML)

%.xml:
$(TOOL) $(BUILD_DIR)/$@ $*
cp _common.xml $(BUILD_DIR)/.

clean:
rm -rf $(BUILD_DIR/*.xml)

clean-all:
rm -rf $(BUILD_DIR)

# Debug variables
print-%:
@echo $* = $($*)
52 changes: 52 additions & 0 deletions projects/rvi-repo-manifest/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
= RVI repos manifest

RVI has many link:https://lf-riscv.atlassian.net/wiki/spaces/HOME/pages/16154706/GitHub+Repo+Map[github org's] with many repositories that represent the work being done. There are tools that make it easier to work with multiple repos. This POC provides one example.

== Details

This POC show how to do the following:

* use github CLI tool `gh` and `jq` to generate a manifest (XML listing of multiple repos)
* use link:https://gerrit.googlesource.com/git-repo/[git `repo` tool] to work with the repos in that manifest

NOTE: `repo` has many features that won't be covered in here or even needed (like `upload`ing changeset to gerrit server)

=== Prerequisites

* install and configure (authorize) link:https://cli.github.com/[`gh`]
* install link:https://jqlang.github.io/jq/[`jq`]
* Install link:https://gerrit.googlesource.com/git-repo/#install[git `repo` tool]

=== Usage

=== Generating a manifest file

Although manifest files can be created manually, a bash script is used here to do it automatically.

==== Using git `repo` tool

Similarly to cloning a single repo, the first step in using `repo` is to link:https://source.android.com/docs/setup/reference/repo#init[initialize] a directory with the configuration (manifest file). This should be done in an empty dir.

[source, bash]
----
mkdir rvi-repos && cd rvi-repos
repo init -u https://github.com/riscv-admin/docs-sig -m projects/rvi-repo-manifest/generated/all-rvi-orgs.xml -g all,-riscv-android-src
----

=== Pros and cons

* Pros
** perform git commands on multiple repos at the same time
* Cons
** manifests manually generated so additions or deletions of repos aren't automatic
*** deletions especially will generate a `repo rsync` failure for that given repo

== References

List of multi-repo tools:

* https://gerrit.googlesource.com/git-repo/
* https://manicli.com/
* https://github.com/nosarthur/gita
* https://github.com/fabioz/mu-repo
* https://github.com/asottile/all-repos
5 changes: 5 additions & 0 deletions projects/rvi-repo-manifest/_common.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="origin" fetch="ssh://[email protected]"/>
<default revision="refs/heads/main" remote="origin" sync-j="4"/>
</manifest>
74 changes: 74 additions & 0 deletions projects/rvi-repo-manifest/generate-manifests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

MAX_REPOS=1000

#################################################################
# SW PREREQ's
# Check if gh is installed
if ! command -v gh &> /dev/null
then
echo "ERROR: gh CLI could not be found. Please install it first."
exit 1
fi

# Check if jq is installed
if ! command -v jq &> /dev/null
then
echo "ERROR: jq could not be found. Please install it first."
exit 1
fi

#################################################################
# Check if correct number of arguments are provided
if [ $# -lt 2 ]; then
echo "Usage: $0 <output_file> <org1> [org2] [org3] ..."
exit 1
fi

# Get the output file name from the first argument
output_file="$1"
shift # Remove the first argument (output file) from the list
mkdir -p "$(dirname "$output_file")"

# Create or clear the output file
> "$output_file"

# List of organizations from command line arguments
org_list="$@"

# XML header
xml_header='<?xml version="1.0" encoding="UTF-8"?>
<!-- GENERATED FILE DO NOT EDIT -->
<!-- https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.md -->
<manifest>
<include name="_common.xml" />'

echo "$xml_header" > "$output_file"

# Loop through each organization
for org in "${org_list[@]}"; do
echo "Fetching repositories for organization: $org"

# Get list of repositories for the organization
repos=$(gh repo list -L $MAX_REPOS --no-archived --source $org --json name --jq '.[].name')

# Loop through each repository
for repo in $repos; do
# Get default branch and topics
repo_info=$(gh repo view "$org/$repo" --json defaultBranchRef --jq '{db: .defaultBranchRef.name}')

default_branch=$(echo $repo_info | jq -r '.db')

# Add repository information to the XML file
repo_entry=" <project name='$org/$repo' revision='$default_branch' groups='$org' />"
echo "$repo_entry" >> $output_file
done
done

xml_footer="
</manifest>"

# Close the root element
echo $xml_footer >> $output_file

echo "XML manifest generated: $output_file"
5 changes: 5 additions & 0 deletions projects/rvi-repo-manifest/generated/_common.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="origin" fetch="ssh://[email protected]"/>
<default revision="refs/heads/main" remote="origin" sync-j="4"/>
</manifest>
11 changes: 11 additions & 0 deletions projects/rvi-repo-manifest/generated/all-rvi-orgs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<include name="riscv-collab.xml" />
<include name="riscv-software-src.xml" />
<include name="riscv.xml" />
<include name="riscv-non-isa.xml" />
<include name="riscv-admin.xml" />
<include name="riscv-software-src.xml" />
<include name="riscv-collab.xml" />
<include name="riscv-android-src.xml" />
</manifest>
104 changes: 104 additions & 0 deletions projects/rvi-repo-manifest/generated/riscv-admin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- GENERATED FILE DO NOT EDIT -->
<!-- https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.md -->
<manifest>
<include name="_common.xml" />
<project name='riscv-admin/riscv-landscape' revision='main' groups='riscv-admin' />
<project name='riscv-admin/composable-custom-extensions' revision='main' groups='riscv-admin' />
<project name='riscv-admin/help' revision='main' groups='riscv-admin' />
<project name='riscv-admin/sig-soft-cpu' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-performance-event-sampling' revision='main' groups='riscv-admin' />
<project name='riscv-admin/post-quantum-cryptography' revision='main' groups='riscv-admin' />
<project name='riscv-admin/vector' revision='main' groups='riscv-admin' />
<project name='riscv-admin/bod-report' revision='main' groups='riscv-admin' />
<project name='riscv-admin/fp' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-scalar-efficiency' revision='main' groups='riscv-admin' />
<project name='riscv-admin/security' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-getting-started-guide' revision='main' groups='riscv-admin' />
<project name='riscv-admin/performance-events' revision='main' groups='riscv-admin' />
<project name='riscv-admin/tech-newsletter' revision='main' groups='riscv-admin' />
<project name='riscv-admin/cheri-tg' revision='main' groups='riscv-admin' />
<project name='riscv-admin/policies' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-toolchains-runtimes' revision='master' groups='riscv-admin' />
<project name='riscv-admin/integrated-matrix-extension' revision='main' groups='riscv-admin' />
<project name='riscv-admin/perf-analysis' revision='main' groups='riscv-admin' />
<project name='riscv-admin/debug-trace-perf-mon' revision='main' groups='riscv-admin' />
<project name='riscv-admin/docs.riscv.org' revision='main' groups='riscv-admin' />
<project name='riscv-admin/spec-plan-editor' revision='main' groups='riscv-admin' />
<project name='riscv-admin/labs-doc' revision='main' groups='riscv-admin' />
<project name='riscv-admin/ml-ai-apps-sig' revision='main' groups='riscv-admin' />
<project name='riscv-admin/iopmp' revision='main' groups='riscv-admin' />
<project name='riscv-admin/dev-partners' revision='main' groups='riscv-admin' />
<project name='riscv-admin/server-soc' revision='main' groups='riscv-admin' />
<project name='riscv-admin/datacenter' revision='main' groups='riscv-admin' />
<project name='riscv-admin/psabi' revision='master' groups='riscv-admin' />
<project name='riscv-admin/timing-fences' revision='main' groups='riscv-admin' />
<project name='riscv-admin/external-debug-security' revision='main' groups='riscv-admin' />
<project name='riscv-admin/template-docs-rtd' revision='main' groups='riscv-admin' />
<project name='riscv-admin/.github' revision='main' groups='riscv-admin' />
<project name='riscv-admin/docs-sig' revision='main' groups='riscv-admin' />
<project name='riscv-admin/app-tools-software' revision='master' groups='riscv-admin' />
<project name='riscv-admin/riscv-brs' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-memory-tagging' revision='main' groups='riscv-admin' />
<project name='riscv-admin/isa-infra' revision='main' groups='riscv-admin' />
<project name='riscv-admin/packed-simd' revision='main' groups='riscv-admin' />
<project name='riscv-admin/groups' revision='main' groups='riscv-admin' />
<project name='riscv-admin/uarch-side-channels' revision='main' groups='riscv-admin' />
<project name='riscv-admin/profiles-sig' revision='main' groups='riscv-admin' />
<project name='riscv-admin/prs' revision='main' groups='riscv-admin' />
<project name='riscv-admin/architecture-test' revision='master' groups='riscv-admin' />
<project name='riscv-admin/sig-high-performance-io' revision='main' groups='riscv-admin' />
<project name='riscv-admin/qemu' revision='main' groups='riscv-admin' />
<project name='riscv-admin/server-platform' revision='main' groups='riscv-admin' />
<project name='riscv-admin/sail-simulators-ci' revision='main' groups='riscv-admin' />
<project name='riscv-admin/control-transfer-records' revision='main' groups='riscv-admin' />
<project name='riscv-admin/runtime-integrity' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-ecosystem-dashboard' revision='main' groups='riscv-admin' />
<project name='riscv-admin/rpmi' revision='main' groups='riscv-admin' />
<project name='riscv-admin/cheri-sig' revision='main' groups='riscv-admin' />
<project name='riscv-admin/debug' revision='main' groups='riscv-admin' />
<project name='riscv-admin/jira-to-google' revision='main' groups='riscv-admin' />
<project name='riscv-admin/graphics' revision='main' groups='riscv-admin' />
<project name='riscv-admin/tech-groupsio-membership' revision='main' groups='riscv-admin' />
<project name='riscv-admin/jira-reports' revision='main' groups='riscv-admin' />
<project name='riscv-admin/attached-matrix-extension' revision='main' groups='riscv-admin' />
<project name='riscv-admin/rvv-intrinsics' revision='main' groups='riscv-admin' />
<project name='riscv-admin/template-group-admin' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-tech-org' revision='main' groups='riscv-admin' />
<project name='riscv-admin/lightweight-isolation' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-tech-calendar' revision='main' groups='riscv-admin' />
<project name='riscv-admin/software' revision='main' groups='riscv-admin' />
<project name='riscv-admin/ecosystem' revision='main' groups='riscv-admin' />
<project name='riscv-admin/spmp' revision='main' groups='riscv-admin' />
<project name='riscv-admin/high-assurance-cryptography' revision='main' groups='riscv-admin' />
<project name='riscv-admin/ai-ml' revision='main' groups='riscv-admin' />
<project name='riscv-admin/smmtt' revision='main' groups='riscv-admin' />
<project name='riscv-admin/trusted-computing' revision='main' groups='riscv-admin' />
<project name='riscv-admin/exchange' revision='main' groups='riscv-admin' />
<project name='riscv-admin/ap-tee' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-arc' revision='main' groups='riscv-admin' />
<project name='riscv-admin/committee-code-of-conduct' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-tech-staff-tasks' revision='main' groups='riscv-admin' />
<project name='riscv-admin/ap-tee-io' revision='main' groups='riscv-admin' />
<project name='riscv-admin/m-mode-isolation' revision='main' groups='riscv-admin' />
<project name='riscv-admin/android' revision='main' groups='riscv-admin' />
<project name='riscv-admin/Managed-Runtimes' revision='master' groups='riscv-admin' />
<project name='riscv-admin/perf-modeling' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-embedded-sig' revision='main' groups='riscv-admin' />
<project name='riscv-admin/security-model' revision='main' groups='riscv-admin' />
<project name='riscv-admin/privileged-software' revision='main' groups='riscv-admin' />
<project name='riscv-admin/unified-discovery' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-ras' revision='main' groups='riscv-admin' />
<project name='riscv-admin/soc-infra' revision='main' groups='riscv-admin' />
<project name='riscv-admin/hypervisors' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-srt' revision='main' groups='riscv-admin' />
<project name='riscv-admin/control-flow-integrity' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-uefi-edk2-docs' revision='master' groups='riscv-admin' />
<project name='riscv-admin/riscv-safety' revision='main' groups='riscv-admin' />
<project name='riscv-admin/simulator' revision='main' groups='riscv-admin' />
<project name='riscv-admin/riscv-technology-hc' revision='master' groups='riscv-admin' />
<project name='riscv-admin/marketing' revision='main' groups='riscv-admin' />
<project name='riscv-admin/isa-infrastructure' revision='main' groups='riscv-admin' />
<project name='riscv-admin/unpriv-isa' revision='main' groups='riscv-admin' />
<project name='riscv-admin/priv-isa' revision='main' groups='riscv-admin' />
</manifest>
Loading

0 comments on commit 8170caa

Please sign in to comment.