Compare commits

..

8 Commits

Author SHA1 Message Date
55beaf55ce Should fix set version
All checks were successful
Build on push / prepare (push) Successful in 11s
Build on push / build (push) Successful in 26s
2026-03-01 16:28:42 +01:00
1f411c0c85 Fixed dotnet version
All checks were successful
Build on push / prepare (push) Successful in 7s
Build on push / build (push) Successful in 17s
2026-02-22 21:09:53 +01:00
6473851d9e Set multiple version types
All checks were successful
Build on push / prepare (push) Successful in 26s
Build on push / build (push) Successful in 17s
2026-02-22 20:59:19 +01:00
2f1a200bdc Escape slashes in package name
All checks were successful
Build on push / prepare (push) Successful in 5s
Build on push / build (push) Successful in 18s
2026-02-22 00:27:43 +01:00
dfa8dc079b Merge pull request 'dev' (#1) from dev into master
All checks were successful
Build on push / prepare (push) Successful in 5s
Build on push / build (push) Successful in 18s
Reviewed-on: #1
2026-02-22 00:19:00 +01:00
321e53be5b Added prod build [skip-ci]
All checks were successful
Build on push / prepare (push) Successful in 5s
Build on push / build (push) Successful in 19s
2026-02-22 00:18:35 +01:00
4e8b04da7b Fixed error handling
All checks were successful
Build on push / prepare (push) Successful in 5s
Build on push / build (push) Successful in 18s
2026-02-22 00:17:23 +01:00
ff8cd3350b Added more debugging
All checks were successful
Build on push / prepare (push) Successful in 6s
Build on push / build (push) Successful in 18s
2026-02-15 12:49:58 +01:00
7 changed files with 186 additions and 25 deletions

View File

@@ -0,0 +1,45 @@
name: Build on push
run-name: Build on push
on:
push:
branches:
- master
jobs:
prepare:
runs-on: [runner]
container: git.sh-edraft.de/sh-edraft.de/act-runner:latest
steps:
- uses: https://git.sh-edraft.de/sh-edraft.de/actions/set-version@master
env:
CI_ACCESS_TOKEN: ${{ secrets.CI_ACCESS_TOKEN }}
build:
runs-on: [runner]
needs: prepare
container: git.sh-edraft.de/sh-edraft.de/act-runner:latest
steps:
- name: Clone Repository
uses: https://github.com/actions/checkout@v3
with:
token: ${{ secrets.CI_ACCESS_TOKEN }}
- name: Download build version artifact
uses: actions/download-artifact@v3
with:
name: version
- name: Build single file executables
run: |
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
- name: Upload to Gitea Generic Package Registry
run: |
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"

View File

@@ -14,7 +14,7 @@ inputs:
types: types:
description: "Types of packages (e.g. Container, PyPi, NuGet)" description: "Types of packages (e.g. Container, PyPi, NuGet)"
required: false required: false
default: "Container,PyPi,NuGet" default: "container,pypi,nuget,npm"
api_token: api_token:
description: "API token for authentication" description: "API token for authentication"
required: true required: true

View File

@@ -25,29 +25,64 @@ runs:
git fetch --tags git fetch --tags
- name: Calculate Version - name: Calculate Version
id: calculate
shell: bash shell: bash
run: | run: |
DATE=$(date +'%Y.%m.%d') DATE_LEADING=$(date +'%Y.%m.%d')
TAG_COUNT=$(git tag -l "${DATE}.*" | wc -l)
if [ "$TAG_COUNT" -eq 0 ]; then YEAR=$(date +'%Y')
BUILD_NUMBER=0 MONTH_NL=$(date +%-m)
else DAY_NL=$(date +%-d)
BUILD_NUMBER=$(($TAG_COUNT + 1))
fi TAG_COUNT=$(git tag -l "${DATE_LEADING}.*" | wc -l)
BUILD_NUMBER="${TAG_COUNT}" # 0 on first build, 1 on second, etc.
VERSION_SUFFIX="${{ inputs.version_suffix }}" VERSION_SUFFIX="${{ inputs.version_suffix }}"
SUFFIX_SEPARATOR="${{ inputs.suffix_separator }}" SUFFIX_SEPARATOR="${{ inputs.suffix_separator }}"
# Regular (keeps leading zeros in date)
if [ -n "$VERSION_SUFFIX" ]; then if [ -n "$VERSION_SUFFIX" ]; then
BUILD_VERSION="${DATE}.${BUILD_NUMBER}${SUFFIX_SEPARATOR}${VERSION_SUFFIX}" BUILD_VERSION="${DATE_LEADING}.${BUILD_NUMBER}${SUFFIX_SEPARATOR}${VERSION_SUFFIX}"
else else
BUILD_VERSION="${DATE}.${BUILD_NUMBER}" BUILD_VERSION="${DATE_LEADING}.${BUILD_NUMBER}"
fi
# Dotnet variant: no leading zeros for month/day, omit build segment when 0
DOTNET_DATE="${YEAR}.${MONTH_NL}.${DAY_NL}"
if [ "${BUILD_NUMBER}" -eq 0 ]; then
if [ -n "$VERSION_SUFFIX" ]; then
DOTNET_VERSION="${DOTNET_DATE}${SUFFIX_SEPARATOR}${VERSION_SUFFIX}"
else
DOTNET_VERSION="${DOTNET_DATE}"
fi
else
if [ -n "$VERSION_SUFFIX" ]; then
DOTNET_VERSION="${DOTNET_DATE}.${BUILD_NUMBER}${SUFFIX_SEPARATOR}${VERSION_SUFFIX}"
else
DOTNET_VERSION="${DOTNET_DATE}.${BUILD_NUMBER}"
fi
fi
# NPM variant: year.month.(DDbb) where DD=day zero-padded to 2, bb=build zero-padded to 2
DAY_PAD=$(printf '%02d' "${DAY_NL}")
BUILD_PAD=$(printf '%02d' "${BUILD_NUMBER}")
NPM_DAY_BUILD="${DAY_PAD}${BUILD_PAD}"
if [ -n "$VERSION_SUFFIX" ]; then
NPM_VERSION="${YEAR}.${MONTH_NL}.${NPM_DAY_BUILD}${SUFFIX_SEPARATOR}${VERSION_SUFFIX}"
else
NPM_VERSION="${YEAR}.${MONTH_NL}.${NPM_DAY_BUILD}"
fi fi
echo "$BUILD_VERSION" > version.txt echo "$BUILD_VERSION" > version.txt
echo "$BUILD_VERSION" > version
echo "$DOTNET_VERSION" > dotnet-version.txt
echo "$DOTNET_VERSION" > dotnet-version
echo "$NPM_VERSION" > npm-version.txt
echo "$NPM_VERSION" > npm-version
echo "VERSION=$BUILD_VERSION" >> $GITHUB_ENV echo "VERSION=$BUILD_VERSION" >> $GITHUB_ENV
echo "Generated version: $BUILD_VERSION" echo "DOTNET_VERSION=$DOTNET_VERSION" >> $GITHUB_ENV
echo "NPM_VERSION=$NPM_VERSION" >> $GITHUB_ENV
- name: Create Git Tag - name: Create Git Tag
shell: bash shell: bash
@@ -63,3 +98,15 @@ runs:
with: with:
name: version name: version
path: version.txt path: version.txt
- name: Upload Dotnet Version Artifact
uses: https://github.com/actions/upload-artifact@v3
with:
name: dotnet-version
path: dotnet-version.txt
- name: Upload NPM Version Artifact
uses: https://github.com/actions/upload-artifact@v3
with:
name: npm-version
path: npm-version.txt

View File

@@ -22,6 +22,29 @@ public class PackageFilterTests
}).ToList(); }).ToList();
} }
[Fact]
public void TestPackageNameParsing()
{
var inputString =
"@sh-edraft.de/core, sh-edraft.core.api, sh-edraft.core.api.auth, sh-edraft.core.api.configuration, sh-edraft.core.api.db, sh-edraft.core.api.graphql, sh-edraft.core.api.service, sh-edraft.core.utils";
List<string> expected = [
"@sh-edraft.de/core",
"sh-edraft.core.api",
"sh-edraft.core.api.auth",
"sh-edraft.core.api.configuration",
"sh-edraft.core.api.db",
"sh-edraft.core.api.graphql",
"sh-edraft.core.api.service",
"sh-edraft.core.utils"
];
var actual = inputString
.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
Assert.Equal(expected.Count, actual.Length);
Assert.Equal(expected, actual);
}
[Fact] [Fact]
public void TestFilterPackagesToDelete() public void TestFilterPackagesToDelete()
{ {
@@ -102,7 +125,26 @@ public class PackageFilterTests
"2024.8.10.0-exp", "2024.8.10.0-exp",
"2024.8.10.1-exp", "2024.8.10.1-exp",
"2024.8.11.0-exp", "2024.8.11.0-exp",
"2024.8.11.2-exp" "2024.8.11.2-exp",
"2026.2.21.27-dev",
"2026.2.21.26-dev",
"2026.2.21.25-dev",
"2026.2.21.24-dev",
"2026.2.21.23-dev",
"2026.2.21.22-dev",
"2026.2.21.21-dev",
"2026.2.21.20-dev",
"2026.2.21.19-dev",
"2026.2.21.18-dev",
"2026.2.21.17-dev",
"2026.2.21.15-dev",
"2026.2.21.14-dev",
"2026.2.21.13-dev",
"2026.2.21.12-dev",
"2026.2.21.11-dev",
"2026.2.21.10-dev",
"2026.2.21.9-dev",
"2026.2.21.8-dev",
]; ];
private readonly List<string> _versionsToHold = private readonly List<string> _versionsToHold =
@@ -139,7 +181,9 @@ public class PackageFilterTests
"0.1.1-exp", "0.1.1-exp",
"0.1.2-exp", "0.1.2-exp",
"2024.8.11.0-exp", "2024.8.11.0-exp",
"2024.8.11.2-exp" "2024.8.11.2-exp",
"2026.2.21.27-dev",
"2026.2.21.26-dev",
]; ];
private List<string> _expectDeleted => _versions.Except(_versionsToHold).ToList(); private List<string> _expectDeleted => _versions.Except(_versionsToHold).ToList();

