Compare commits
2 Commits
2026.02.15
...
2026.02.15
| Author | SHA1 | Date | |
|---|---|---|---|
| c6fe9f7397 | |||
| 4ff5680310 |
@@ -55,4 +55,7 @@ runs:
|
|||||||
GITHUB_OUTPUT: ${{ env.GITHUB_OUTPUT }}
|
GITHUB_OUTPUT: ${{ env.GITHUB_OUTPUT }}
|
||||||
run: |
|
run: |
|
||||||
echo "Starting cleanup..."
|
echo "Starting cleanup..."
|
||||||
./package-cleanup-linux-x64
|
./package-cleanup-linux-x64 > output.txt
|
||||||
|
cat output.txt
|
||||||
|
echo "$(cat output.txt)"
|
||||||
|
echo "Cleanup completed."
|
||||||
|
|||||||
@@ -15,5 +15,9 @@ builder.Services
|
|||||||
.AddHostedService<Worker>()
|
.AddHostedService<Worker>()
|
||||||
.AddHttpClient<IGiteaPackageService, GiteaPackageService>();
|
.AddHttpClient<IGiteaPackageService, GiteaPackageService>();
|
||||||
|
|
||||||
|
builder.Logging.ClearProviders();
|
||||||
|
builder.Logging.AddConsole();
|
||||||
|
builder.Logging.SetMinimumLevel(LogLevel.Debug);
|
||||||
|
|
||||||
var host = builder.Build();
|
var host = builder.Build();
|
||||||
await host.RunAsync();
|
await host.RunAsync();
|
||||||
|
|||||||
@@ -11,22 +11,19 @@ public class Worker(
|
|||||||
IGiteaPackageService giteaPackageService
|
IGiteaPackageService giteaPackageService
|
||||||
) : BackgroundService
|
) : BackgroundService
|
||||||
{
|
{
|
||||||
private async Task<int> DeletePackages(List<GiteaPackage> packages, CancellationToken cancellationToken = default)
|
private async Task DeletePackages(List<GiteaPackage> packages, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var dryRun = configuration["DRY_RUN"]?.ToLower() == "true";
|
var dryRun = configuration["DRY_RUN"]?.ToLower() == "true";
|
||||||
if (dryRun)
|
if (dryRun)
|
||||||
{
|
{
|
||||||
logger.LogInformation("Dry run enabled, not deleting {Count} packages", packages.Count);
|
logger.LogInformation("Dry run enabled, not deleting {Count} packages", packages.Count);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var deletedCount = 0;
|
|
||||||
foreach (var giteaPackage in packages)
|
foreach (var giteaPackage in packages)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await giteaPackageService.DeletePackage(giteaPackage, cancellationToken);
|
await giteaPackageService.DeletePackage(giteaPackage, cancellationToken);
|
||||||
deletedCount++;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -34,27 +31,6 @@ public class Worker(
|
|||||||
giteaPackage.Name, giteaPackage.Version);
|
giteaPackage.Name, giteaPackage.Version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return deletedCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void WriteGitHubOutput(string name, string value)
|
|
||||||
{
|
|
||||||
var githubOutput = configuration["GITHUB_OUTPUT"];
|
|
||||||
if (string.IsNullOrEmpty(githubOutput))
|
|
||||||
{
|
|
||||||
logger.LogDebug("GITHUB_OUTPUT not set, skipping output: {Name}={Value}", name, value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File.AppendAllText(githubOutput, $"{name}={value}{Environment.NewLine}");
|
|
||||||
logger.LogInformation("Wrote to GITHUB_OUTPUT: {Name}={Value}", name, value);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.LogError(ex, "Failed to write to GITHUB_OUTPUT file");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
|
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
|
||||||
@@ -68,14 +44,10 @@ public class Worker(
|
|||||||
if (names.Length == 0)
|
if (names.Length == 0)
|
||||||
{
|
{
|
||||||
logger.LogWarning("No package names configured");
|
logger.LogWarning("No package names configured");
|
||||||
WriteGitHubOutput("deleted_packages", "0");
|
|
||||||
WriteGitHubOutput("processed_names", "0");
|
|
||||||
appLifetime.StopApplication();
|
appLifetime.StopApplication();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var totalDeleted = 0;
|
|
||||||
|
|
||||||
// Process each name separately: collect -> filter -> delete
|
// Process each name separately: collect -> filter -> delete
|
||||||
foreach (var name in names)
|
foreach (var name in names)
|
||||||
{
|
{
|
||||||
@@ -85,26 +57,20 @@ public class Worker(
|
|||||||
logger.LogInformation("Found {Count} packages for name '{Name}'", packages.Count, name);
|
logger.LogInformation("Found {Count} packages for name '{Name}'", packages.Count, name);
|
||||||
|
|
||||||
var packagesToDelete = packageService.FilterPackagesToDelete(packages);
|
var packagesToDelete = packageService.FilterPackagesToDelete(packages);
|
||||||
logger.LogInformation("Found {Count} packages to delete for name '{Name}'", packagesToDelete.Count, name);
|
logger.LogInformation("Found {Count} packages to delete for name '{Name}'", packagesToDelete.Count,
|
||||||
|
name);
|
||||||
|
|
||||||
var deletedCount = await DeletePackages(packagesToDelete, cancellationToken);
|
await DeletePackages(packagesToDelete, cancellationToken);
|
||||||
totalDeleted += deletedCount;
|
logger.LogInformation("Deleted {Count} packages for name '{Name}'", packagesToDelete.Count, name);
|
||||||
logger.LogInformation("Deleted {Count} packages for name '{Name}'", deletedCount, name);
|
|
||||||
|
|
||||||
logger.LogInformation("Cleanup finished for name '{Name}'", name);
|
logger.LogInformation("Cleanup finished for name '{Name}'", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.LogInformation("All package names processed successfully");
|
logger.LogInformation("All package names processed successfully");
|
||||||
|
|
||||||
// Write outputs to GITHUB_OUTPUT
|
|
||||||
WriteGitHubOutput("deleted_packages", totalDeleted.ToString());
|
|
||||||
WriteGitHubOutput("processed_names", names.Length.ToString());
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogError(ex, "Cleanup failed with an error");
|
logger.LogError(ex, "Cleanup failed with an error");
|
||||||
WriteGitHubOutput("deleted_packages", "0");
|
|
||||||
WriteGitHubOutput("processed_names", "0");
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user