Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
boulder/cli: Implement update command to update version in recipes
Browse files Browse the repository at this point in the history
Updates an existing recipe (stone.yml) with a new version and tarball,
provided by the user. Additionally, it recomputes the hash of the new
tarball and increments the release.

PoC only because dyaml is a shitter and doesn't provide any formatting
options when dumping a yaml file to disk making the thing look my left ball
and my big toe had a baby.
  • Loading branch information
joebonrichie committed Jan 7, 2023
1 parent 793ff50 commit d5d2d89
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/boulder/cli/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module boulder.cli;
public import moss.core.cli;
public import boulder.cli.build_command;
public import boulder.cli.new_command;
public import boulder.cli.update_command;
public import boulder.cli.version_command;

/**
Expand Down
102 changes: 102 additions & 0 deletions source/boulder/cli/update_command.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* SPDX-FileCopyrightText: Copyright © 2020-2023 Serpent OS Developers
*
* SPDX-License-Identifier: Zlib
*/

/**
* boulder.cli.update_command
*
* Implements the `boulder update` subcommand
*
* Authors: Copyright © 2020-2023 Serpent OS Developers
* License: Zlib
*/

module boulder.cli.update_command;

public import moss.core.cli;
import boulder.cli : BoulderCLI;
import core.sys.posix.unistd : geteuid;
import drafter;
import dyaml;
import moss.core;
import moss.core.util : computeSHA256;
import moss.fetcher;
import std.algorithm : each;
import std.stdio : File;
import std.file : exists;
import std.format : format;
import std.experimental.logger;

/**
* The BuildCommand is responsible for handling requests to build stone.yml
* formatted files into useful binary packages.
*/
@CommandName("update")
@CommandHelp("Update the version for an existing recipe")
@CommandUsage("[version] [tarball]")
public struct UpdateCommand
{
/** Extend BaseCommand with UpdateCommand specific functionality */
BaseCommand pt;
alias pt this;

/**
* Manipulation of recipes
*/
@CommandEntry() int run(ref string[] argv)
{
immutable useDebug = this.findAncestor!BoulderCLI.debugMode;
globalLogLevel = useDebug ? LogLevel.trace : LogLevel.info;

if (argv.length != 2)
{
warning("No arguments specified. For help, run boulder update -h");
return ExitStatus.Failure;
}

if (!recipeLocation.exists)
{
error(format!"Unable to find stone.yml in current directory. Use -r to specify location.");
return 1;
}

immutable ver = argv[0];
immutable tarball = argv[1];

/* Download the tarball */
auto f = new FetchController();
auto dlLoc= "/tmp/boulderUpdateTarball";
auto j = Fetchable(tarball, dlLoc, 0, FetchType.RegularFile, null);
f.enqueue(j);
while (!f.empty())
{
f.fetch();
}
info(format!"Wrote tarball to %s"(dlLoc));

auto hash = computeSHA256(dlLoc, true);
info(format!"Hash: %s"(hash));

/* Overwrite recipe with updated params */
Node root = Loader.fromFile(recipeLocation).load();
immutable rel = root["release"].as!int;
// FIXME: This isn't really working as expected
immutable upstreams = format("%s : %s", tarball, hash);
root["release"] = rel + 1;
root["version"] = ver;
root["upstreams"] = upstreams;
/* Purposely write as test.yaml for now as this is still PoC */
dumper().dump(File("test.yaml", "w").lockingTextWriter, root);
info("Successfully updated recipe");

return 0;
}

/** Where to output the YML file */
@Option("r", "recipe-location", "Location of existing stone.yml file to update version")
string recipeLocation = "stone.yml";
}


1 change: 1 addition & 0 deletions source/boulder/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ int boulderMain(string[] args)
auto clip = cliProcessor!BoulderCLI(args);
clip.addCommand!BuildControlCommand;
clip.addCommand!NewCommand;
clip.addCommand!UpdateCommand;
clip.addCommand!VersionCommand;
clip.addCommand!HelpCommand;
return clip.process(args);
Expand Down
1 change: 1 addition & 0 deletions source/boulder/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
boulder_sources = [
'cli/package.d',
'cli/new_command.d',
'cli/update_command.d',
'cli/version_command.d',
'cli/build_command.d',
'buildjob.d',
Expand Down

0 comments on commit d5d2d89

Please sign in to comment.