Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 140 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ on:
tags:
- '*'
Comment thread
JayPavlina marked this conversation as resolved.
Outdated
pull_request:
Comment thread
JayPavlina marked this conversation as resolved.
workflow_dispatch:
inputs:
version:
description: 'UPM version to build (without leading v), e.g. 3.0.0. Only used by the upm job; the main build runs on the current ref.'
required: false

permissions:
contents: write
Expand Down Expand Up @@ -52,8 +57,141 @@ jobs:
- name: Build NuGet Packages
run: dotnet pack ./src/Enjin.Platform.Sdk/Enjin.Platform.Sdk/Enjin.Platform.Sdk.csproj --configuration Release --no-build --output ./src/Enjin.Platform.Sdk/nuget-packages/

- name: Upload Artifacts
- name: Upload nupkgs to draft release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
if: startsWith(github.ref, 'refs/tags/v')
with:
# Keep the release in draft mode until the publish-release job flips
# it. softprops/action-gh-release upserts the release, so uploads from
# multiple jobs/workflows on the same tag all attach to the same
# draft. This avoids the "immutable release" upload error that
# happens when assets are pushed after publication.
draft: true
files: ./src/Enjin.Platform.Sdk/nuget-packages/*.nupkg

- name: Publish to NuGet.org
if: startsWith(github.ref, 'refs/tags/v')
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
dotnet nuget push ./src/Enjin.Platform.Sdk/nuget-packages/*.nupkg \
--api-key "${NUGET_API_KEY}" \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate

upm:
# Assembles the Unity Package Manager distribution from unity-template/ +
# the freshly-built DLL, pushes it to a parallel `upm/v<version>` git tag
# (which is what users reference in their Unity Package Manager git URL),
# and attaches the tarball to the same draft GitHub Release.
needs: build
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
Comment thread
JayPavlina marked this conversation as resolved.
Outdated
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Need full history + a writable token so we can push the upm/<version> tag.
fetch-depth: 0
persist-credentials: true

- name: Determine version
id: version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
if [[ -z "${VERSION}" ]]; then
echo "::error::workflow_dispatch requires the 'version' input"
exit 1
fi
else
# strip leading 'v' from refs/tags/v3.0.0
VERSION="${GITHUB_REF_NAME#v}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "Building UPM package for version ${VERSION}"

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Cache NuGet Packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-

- name: Build SDK (Release)
run: dotnet build ./src/Enjin.Platform.Sdk/Enjin.Platform.Sdk/Enjin.Platform.Sdk.csproj --configuration Release

- name: Assemble UPM package
run: ./scripts/assemble-upm.sh ${{ steps.version.outputs.version }}

- name: Push upm/<version> tag
# This is what end users reference in their Unity Package Manager git URL:
# https://github.com/enjin/platform-csharp-sdk.git#upm/v3.0.0
# The tag points at an orphan commit whose tree is exactly the contents
# of upm-staging/, so Unity's git fetcher sees a valid UPM package at
# the repo root (without any ?path= suffix needed).
#
# NOTE: the repo's tag-name ruleset must allow upm/v* tags (or grant a
# bypass to github-actions). Otherwise the push is rejected with
# "Tag name must match a given regex pattern".
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
VERSION="${{ steps.version.outputs.version }}"
UPM_TAG="upm/v${VERSION}"

WORK="$(mktemp -d)"
cp -R upm-staging/. "${WORK}/"
(
cd "${WORK}"
git init -q -b "${UPM_TAG}"
git remote add origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git add -A
git -c user.name="github-actions[bot]" \
-c user.email="41898282+github-actions[bot]@users.noreply.github.com" \
commit -q -m "UPM package v${VERSION}"
git tag -f "${UPM_TAG}"
git push -f origin "refs/tags/${UPM_TAG}"
)
rm -rf "${WORK}"
echo "Pushed tag ${UPM_TAG}"

- name: Attach UPM tarball to draft release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/v')
with:
draft: true
files: EnjinPlatformSdk-v${{ steps.version.outputs.version }}-upm.tar.gz

- name: Upload tarball as workflow artifact
# Always upload (including workflow_dispatch runs) so manual builds are
# downloadable for inspection without needing a release.
uses: actions/upload-artifact@v4
with:
name: EnjinPlatformSdk-v${{ steps.version.outputs.version }}-upm
path: EnjinPlatformSdk-v${{ steps.version.outputs.version }}-upm.tar.gz

publish-release:
# Flip the draft release to published once both the nupkgs and UPM tarball
# have been attached. This step is what makes the release "go live" on the
# repo's Releases page and on the GitHub Releases API.
needs: [build, upm]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Publish GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
set -euo pipefail
TAG="${GITHUB_REF_NAME}"
echo "Publishing release ${TAG}"
gh release edit "${TAG}" --draft=false
104 changes: 0 additions & 104 deletions .github/workflows/unity.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void DefaultUserAgentIsDerivedFromAssemblyVersion()
version = version[1..];
}

var expected = $"Enjin.Platform.Sdk/{version}";
var expected = $"Enjin-Platform-CSharp-SDK/{version}";

// Act
using var client = new PlatformClient(new Uri(_server.Urls[0] + "/graphql"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ namespace Enjin.Platform.Sdk;
[PublicAPI]
public sealed class PlatformClient : IPlatformClient
{
/// <summary>
/// The default base address of the Enjin Platform GraphQL endpoint.
/// </summary>
public static readonly Uri DefaultBaseAddress = new("https://platform.enjin.io/graphql");

private static readonly string DefaultUserAgent = BuildDefaultUserAgent();

private static string BuildDefaultUserAgent()
Expand All @@ -38,7 +43,7 @@ private static string BuildDefaultUserAgent()
version = version[1..];
}

return $"Enjin.Platform.Sdk/{version}";
return $"Enjin-Platform-CSharp-SDK/{version}";
}

private readonly HttpClient _httpClient;
Expand All @@ -58,21 +63,18 @@ private static string BuildDefaultUserAgent()
/// <summary>
/// Initializes a new <see cref="PlatformClient"/>.
/// </summary>
/// <param name="baseAddress">The base address of the platform's GraphQL endpoint (e.g. <c>https://platform.enjin.io/graphql</c>).</param>
/// <param name="userAgent">Optional User-Agent header value. Defaults to <c>Enjin.Platform.Sdk/{assembly-version}</c>.</param>
/// <param name="baseAddress">The base address of the platform's GraphQL endpoint (e.g. <c>https://platform.enjin.io/graphql</c>). Defaults to <see cref="DefaultBaseAddress"/>.</param>
/// <param name="userAgent">Optional User-Agent header value. Defaults to <c>Enjin-Platform-CSharp-SDK/{assembly-version}</c>.</param>
/// <param name="logger">Optional logger; when provided HTTP traffic is logged at the given <paramref name="httpLogLevel"/>.</param>
/// <param name="httpLogLevel">HTTP log level. Ignored when <paramref name="logger"/> is <c>null</c>.</param>
public PlatformClient(
Uri baseAddress,
Uri? baseAddress = null,
string? userAgent = null,
ILogger? logger = null,
HttpLogLevel httpLogLevel = HttpLogLevel.None
)
{
if (baseAddress == null)
{
throw new ArgumentNullException(nameof(baseAddress));
}
baseAddress ??= DefaultBaseAddress;

Comment thread
JayPavlina marked this conversation as resolved.
UserAgent = userAgent ?? DefaultUserAgent;

Expand Down
Loading