Initial Commit

This commit is contained in:
2026-01-29 12:35:43 +01:00
commit c6553f80bc
10 changed files with 285 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
# publish-nuget
A Gitea Action which pushes a package to our NuGet registry, and performs Gitea artifact attestation on the result.
+47
View File
@@ -0,0 +1,47 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/github-action.json
name: "publish-nuget"
description: "Publishes a NuGet package to a Gitea-hosted NuGet registry and attests to its contents."
inputs:
package-name:
description: "Name of the NuGet package, e.g. Oceanbox.FvcomKit."
required: true
nuget-key:
description: "API key with which to authenticate to the NuGet registry."
required: true
nupkg-dir:
description: |
Directory in which to find the NuGet .nupkg file. We will search one level deep inside this directory for nupkg files named {package-name}.{any-string}.nupkg.
Note that this action is not designed to work if you have two .nupkg files inside this directory, one called Foo.0.0.0.nupkg and one called Foo.Bar.0.0.0.nupkg;
you should make sure there's only one package in this directory.
required: true
registry-url:
description: "URL of the NuGet registry, e.g. https://git.oceanbox.io/api/packages/oceanbox/nuget/index.json"
required: true
default: "https://git.oceanbox.io/api/packages/oceanbox/nuget/index.json"
source-name:
description: "Name to use for the NuGet source when adding it."
required: false
default: "gitea-nuget"
dotnet:
description: "Path to the `dotnet` executable, if you want to override the default (e.g. because you wish to operate inside a Nix devshell)."
required: false
default: "dotnet"
skip-duplicate:
description: 'If set to "true", skips publishing if the package version already exists.'
required: false
default: "true"
runs:
using: "composite"
steps:
- name: Publish to NuGet Registry
shell: bash
id: publish-success
env:
NUGET_API_KEY: ${{ inputs.nuget-key }}
PACKAGE_DIR: ${{ inputs.nupkg-dir }}
PACKAGE_NAME: ${{ inputs.package-name }}
DOTNET_EXE: ${{ inputs.dotnet }}
REGISTRY_URL: ${{ inputs.registry-url }}
SOURCE_NAME: ${{ inputs.source-name }}
SKIP_DUPLICATE: ${{ inputs.skip-duplicate }}
run: '$GITHUB_ACTION_PATH/nuget_push.sh "$PACKAGE_DIR"/"$PACKAGE_NAME".*.nupkg'
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -euo pipefail
# Script to publish NuGet packages to a Gitea registry
# Usage: nuget_push.sh <nupkg-path-pattern>
NUPKG_PATTERN="${1:?Missing nupkg pattern argument}"
# Function to run commands, optionally in nix-shell
run_cmd() {
nix-shell --run "$*"
}
# Find the nupkg file
NUPKG_FILE=$(find "$(dirname "$NUPKG_PATTERN")" -maxdepth 1 -name "$(basename "$NUPKG_PATTERN")" -type f | head -n 1)
if [[ -z "$NUPKG_FILE" ]]; then
echo "Error: No .nupkg file found matching pattern: $NUPKG_PATTERN"
exit 1
fi
echo "Found package: $NUPKG_FILE"
# Extract version from filename
FILENAME=$(basename "$NUPKG_FILE")
VERSION=$(echo "$FILENAME" | sed -E "s/^${PACKAGE_NAME}\.(.+)\.nupkg$/\1/")
echo "Package version: $VERSION"
# Add NuGet source if not already present
echo "Configuring NuGet source: $SOURCE_NAME"
run_cmd "$DOTNET_EXE nuget list source" | grep -q "$SOURCE_NAME" || \
run_cmd "$DOTNET_EXE nuget add source --name \"$SOURCE_NAME\" \"$REGISTRY_URL\""
# Publish the package
echo "Publishing package to $SOURCE_NAME..."
PUSH_CMD="$DOTNET_EXE nuget push \"$NUPKG_FILE\" --api-key \"$NUGET_API_KEY\" --source \"$SOURCE_NAME\""
if [[ "${SKIP_DUPLICATE:-true}" == "true" ]]; then
PUSH_CMD="$PUSH_CMD --skip-duplicate"
fi
if run_cmd "$PUSH_CMD"; then
# Check if it was skipped or actually pushed
# If skip-duplicate is enabled and package exists, dotnet exits with 0 but prints a message
echo "result=published" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Successfully published (or skipped duplicate): $PACKAGE_NAME $VERSION"
else
echo "result=failed" >> "$GITHUB_OUTPUT"
echo "Failed to publish package"
exit 1
fi