Update+bugfix

This commit is contained in:
Laura Hausmann 2020-06-25 22:25:11 +02:00
parent 1d49bd6ef3
commit 6ca140cbbd
Signed by: zotan
GPG key ID: 5EC1D38FFC321311
6 changed files with 445 additions and 498 deletions

View file

@ -1,4 +1,5 @@
@page @page
@using System.Web
@model IndexModel @model IndexModel
@{ @{
ViewData["Title"] = "Builds"; ViewData["Title"] = "Builds";
@ -40,7 +41,7 @@
} }
@if (System.IO.File.Exists(System.IO.Path.Combine(Program.Repo._pkgpath, p.Name, "buildlog.txt"))) @if (System.IO.File.Exists(System.IO.Path.Combine(Program.Repo._pkgpath, p.Name, "buildlog.txt")))
{ {
<td><a role="button" class="btn btn-sm btn-info" target="_blank" href="/Log?package=@p.Name">View Build log</a></td> <td><a role="button" class="btn btn-sm btn-info" target="_blank" href="/Log?package=@HttpUtility.UrlEncode(p.Name)">View Build log</a></td>
} }
else else
{ {

View file

@ -6,148 +6,130 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore; using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace repomgr namespace repomgr {
{ public static class Program {
public static class Program public static RepoMgr Repo;
{
public static RepoMgr Repo;
public static void Main(string[] args) public static void Main(string[] args) {
{ if (File.Exists("/tmp/repomgr.lock") && args[1] != "daemon") {
if (File.Exists("/tmp/repomgr.lock") && args[1] != "daemon") Console.WriteLine("/tmp/repomgr.lock exists, delete it if you are sure no other process is running");
{ Environment.Exit(1);
Console.WriteLine("/tmp/repomgr.lock exists, delete it if you are sure no other process is running"); }
Environment.Exit(1); else if (args[1] != "daemon") {
} File.Create("/tmp/repomgr.lock");
else if (args[1] != "daemon") }
{
File.Create("/tmp/repomgr.lock");
}
if (args.Length < 2 || args[1].Equals("help")) if (args.Length < 2 || args[1].Equals("help"))
PrintHelp(); PrintHelp();
Repo = new RepoMgr(args[0]);
if (File.Exists(Path.Combine(args[0], "repomgr.index.json")))
Repo.ReadIndex();
switch (args[1])
{
case "daemon":
CreateWebHostBuilder(args).Build().Run();
break;
case "init":
if (args.Length != 4)
PrintHelp();
try
{
Repo.Init(args[2], args[3]);
}
catch (Exception e)
{
Console.WriteLine("Init failed with error: " + e);
}
break; Repo = new RepoMgr(args[0]);
case "add": if (File.Exists(Path.Combine(args[0], "repomgr.index.json")))
if (args.Length != 3) Repo.ReadIndex();
PrintHelp(); switch (args[1]) {
try case "daemon":
{ CreateHostBuilder(args).Build().Run();
Repo.Add(args[2]); break;
} case "init":
catch (Exception e) if (args.Length != 4)
{ PrintHelp();
Console.WriteLine("Add failed with error: " + e); try {
} Repo.Init(args[2], args[3]);
}
catch (Exception e) {
Console.WriteLine("Init failed with error: " + e);
}
break; break;
case "update": case "add":
if (args.Length < 3 || args.Length > 4) if (args.Length != 3)
PrintHelp(); PrintHelp();
try try {
{ Repo.Add(args[2]);
switch (args.Length) }
{ catch (Exception e) {
case 3: Console.WriteLine("Add failed with error: " + e);
Repo.Build(args[2]); }
break;
case 4 when args[3] == "-f":
Repo.Build(args[2], true);
break;
default:
PrintHelp();
break;
}
}
catch (Exception e)
{
Console.WriteLine("Build failed with error: " + e);
}
break; break;
case "update-all": case "update":
if (args.Length != 2) if (args.Length < 3 || args.Length > 4)
PrintHelp(); PrintHelp();
try try {
{ switch (args.Length) {
Repo.BuildAll(); case 3:
} Repo.Build(args[2]);
catch (Exception e) break;
{ case 4 when args[3] == "-f":
Console.WriteLine("BuildAll failed with error: " + e); Repo.Build(args[2], true);
} break;
default:
PrintHelp();
break;
}
}
catch (Exception e) {
Console.WriteLine("Build failed with error: " + e);
}
break; break;
case "remove": case "update-all":
if (args.Length != 3) if (args.Length != 2)
PrintHelp(); PrintHelp();
try try {
{ Repo.BuildAll();
Repo.Remove(args[2]); }
} catch (Exception e) {
catch (Exception e) Console.WriteLine("BuildAll failed with error: " + e);
{ }
Console.WriteLine("Remove failed with error: " + e);
}
break; break;
case "list": case "remove":
if (args.Length != 2) if (args.Length != 3)
PrintHelp(); PrintHelp();
try try {
{ Repo.Remove(args[2]);
Repo.List(); }
} catch (Exception e) {
catch (Exception e) Console.WriteLine("Remove failed with error: " + e);
{ }
Console.WriteLine("List failed with error " + e);
}
break; break;
default: case "list":
PrintHelp(); if (args.Length != 2)
break; PrintHelp();
} try {
if (File.Exists("/tmp/repomgr.lock")) Repo.List();
File.Delete("/tmp/repomgr.lock"); }
} catch (Exception e) {
Console.WriteLine("List failed with error " + e);
}
private static void PrintHelp() break;
{ default:
//TODO: add/remove <package> [...] PrintHelp();
Console.WriteLine("Usage:"); break;
Console.WriteLine("repomgr <data-path> init <repo-path> <reponame>"); }
Console.WriteLine("repomgr <data-path> list");
Console.WriteLine("repomgr <data-path> add <package>");
Console.WriteLine("repomgr <data-path> remove <package>");
Console.WriteLine("repomgr <data-path> update <package> [-f]");
Console.WriteLine("repomgr <data-path> update-all");
Console.WriteLine("repomgr <data-path> daemon");
}
private static IWebHostBuilder CreateWebHostBuilder(string[] args) => if (File.Exists("/tmp/repomgr.lock"))
WebHost.CreateDefaultBuilder(args) File.Delete("/tmp/repomgr.lock");
.UseStartup<Startup>(); }
}
private static void PrintHelp() {
//TODO: add/remove <package> [...]
Console.WriteLine("Usage:");
Console.WriteLine("repomgr <data-path> init <repo-path> <reponame>");
Console.WriteLine("repomgr <data-path> list");
Console.WriteLine("repomgr <data-path> add <package>");
Console.WriteLine("repomgr <data-path> remove <package>");
Console.WriteLine("repomgr <data-path> update <package> [-f]");
Console.WriteLine("repomgr <data-path> update-all");
Console.WriteLine("repomgr <data-path> daemon");
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}
} }

View file

@ -6,343 +6,309 @@ using System.Linq;
using LibGit2Sharp; using LibGit2Sharp;
using System.Diagnostics; using System.Diagnostics;
namespace repomgr namespace repomgr {
{ public class RepoMgr {
public class RepoMgr public RepoMgr(string buildpath) {
{ _buildpath = Path.GetFullPath(buildpath);
public RepoMgr(string buildpath) _pkgpath = Path.Combine(_buildpath, "pkg");
{ }
_buildpath = Path.GetFullPath(buildpath);
_pkgpath = Path.Combine(_buildpath, "pkg");
}
public readonly string _buildpath; public readonly string _buildpath;
public readonly string _pkgpath; public readonly string _pkgpath;
public Repository _repo; public Repository _repo;
public void Init(string repopath, string reponame)
{
_repo = new Repository(repopath, reponame);
if (!Directory.Exists(repopath))
Directory.CreateDirectory(repopath);
WriteIndex();
Console.WriteLine("Initialized.");
}
public void Add(string package)
{
Package pkg;
if (Directory.Exists(Path.Combine(_pkgpath, package)))
{
if (_repo.Packages.Find(p => p.Name.Equals(package)) != null)
{
Console.WriteLine("Package already exists.");
return;
}
if (!CheckPackage(package))
{
throw new Exception("Package directory exists but is invalid (PKGBUILD or .git missing)");
}
pkg = new Package(package);
}
else
{
if (_repo.Packages.Find(p => p.Name.Equals(package)) != null)
_repo.Packages.RemoveAll(p => p.Name.Equals(package));
try
{
var refcount = LibGit2Sharp.Repository.ListRemoteReferences($"https://aur.archlinux.org/{package}.git").Count();
if (refcount < 1)
{
throw new Exception("git clone failed: Package doesn't exist in remote");
}
LibGit2Sharp.Repository.Clone($"https://aur.archlinux.org/{package}.git", public void Init(string repopath, string reponame) {
Path.Combine(_pkgpath, package)); _repo = new Repository(repopath, reponame);
} if (!Directory.Exists(repopath))
catch (Exception e) Directory.CreateDirectory(repopath);
{ WriteIndex();
throw new Exception($"Error during clone: {e}"); Console.WriteLine("Initialized.");
} }
pkg = new Package(package);
}
Console.WriteLine($"Adding package {package}...");
_repo.Packages.Add(pkg);
WriteIndex();
}
private void Build(Package package, bool force = false)
{
if (UpdateAvailable(package))
UpdatePackage(package);
if (File.ReadAllText(Path.Combine(_pkgpath, package.Name, "PKGBUILD")).Contains("pkgver()"))
Shell.Exec("makepkg -os --noconfirm", Path.Combine(_pkgpath, package.Name));
package.CurrentVersion = Shell.ExecR("source PKGBUILD; echo \"$pkgver-$pkgrel\"", Path.Combine(_pkgpath, package.Name));
WriteIndex();
if (force)
Shell.Exec("makepkg -Ccsf --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name));
else if (package.CurrentVersion != package.RepoVersion)
Shell.Exec("makepkg -Ccs --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name));
else return;
var resultingPackages = Directory public void Add(string package) {
.GetFiles(Path.Combine(_pkgpath, package.Name), "*.pkg.tar*"); Package pkg;
if (resultingPackages.Length < 1) if (Directory.Exists(Path.Combine(_pkgpath, package))) {
{ if (_repo.Packages.Find(p => p.Name.Equals(package)) != null) {
package.LastBuildSucceeded = false; Console.WriteLine("Package already exists.");
throw new Exception("makepkg didn't build any package"); return;
} }
package.LastBuildSucceeded = true; if (!CheckPackage(package)) {
if (package.PkgFiles.Any()) throw new Exception("Package directory exists but is invalid (PKGBUILD or .git missing)");
{ }
foreach (var pkgFile in package.PkgFiles)
if (File.Exists(Path.Combine(_repo.Path, pkgFile)))
File.Delete(Path.Combine(_repo.Path, pkgFile));
package.PkgFiles.Clear();
}
foreach (var resultingPackage in resultingPackages.Where(p => p.EndsWith(".sig")))
{
File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true);
File.Delete(resultingPackage);
package.PkgFiles.Add(Path.GetFileName(resultingPackage));
}
foreach (var resultingPackage in resultingPackages.Where(p => !p.EndsWith(".sig")))
{
File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true);
File.Delete(resultingPackage);
package.PkgFiles.Add(Path.GetFileName(resultingPackage));
Shell.Exec($"repo-add --remove --sign {_repo.Name}.db.tar.gz {Path.GetFileName(resultingPackage)}", _repo.Path);
}
package.RepoVersion = package.CurrentVersion;
WriteIndex();
}
private void Remove(Package package)
{
var packageDir = Path.Combine(_pkgpath, package.Name);
if (Directory.Exists(packageDir))
Directory.Delete(packageDir, true);
Shell.Exec($"repo-remove --sign {_repo.Name}.db.tar.gz {package.Name}", _repo.Path);
if (package.PkgFiles.Any())
{
foreach (var pkgFile in package.PkgFiles)
if (File.Exists(Path.Combine(_repo.Path, pkgFile)))
File.Delete(Path.Combine(_repo.Path, pkgFile));
package.PkgFiles.Clear();
}
_repo.Packages.Remove(package);
WriteIndex();
}
public void List()
{
Console.WriteLine(Shell.Yellow($"{Shell.Bold(_repo.Name)} ({_repo.Packages.Count} packages):"));
foreach (var package in _repo.Packages.OrderBy(p => p.Name))
{
var line = $"{Shell.Bold(package.Name)}";
if (package.RepoVersion != package.CurrentVersion)
line += $" ({Shell.Red(package.RepoVersion)} {Shell.Gray("->")} {Shell.Yellow(package.CurrentVersion)})";
else
line += $" ({Shell.Green(package.RepoVersion)})";
if (package.LastBuildSucceeded)
line += $" [{Shell.Green(Shell.Bold("BUILD PASSING"))}]";
else
line += $" [{Shell.Red(Shell.Bold("BUILD FAILING"))}]";
Console.WriteLine(line);
}
}
// util stuff
private Package GetPackage(string package)
{
var pkg = _repo.Packages.FirstOrDefault(p => p.Name.Equals(package));
if (pkg != null) return pkg;
throw new Exception("Package not found.");
}
// git fetch, returns true if differences between origin/master and master found
private bool UpdateAvailable(Package package)
{
var repo = new LibGit2Sharp.Repository(Path.Combine(_pkgpath, package.Name));
var remote = repo.Network.Remotes["origin"];
var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
Commands.Fetch(repo, remote.Name, refSpecs, null, null);
return repo.Diff.Compare<TreeChanges>(repo.Branches["origin/master"].Tip.Tree,
DiffTargets.Index | DiffTargets.WorkingDirectory).Any();
}
// resets master to origin/master
private void UpdatePackage(Package package)
{
var repo = new LibGit2Sharp.Repository(Path.Combine(_pkgpath, package.Name));
var originMaster = repo.Branches["origin/master"];
repo.Reset(ResetMode.Hard, originMaster.Tip);
}
public void ReadIndex()
{
try
{
_repo = JsonConvert.DeserializeObject<Repository>(
File.ReadAllText(Path.Combine(_buildpath, "repomgr.index.json")));
}
catch (IOException)
{
throw new Exception("configuration file not found or wrong permissions. Did you run repomgr init?");
}
catch (JsonException)
{
throw new Exception("configuration corrupt. Please check manually or re-init repo.");
}
}
private void WriteIndex()
{
try
{
var json = JsonConvert.SerializeObject(_repo);
if (!Directory.Exists(_buildpath))
Directory.CreateDirectory(_buildpath);
File.WriteAllText(Path.Combine(_buildpath, "repomgr.index.json"), json);
}
catch (IOException)
{
throw new Exception("Unable to write configuration. Check permissions.");
}
}
private bool CheckPackage(string package)
{
return Directory.Exists(Path.Combine(_pkgpath, package, ".git")) &&
File.Exists(Path.Combine(_pkgpath, package, "PKGBUILD"));
}
public void Build(string package, bool force = false)
{
if (!CheckPackage(package)) return;
var iPackage = GetPackage(package);
try
{
Build(iPackage, force);
}
catch (Exception)
{
iPackage.LastBuildSucceeded = false;
throw;
}
}
public void BuildAll()
{
foreach (var package in _repo.Packages)
{
if (!CheckPackage(package.Name)) return;
try
{
Build(package);
}
catch (Exception)
{
package.LastBuildSucceeded = false;
}
}
}
public void Remove(string package)
{
if (CheckPackage(package))
Remove(GetPackage(package));
}
}
public class Repository pkg = new Package(package);
{ }
public Repository(string path, string name) else {
{ if (_repo.Packages.Find(p => p.Name.Equals(package)) != null)
Path = path; _repo.Packages.RemoveAll(p => p.Name.Equals(package));
Name = name; try {
Packages = new List<Package>(); var refcount = LibGit2Sharp.Repository.ListRemoteReferences($"https://aur.archlinux.org/{package}.git").Count();
} if (refcount < 1) {
throw new Exception("git clone failed: Package doesn't exist in remote");
}
public readonly string Path; LibGit2Sharp.Repository.Clone($"https://aur.archlinux.org/{package}.git", Path.Combine(_pkgpath, package));
public readonly string Name; }
public readonly List<Package> Packages; catch (Exception e) {
} throw new Exception($"Error during clone: {e}");
}
public class Package pkg = new Package(package);
{ }
public Package(string name)
{
Name = name;
}
public readonly string Name; Console.WriteLine($"Adding package {package}...");
public string CurrentVersion = "never-updated"; _repo.Packages.Add(pkg);
public string RepoVersion = "nA"; WriteIndex();
public bool LastBuildSucceeded = true; }
public readonly List<string> PkgFiles = new List<string>();
}
internal static class Shell private void Build(Package package, bool force = false) {
{ if (UpdateAvailable(package))
public static void Exec(string cmd, string workingDirectory) UpdatePackage(package);
{ if (File.ReadAllText(Path.Combine(_pkgpath, package.Name, "PKGBUILD")).Contains("pkgver()"))
var escapedArgs = cmd.Replace("\"", "\\\""); Shell.Exec("makepkg -os --noconfirm", Path.Combine(_pkgpath, package.Name));
package.CurrentVersion = Shell.ExecR("source PKGBUILD; echo \"$pkgver-$pkgrel\"", Path.Combine(_pkgpath, package.Name));
var process = new Process() WriteIndex();
{ if (force)
StartInfo = new ProcessStartInfo Shell.Exec("makepkg -Ccsf --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name));
{ else if (package.CurrentVersion != package.RepoVersion)
FileName = "/bin/bash", Shell.Exec("makepkg -Ccs --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name));
Arguments = $"-c \"{escapedArgs}\"", else
WorkingDirectory = workingDirectory, return;
RedirectStandardOutput = false,
RedirectStandardError = false,
UseShellExecute = false,
CreateNoWindow = true,
}
};
process.Start();
process.WaitForExit();
}
public static string ExecR(string cmd, string workingDirectory)
{
var escapedArgs = cmd.Replace("\"", "\\\"");
var process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
Arguments = $"-c \"{escapedArgs}\"",
WorkingDirectory = workingDirectory,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
process.Start();
var stdout = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return stdout.Trim();
}
public static string Bold(string s) var resultingPackages = Directory.GetFiles(Path.Combine(_pkgpath, package.Name), "*.pkg.tar*");
{ if (resultingPackages.Length < 1) {
return $"\x1B[1m{s}\x1B[21m"; package.LastBuildSucceeded = false;
} throw new Exception("makepkg didn't build any package");
}
public static string Red(string s) package.LastBuildSucceeded = true;
{ if (package.PkgFiles.Any()) {
return $"\x1b[31m{s}\x1b[39m"; foreach (var pkgFile in package.PkgFiles)
} if (File.Exists(Path.Combine(_repo.Path, pkgFile)))
public static string Yellow(string s) File.Delete(Path.Combine(_repo.Path, pkgFile));
{ package.PkgFiles.Clear();
return $"\x1b[33m{s}\x1b[39m"; }
}
public static string Green(string s) foreach (var resultingPackage in resultingPackages.Where(p => p.EndsWith(".sig"))) {
{ File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true);
return $"\x1b[32m{s}\x1b[39m"; File.Delete(resultingPackage);
} package.PkgFiles.Add(Path.GetFileName(resultingPackage));
public static string Gray(string s) }
{
return $"\x1b[90m{s}\x1b[39m"; foreach (var resultingPackage in resultingPackages.Where(p => !p.EndsWith(".sig"))) {
} File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true);
} File.Delete(resultingPackage);
package.PkgFiles.Add(Path.GetFileName(resultingPackage));
Shell.Exec($"repo-add --remove --sign {_repo.Name}.db.tar.gz {Path.GetFileName(resultingPackage)}", _repo.Path);
}
package.RepoVersion = package.CurrentVersion;
WriteIndex();
}
private void Remove(Package package) {
var packageDir = Path.Combine(_pkgpath, package.Name);
if (Directory.Exists(packageDir))
Directory.Delete(packageDir, true);
Shell.Exec($"repo-remove --sign {_repo.Name}.db.tar.gz {package.Name}", _repo.Path);
if (package.PkgFiles.Any()) {
foreach (var pkgFile in package.PkgFiles)
if (File.Exists(Path.Combine(_repo.Path, pkgFile)))
File.Delete(Path.Combine(_repo.Path, pkgFile));
package.PkgFiles.Clear();
}
_repo.Packages.Remove(package);
WriteIndex();
}
public void List() {
Console.WriteLine(Shell.Yellow($"{Shell.Bold(_repo.Name)} ({_repo.Packages.Count} packages):"));
foreach (var package in _repo.Packages.OrderBy(p => p.Name)) {
var line = $"{Shell.Bold(package.Name)}";
if (package.RepoVersion != package.CurrentVersion)
line += $" ({Shell.Red(package.RepoVersion)} {Shell.Gray("->")} {Shell.Yellow(package.CurrentVersion)})";
else
line += $" ({Shell.Green(package.RepoVersion)})";
if (package.LastBuildSucceeded)
line += $" [{Shell.Green(Shell.Bold("BUILD PASSING"))}]";
else
line += $" [{Shell.Red(Shell.Bold("BUILD FAILING"))}]";
Console.WriteLine(line);
}
}
// util stuff
private Package GetPackage(string package) {
var pkg = _repo.Packages.FirstOrDefault(p => p.Name.Equals(package));
if (pkg != null)
return pkg;
throw new Exception("Package not found.");
}
// git fetch, returns true if differences between origin/master and master found
private bool UpdateAvailable(Package package) {
var repo = new LibGit2Sharp.Repository(Path.Combine(_pkgpath, package.Name));
var remote = repo.Network.Remotes["origin"];
var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
Commands.Fetch(repo, remote.Name, refSpecs, null, null);
return repo.Diff.Compare<TreeChanges>(repo.Branches["origin/master"].Tip.Tree, DiffTargets.Index | DiffTargets.WorkingDirectory).Any();
}
// resets master to origin/master
private void UpdatePackage(Package package) {
var repo = new LibGit2Sharp.Repository(Path.Combine(_pkgpath, package.Name));
var originMaster = repo.Branches["origin/master"];
repo.Reset(ResetMode.Hard, originMaster.Tip);
repo.RemoveUntrackedFiles();
}
public void ReadIndex() {
try {
_repo = JsonConvert.DeserializeObject<Repository>(File.ReadAllText(Path.Combine(_buildpath, "repomgr.index.json")));
}
catch (IOException) {
throw new Exception("configuration file not found or wrong permissions. Did you run repomgr init?");
}
catch (JsonException) {
throw new Exception("configuration corrupt. Please check manually or re-init repo.");
}
}
private void WriteIndex() {
try {
var json = JsonConvert.SerializeObject(_repo);
if (!Directory.Exists(_buildpath))
Directory.CreateDirectory(_buildpath);
File.WriteAllText(Path.Combine(_buildpath, "repomgr.index.json"), json);
}
catch (IOException) {
throw new Exception("Unable to write configuration. Check permissions.");
}
}
private bool CheckPackage(string package) {
return Directory.Exists(Path.Combine(_pkgpath, package, ".git")) && File.Exists(Path.Combine(_pkgpath, package, "PKGBUILD"));
}
public void Build(string package, bool force = false) {
if (!CheckPackage(package))
return;
var iPackage = GetPackage(package);
try {
Build(iPackage, force);
}
catch (Exception) {
iPackage.LastBuildSucceeded = false;
throw;
}
}
public void BuildAll() {
foreach (var package in _repo.Packages) {
if (!CheckPackage(package.Name))
return;
try {
Build(package);
}
catch (Exception) {
package.LastBuildSucceeded = false;
}
}
}
public void Remove(string package) {
if (CheckPackage(package))
Remove(GetPackage(package));
}
}
public class Repository {
public Repository(string path, string name) {
Path = path;
Name = name;
Packages = new List<Package>();
}
public readonly string Path;
public readonly string Name;
public readonly List<Package> Packages;
}
public class Package {
public Package(string name) {
Name = name;
}
public readonly string Name;
public string CurrentVersion = "never-updated";
public string RepoVersion = "nA";
public bool LastBuildSucceeded = true;
public readonly List<string> PkgFiles = new List<string>();
}
internal static class Shell {
public static void Exec(string cmd, string workingDirectory) {
var escapedArgs = cmd.Replace("\"", "\\\"");
var process = new Process() {
StartInfo = new ProcessStartInfo {
FileName = "/bin/bash",
Arguments = $"-c \"{escapedArgs}\"",
WorkingDirectory = workingDirectory,
RedirectStandardOutput = false,
RedirectStandardError = false,
UseShellExecute = false,
CreateNoWindow = true,
}
};
process.Start();
process.WaitForExit();
}
public static string ExecR(string cmd, string workingDirectory) {
var escapedArgs = cmd.Replace("\"", "\\\"");
var process = new Process() {
StartInfo = new ProcessStartInfo {
FileName = "/bin/bash",
Arguments = $"-c \"{escapedArgs}\"",
WorkingDirectory = workingDirectory,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
process.Start();
var stdout = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return stdout.Trim();
}
public static string Bold(string s) {
return $"\x1B[1m{s}\x1B[0m";
}
public static string Red(string s) {
return $"\x1b[31m{s}\x1b[39m";
}
public static string Yellow(string s) {
return $"\x1b[33m{s}\x1b[39m";
}
public static string Green(string s) {
return $"\x1b[32m{s}\x1b[39m";
}
public static string Gray(string s) {
return $"\x1b[90m{s}\x1b[39m";
}
}
} }

View file

@ -9,51 +9,48 @@ using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace repomgr namespace repomgr
{ {
public class Startup public class Startup {
{ public Startup(IConfiguration configuration) => Configuration = configuration;
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; } public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services) {
{ services.AddRazorPages();
services.Configure<CookiePolicyOptions>(options => #if (DEBUG)
{ services.AddControllers().AddRazorRuntimeCompilation();
// This lambda determines whether user consent for non-essential cookies is needed for a given request. #else
options.CheckConsentNeeded = context => true; services.AddControllers();
options.MinimumSameSitePolicy = SameSiteMode.None; #endif
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env) public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
{ if (env.IsDevelopment()) {
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
else else {
{
app.UseExceptionHandler("/Error"); app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts(); app.UseHsts();
} }
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc(); app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints => {
endpoints.MapRazorPages();
endpoints.MapControllers();
});
} }
} }
} }

View file

@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Configurations>Debug;Release</Configurations> <Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms> <Platforms>AnyCPU</Platforms>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier> <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<OutputType>Exe</OutputType>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.26.0" /> <PackageReference Include="LibGit2Sharp" Version="0.26.2" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" /> <PackageReference Include="LibGit2Sharp.NativeBinaries" Version="2.0.306" />
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
</ItemGroup> </ItemGroup>

View file

@ -1,15 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> <PackageReference Include="LibGit2Sharp.NativeBinaries" Version="2.0.306" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>