Compare commits
2 Commits
2026.02.21
...
2026.02.22
| Author | SHA1 | Date | |
|---|---|---|---|
| 6473851d9e | |||
| 2f1a200bdc |
@@ -25,29 +25,58 @@ 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')
|
# Regular date with leading zeros
|
||||||
TAG_COUNT=$(git tag -l "${DATE}.*" | wc -l)
|
DATE_LEADING=$(date +'%Y.%m.%d')
|
||||||
|
|
||||||
if [ "$TAG_COUNT" -eq 0 ]; then
|
# Year, month and day without leading zeros for alternate formats
|
||||||
|
YEAR=$(date +'%Y')
|
||||||
|
MONTH_NL=$(date +%-m)
|
||||||
|
DAY_NL=$(date +%-d)
|
||||||
|
|
||||||
|
TAG_COUNT=$(git tag -l "${DATE_LEADING}.*" | wc -l)
|
||||||
|
|
||||||
|
if [ "${TAG_COUNT}" -eq 0 ]; then
|
||||||
BUILD_NUMBER=0
|
BUILD_NUMBER=0
|
||||||
else
|
else
|
||||||
BUILD_NUMBER=$(($TAG_COUNT + 1))
|
BUILD_NUMBER=$((${TAG_COUNT} + 1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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
|
fi
|
||||||
|
|
||||||
|
# Dotnet variant: year.month.day.build (no leading zeros for month/day)
|
||||||
|
DOTNET_DATE="${YEAR}.${MONTH_NL}.${DAY_NL}"
|
||||||
|
if [ -n "$VERSION_SUFFIX" ]; then
|
||||||
|
DOTNET_VERSION="${DOTNET_DATE}.${BUILD_NUMBER}${SUFFIX_SEPARATOR}${VERSION_SUFFIX}"
|
||||||
|
else
|
||||||
|
DOTNET_VERSION="${DOTNET_DATE}.${BUILD_NUMBER}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# NPM variant: year.month.(day concatenated with build) e.g. 2026.2.221 for day=22 build=1
|
||||||
|
NPM_DAY_BUILD="${DAY_NL}${BUILD_NUMBER}"
|
||||||
|
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
|
||||||
|
|
||||||
|
# Write the versions as artifacts for backward compatibility and accessibility
|
||||||
echo "$BUILD_VERSION" > version.txt
|
echo "$BUILD_VERSION" > version.txt
|
||||||
|
echo "$DOTNET_VERSION" > dotnet-version.txt
|
||||||
|
echo "$NPM_VERSION" > npm-version.txt
|
||||||
|
|
||||||
|
# Export regular version to environment (backwards-compatible)
|
||||||
echo "VERSION=$BUILD_VERSION" >> $GITHUB_ENV
|
echo "VERSION=$BUILD_VERSION" >> $GITHUB_ENV
|
||||||
echo "Generated version: $BUILD_VERSION"
|
|
||||||
|
|
||||||
- name: Create Git Tag
|
- name: Create Git Tag
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -63,3 +92,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
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user