Compare commits

...

3 Commits

Author SHA1 Message Date
c6fe9f7397 Added output manually
All checks were successful
Build on push / prepare (push) Successful in 6s
Build on push / build (push) Successful in 14s
2026-02-15 10:37:47 +01:00
4ff5680310 Changed logging
All checks were successful
Build on push / prepare (push) Successful in 7s
Build on push / build (push) Successful in 15s
2026-02-15 10:29:52 +01:00
6d3a5b1930 Fixe build
All checks were successful
Build on push / prepare (push) Successful in 5s
Build on push / build (push) Successful in 15s
2026-02-15 10:19:44 +01:00
4 changed files with 21 additions and 48 deletions

View File

@@ -36,7 +36,7 @@ jobs:
cd sh.actions.package-cleanup
# Build for Linux x64
dotnet publish -c Release -r linux-x64 -p:Version=$(cat ../../version.txt) -o publish/linux-x64
dotnet publish -c Release -r linux-x64 -p:Version=$(cat ../version.txt) -o publish/linux-x64
- name: Upload to Gitea Generic Package Registry
run: |
@@ -44,4 +44,4 @@ jobs:
curl -X PUT \
-H "Authorization: token ${{ secrets.CI_ACCESS_TOKEN }}" \
-T publish/linux-x64/sh.actions.package-cleanup \
"https://git.sh-edraft.de/api/packages/sh-edraft.de/generic/package-cleanup/$(cat ../../version.txt)/package-cleanup-linux-x64"
"https://git.sh-edraft.de/api/packages/sh-edraft.de/generic/package-cleanup/$(cat ../version.txt)/package-cleanup-linux-x64"

View File

@@ -55,4 +55,7 @@ runs:
GITHUB_OUTPUT: ${{ env.GITHUB_OUTPUT }}
run: |
echo "Starting cleanup..."
./package-cleanup-linux-x64
./package-cleanup-linux-x64 > output.txt
cat output.txt
echo "$(cat output.txt)"
echo "Cleanup completed."

View File

@@ -15,5 +15,9 @@ builder.Services
.AddHostedService<Worker>()
.AddHttpClient<IGiteaPackageService, GiteaPackageService>();
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Logging.SetMinimumLevel(LogLevel.Debug);
var host = builder.Build();
await host.RunAsync();

View File

@@ -11,22 +11,19 @@ public class Worker(
IGiteaPackageService giteaPackageService
) : 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";
if (dryRun)
{
logger.LogInformation("Dry run enabled, not deleting {Count} packages", packages.Count);
return 0;
}
var deletedCount = 0;
foreach (var giteaPackage in packages)
{
try
{
await giteaPackageService.DeletePackage(giteaPackage, cancellationToken);
deletedCount++;
}
catch (Exception ex)
{
@@ -34,27 +31,6 @@ public class Worker(
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)
@@ -68,14 +44,10 @@ public class Worker(
if (names.Length == 0)
{
logger.LogWarning("No package names configured");
WriteGitHubOutput("deleted_packages", "0");
WriteGitHubOutput("processed_names", "0");
appLifetime.StopApplication();
return;
}
var totalDeleted = 0;
// Process each name separately: collect -> filter -> delete
foreach (var name in names)
{
@@ -85,26 +57,20 @@ public class Worker(
logger.LogInformation("Found {Count} packages for name '{Name}'", packages.Count, name);
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);
totalDeleted += deletedCount;
logger.LogInformation("Deleted {Count} packages for name '{Name}'", deletedCount, name);
await DeletePackages(packagesToDelete, cancellationToken);
logger.LogInformation("Deleted {Count} packages for name '{Name}'", packagesToDelete.Count, name);
logger.LogInformation("Cleanup finished for name '{Name}'", name);
}
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)
{
logger.LogError(ex, "Cleanup failed with an error");
WriteGitHubOutput("deleted_packages", "0");
WriteGitHubOutput("processed_names", "0");
}
finally
{