diff --git a/phase1/master.cfg b/phase1/master.cfg index 9967eaf..6f2b406 100644 --- a/phase1/master.cfg +++ b/phase1/master.cfg @@ -109,6 +109,9 @@ def ini_parse_branch(section): pb_port = inip1.get("port") or 9989 feeds_host_override = inip1.get("feeds_host_override", "").strip() +if feeds_host_override: + repo_url = re.sub(r"git\.openwrt\.org/openwrt", feeds_host_override, repo_url) + # This is the dictionary that the buildmaster pays attention to. We also use # a shorter alias to save typing. c = BuildmasterConfig = {} @@ -920,6 +923,18 @@ def prepareFactory(target): ) ) + # keep existing checkouts aligned to the configured repo_url if it changes via feeds_host_override + factory.addStep( + ShellCommand( + name="setorigin", + description="Syncing Git origin URL", + descriptionDone="Git origin URL synced", + command=["sh", "-c", 'test ! -d .git || git remote set-url origin "$REPO_URL"'], + env={"REPO_URL": repo_url}, + haltOnFailure=True, + ) + ) + # workaround for https://github.com/openwrt/buildbot/issues/5 factory.addStep( Git( @@ -996,32 +1011,15 @@ def prepareFactory(target): ) ) - factory.addStep( - ShellCommand( - name="feeds-backup", - description="Backing up feeds.conf.default", - descriptionDone="feeds.conf.default backed up", - command=["cp", "-p", "feeds.conf.default", "feeds.conf.default.bak"], - doStepIf=IsFeedsHostOverrideEnabled, - haltOnFailure=True, - ) - ) - factory.addStep( ShellCommand( name="feeds-override", - description="Overriding feeds host", - descriptionDone="Feeds host overridden", - command=[ - "sed", - "-i", - "-E", - Interpolate( - "s;git.openwrt.org/(feed|project);%(kw:host)s;", - host=GetFeedsHostOverride, - ), - "feeds.conf.default", - ], + description="Creating feeds.conf with host override", + descriptionDone="feeds.conf with override created", + command=Interpolate( + "sed -E 's;git.openwrt.org/(feed|project);%(kw:host)s;' feeds.conf.default > feeds.conf", + host=GetFeedsHostOverride, + ), doStepIf=IsFeedsHostOverrideEnabled, haltOnFailure=True, ) @@ -1039,24 +1037,24 @@ def prepareFactory(target): ) ) + # feed factory.addStep( ShellCommand( - name="feeds-restore", - description="Restoring feeds.conf.default", - descriptionDone="feeds.conf.default restored", - command="test -f feeds.conf.default.bak && mv -f feeds.conf.default.bak feeds.conf.default || true", - doStepIf=IsFeedsHostOverrideEnabled, + name="installfeeds", + description="Installing feeds", + command=["./scripts/feeds", "install", "-a"], + env=MakeEnv(tryccache=True), haltOnFailure=True, ) ) - # feed factory.addStep( ShellCommand( - name="installfeeds", - description="Installing feeds", - command=["./scripts/feeds", "install", "-a"], - env=MakeEnv(tryccache=True), + name="feeds-cleanup", + description="Removing feeds.conf override", + descriptionDone="feeds.conf override removed", + command=["rm", "-f", "feeds.conf"], + doStepIf=IsFeedsHostOverrideEnabled, haltOnFailure=True, ) ) diff --git a/phase2/config.ini.example b/phase2/config.ini.example index eda9763..fcb6f06 100644 --- a/phase2/config.ini.example +++ b/phase2/config.ini.example @@ -10,6 +10,7 @@ status_user = example status_password = example port = 9990 persistent = false +feeds_host_override = git_ssh = true git_ssh_key = -----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEAuCJwo6OmrRDxcGfsMgBhq0vdzp2ZIdqnedFH8u6tVYLt9WDU diff --git a/phase2/master.cfg b/phase2/master.cfg index 7af1b30..939d688 100644 --- a/phase2/master.cfg +++ b/phase2/master.cfg @@ -69,6 +69,8 @@ if ini.has_option("phase2", "port"): if ini.has_option("phase2", "persistent"): persistent = ini.getboolean("phase2", "persistent") +feeds_host_override = ini.get("phase2", "feeds_host_override", fallback="").strip() + c['workers'] = [] for section in ini.sections(): @@ -134,6 +136,9 @@ repo_branch = "main" if ini.has_option("repo", "branch"): repo_branch = ini.get("repo", "branch") +if feeds_host_override: + repo_url = re.sub(r"git\.openwrt\.org/openwrt", feeds_host_override, repo_url) + usign_key = None usign_comment = "untrusted comment: " + repo_branch.replace("-", " ").title() + " key" @@ -151,6 +156,7 @@ archnames = [ ] if not os.path.isdir(work_dir+'/source.git'): subprocess.call(["git", "clone", "--depth=1", "--branch="+repo_branch, repo_url, work_dir+'/source.git']) else: + subprocess.call(["git", "remote", "set-url", "origin", repo_url], cwd = work_dir+'/source.git') subprocess.call(["git", "pull"], cwd = work_dir+'/source.git') os.makedirs(work_dir+'/source.git/tmp', exist_ok=True) @@ -319,6 +325,13 @@ def IsSignEnabled(step): IsUsignEnabled(step) or IsApkSigningEnabled(step) or IsGpgSigningEnabled(step) ) +def IsFeedsHostOverrideEnabled(step): + return bool(feeds_host_override) + +@util.renderer +def GetFeedsHostOverride(props): + return feeds_host_override + @defer.inlineCallbacks def getNewestCompleteTime(bldr): """Returns the complete_at of the latest completed and not SKIPPED @@ -546,6 +559,18 @@ for arch in arches: command = ["./ccache.sh"], haltOnFailure = True)) + factory.addStep(ShellCommand( + name = "feeds-override", + description = "Creating feeds.conf with host override", + descriptionDone = "feeds.conf with override created", + workdir = "build/sdk", + command = Interpolate( + "sed -E 's;git.openwrt.org/(feed|project);%(kw:host)s;' feeds.conf.default > feeds.conf", + host=GetFeedsHostOverride, + ), + doStepIf = IsFeedsHostOverrideEnabled, + haltOnFailure = True)) + factory.addStep(ShellCommand( name = "updatefeeds", description = "Updating feeds", @@ -560,6 +585,15 @@ for arch in arches: command = ["./scripts/feeds", "install", "-a"], haltOnFailure = True)) + factory.addStep(ShellCommand( + name = "feeds-cleanup", + description = "Removing feeds.conf override", + descriptionDone = "feeds.conf override removed", + workdir = "build/sdk", + command = ["rm", "-f", "feeds.conf"], + doStepIf = IsFeedsHostOverrideEnabled, + haltOnFailure = True)) + factory.addStep(ShellCommand( name = "logclear", description = "Clearing failure logs",