View File

@@ -1,5 +1,6 @@
namespace sh.actions.package_cleanup.Service; namespace sh.actions.package_cleanup.Service;
using System;
using System.Net.Http.Json; using System.Net.Http.Json;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using sh.actions.package_cleanup.Models; using sh.actions.package_cleanup.Models;
@@ -10,8 +11,10 @@ public class GiteaPackageService(
HttpClient httpClient) HttpClient httpClient)
: IGiteaPackageService : IGiteaPackageService
{ {
private static string EncodePathSegment(string? s) => Uri.EscapeDataString((s ?? string.Empty));
private string GetBaseUrl() => private string GetBaseUrl() =>
$"{configuration["URL"]?.TrimEnd('/')}/packages/{configuration["OWNER"]}"; $"{configuration["URL"]?.TrimEnd('/')}/packages/{EncodePathSegment(configuration["OWNER"]) }";
private void AddAuthorizationHeader(HttpRequestMessage request) private void AddAuthorizationHeader(HttpRequestMessage request)
{ {
@@ -45,7 +48,10 @@ public class GiteaPackageService(
while (true) while (true)
{ {
var url = $"{baseUrl}/{type}/{name}?page={page}"; var encodedType = EncodePathSegment(type);
var encodedName = EncodePathSegment(name);
var url = $"{baseUrl}/{encodedType}/{encodedName}?page={page}";
logger.LogInformation("Fetching packages from Gitea: {Url}", url); logger.LogInformation("Fetching packages from Gitea: {Url}", url);
var request = new HttpRequestMessage(HttpMethod.Get, url); var request = new HttpRequestMessage(HttpMethod.Get, url);
@@ -126,7 +132,11 @@ public class GiteaPackageService(
try try
{ {
var baseUrl = GetBaseUrl(); var baseUrl = GetBaseUrl();
var url = $"{baseUrl}/{package.Type}/{package.Name}/{package.Version}"; var encodedType = EncodePathSegment(package.Type);
var encodedName = EncodePathSegment(package.Name);
var encodedVersion = EncodePathSegment(package.Version);
var url = $"{baseUrl}/{encodedType}/{encodedName}/{encodedVersion}";
logger.LogInformation("Deleting package {PackageName} (ID: {PackageId}) from Gitea", logger.LogInformation("Deleting package {PackageName} (ID: {PackageId}) from Gitea",
package.Name, package.Id); package.Name, package.Id);

View File

@@ -17,6 +17,8 @@ public class Worker(
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);
logger.LogInformation("Would delete packages: {versions}",
string.Join(", ", packages.Select(p => p.Version)));
} }
foreach (var giteaPackage in packages) foreach (var giteaPackage in packages)
@@ -54,22 +56,31 @@ public class Worker(
return; return;
} }
logger.LogInformation("Deleting {count} packages: {names}", names.Length, string.Join(", ", names));
// Process each name separately: collect -> filter -> delete // Process each name separately: collect -> filter -> delete
foreach (var name in names) foreach (var name in names)
{ {
logger.LogInformation("Processing packages for name '{Name}'", name); try
{
logger.LogInformation("Processing packages for name '{Name}'", name);
var packages = (await giteaPackageService.GetPackagesByNameAsync(name, cancellationToken)).ToList(); var packages = (await giteaPackageService.GetPackagesByNameAsync(name, cancellationToken)).ToList();
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, logger.LogInformation("Found {Count} packages to delete for name '{Name}'", packagesToDelete.Count,
name); name);
await DeletePackages(packagesToDelete, cancellationToken); await DeletePackages(packagesToDelete, cancellationToken);
logger.LogInformation("Deleted {Count} packages for name '{Name}'", packagesToDelete.Count, name); logger.LogInformation("Deleted {Count} packages for name '{Name}'", packagesToDelete.Count, name);
logger.LogInformation("Cleanup finished for name '{Name}'", name); logger.LogInformation("Cleanup finished for name '{Name}'", name);
}
catch (Exception ex)
{
logger.LogError(ex, "Failed to delete package {PackageName}", name);
}
} }
logger.LogInformation("All package names processed successfully"); logger.LogInformation("All package names processed successfully");

View File

@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=6fbf28ff_002Db08e_002D4d2b_002D8694_002D3f25abc9fe16/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;sh.actions.package-cleanup.Tests&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Project Location="/home/sven/dev/git_sh-edraft_de/actions/sh.actions.package-cleanup.Tests" Presentation="&amp;lt;sh.actions.package-cleanup.Tests&amp;gt;" /&gt;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>