Skip to content

Generate Reference Package #3285

Generate Reference Package

Generate Reference Package #3285

name: Generate Reference Package
on:
workflow_dispatch:
inputs:
build_version:
description: "Build version from Resonite (optional, uses Build.version if not provided)"
required: false
type: string
branch:
description: "Branch to process"
required: false
default: "public"
type: string
publish:
description: "publish to nuget"
required: false
default: false
type: boolean
schedule:
- cron: "*/10 * * * *"
jobs:
generate:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
attestations: write
steps:
- name: Checkout Repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Setup .NET
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0
with:
dotnet-version: "10.0.x"
- name: Download Resonite Assemblies
uses: hazre/resonite-download-action@a0255ea1241b3245c1e6783aa7a3db24d07e11bb # v1.0.2
with:
steam-username: ${{ secrets.STEAM_USERNAME }}
steam-password: ${{ secrets.STEAM_PASSWORD }}
resonite-path: resonite-assemblies
branch: ${{ github.event.inputs.branch || 'public' }}
- name: Resolve Build Metadata
env:
INPUT_BUILD_VERSION: ${{ github.event.inputs.build_version }}
INPUT_BRANCH: ${{ github.event.inputs.branch || 'public' }}
run: |
# Prefer explicit input version for manual runs, otherwise read from Build.version
if [ -n "${INPUT_BUILD_VERSION:-}" ]; then
version="$INPUT_BUILD_VERSION"
echo "Using provided build_version input: $version"
else
version_file="resonite-assemblies/Build.version"
if [ -f "$version_file" ]; then
version=$(cat "$version_file" | tr -d '\r\n')
echo "Read version from Build.version: $version"
else
echo "Error: No build_version provided and Build.version not found"
exit 1
fi
fi
branch="${INPUT_BRANCH:-public}"
echo "Processing branch: $branch"
if [ "$branch" != "public" ]; then
sanitized_branch=$(echo "$branch" | sed 's/[^a-zA-Z0-9-]/-/g')
version="${version}-${sanitized_branch}"
echo "Appended branch name to version for prerelease"
fi
package_name=$(jq -r '.PackageIdPrefix + .SinglePackageName' Resonite.json)
if [ -z "$package_name" ] || [ "$package_name" = "null" ]; then
echo "Error: Could not derive package name from Resonite.json"
exit 1
fi
echo "Using version: $version"
echo "Resolved package name: $package_name"
echo "BUILD_VERSION=$version" >> $GITHUB_ENV
echo "PACKAGE_NAME=$package_name" >> $GITHUB_ENV
- name: Check NuGet for Existing Version
run: |
package_id_lower=$(echo "$PACKAGE_NAME" | tr '[:upper:]' '[:lower:]')
version_lower=$(echo "$BUILD_VERSION" | tr '[:upper:]' '[:lower:]')
index_url="https://api.nuget.org/v3-flatcontainer/${package_id_lower}/index.json"
echo "Checking NuGet for ${PACKAGE_NAME} ${BUILD_VERSION}"
if curl -fsSL "$index_url" | jq -e --arg v "$version_lower" '.versions | map(ascii_downcase) | index($v) != null' > /dev/null; then
echo "Version already exists on NuGet. Marking workflow for early skip."
echo "SKIP_WORKFLOW=true" >> $GITHUB_ENV
else
echo "Version not published yet. Continuing workflow."
echo "SKIP_WORKFLOW=false" >> $GITHUB_ENV
fi
- name: Early Exit (Already Published)
if: env.SKIP_WORKFLOW == 'true'
run: echo "Skipping package generation because this version is already published to NuGet."
- name: Prepare Config
if: env.SKIP_WORKFLOW != 'true'
env:
BUILD_VERSION: ${{ env.BUILD_VERSION }}
run: |
version="$BUILD_VERSION"
# Copy and modify the Resonite.json config
cp Resonite.json resonite-config.json
# Use jq to update paths and version
jq --arg sp "${{ github.workspace }}/resonite-assemblies" \
--arg dp "${{ github.workspace }}/output/dlls" \
--arg np "${{ github.workspace }}/output/packages" \
--arg rp "${{ github.workspace }}/ReferencePackageGenerator/README.md" \
--arg ver "$version" \
'.SourcePath = $sp |
.DllTargetPath = $dp |
.NupkgTargetPath = $np |
.ReadmePath = $rp |
.SinglePackageVersion = $ver' \
resonite-config.json > resonite-config-temp.json
mv resonite-config-temp.json resonite-config.json
echo "Config file prepared from Resonite.json"
- name: Generate Reference Package
if: env.SKIP_WORKFLOW != 'true'
run: |
cd ReferencePackageGenerator
dotnet run -- "${{ github.workspace }}/resonite-config.json"
- name: Attest Build Provenance
if: env.SKIP_WORKFLOW != 'true'
uses: actions/attest-build-provenance@0f67c3f4856b2e3261c31976d6725780e5e4c373
with:
subject-path: output/packages/${{ env.PACKAGE_NAME }}.nupkg
- name: Upload Package Artifact
if: env.SKIP_WORKFLOW != 'true'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: reference-package-${{ env.BUILD_VERSION }}
path: output/packages/*.nupkg
retention-days: 30
- name: Upload DLLs Artifact
if: env.SKIP_WORKFLOW != 'true'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: stripped-dlls-${{ env.BUILD_VERSION }}
path: output/dlls/*.dll
retention-days: 7
- name: Publish to NuGet
if: env.SKIP_WORKFLOW != 'true' && (github.event_name == 'schedule' || github.event.inputs.publish == 'true')
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
if [ -n "$NUGET_API_KEY" ]; then
for package in output/packages/*.nupkg; do
if [ -f "$package" ]; then
echo "Publishing $(basename $package) to NuGet..."
dotnet nuget push "$package" --api-key "$NUGET_API_KEY" --source https://api.nuget.org/v3/index.json --skip-duplicate
fi
done
else
echo "Warning: NUGET_API_KEY not set, skipping publish"
fi