Compare commits

..

5 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
5dca7e693b Fixed file structure
Some checks failed
Build on push / prepare (push) Successful in 8s
Build on push / build (push) Failing after 10s
2026-02-15 10:18:56 +01:00
a2fe4cb960 Added debug info [skip ci] 2026-02-15 10:17:48 +01:00
4 changed files with 24 additions and 50 deletions

View File

@@ -33,15 +33,15 @@ jobs:
- name: Build single file executables
run: |
cd sh.actions/sh.actions.package-cleanup
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: |
cd sh.actions/sh.actions.package-cleanup
cd sh.actions.package-cleanup
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

@@ -54,4 +54,8 @@ runs:
DRY_RUN: ${{ inputs.dry_run }}
GITHUB_OUTPUT: ${{ env.GITHUB_OUTPUT }}
run: |
./package-cleanup-linux-x64
echo "Starting cleanup..."
./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,50 +11,26 @@ 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)
{
logger.LogError(ex, "Failed to delete package {PackageName} version {Version}",
logger.LogError(ex, "Failed to delete package {PackageName} version {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)
@@ -68,43 +44,33 @@ 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)
{
logger.LogInformation("Processing packages for name '{Name}'", name);
var packages = (await giteaPackageService.GetPackagesByNameAsync(name, cancellationToken)).ToList();
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);
var deletedCount = await DeletePackages(packagesToDelete, cancellationToken);
totalDeleted += deletedCount;
logger.LogInformation("Deleted {Count} packages for name '{Name}'", deletedCount, name);
logger.LogInformation("Found {Count} packages to delete for name '{Name}'", packagesToDelete.Count,
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
{