Skip to content

Commit

Permalink
Merge pull request #1920 from tgstation/1858-AppSupport [APIDeploy][N…
Browse files Browse the repository at this point in the history
…ugetDeploy][DMDeploy]

Support for player count, uptime, and GitHub App authentication
  • Loading branch information
Cyberboss authored Sep 4, 2024
2 parents f668b84 + 02a9f26 commit d0d506f
Show file tree
Hide file tree
Showing 49 changed files with 720 additions and 179 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-approve-dominions-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: GitHub API Call
run: |
curl --request POST \
--url https://api.github.com/repos/${{github.repository}}/pulls/${{github.event.number}}/reviews \
--url https://api.github.com/repos/${{ github.repository }}/pulls/${{github.event.number}}/reviews \
--header 'authorization: Bearer ${{ steps.app-token-generation.outputs.token }}' \
--header 'content-type: application/json' \
-d '{"event":"APPROVE"}' \
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/ci-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,6 @@ jobs:
matrix:
configuration: ["Debug", "Release"]
env:
TGS_TEST_DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
TGS_TEST_IRC_CONNECTION_STRING: ${{ secrets.IRC_CONNECTION_STRING }}
TGS_TELEMETRY_KEY_FILE: /tmp/tgs_telemetry_key.txt
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -486,6 +484,12 @@ jobs:

- name: Run Unit Tests
run: sudo dotnet test --no-build --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" --filter TestCategory!=RequiresDatabase -c ${{ matrix.configuration }}NoWindows --collect:"XPlat Code Coverage" --settings build/ci.runsettings --results-directory ./TestResults tgstation-server.sln
env:
TGS_TEST_DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
TGS_TEST_IRC_CONNECTION_STRING: ${{ secrets.IRC_CONNECTION_STRING }}
TGS_TEST_APP_ID: ${{ secrets.APP_ID }}
TGS_TEST_APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
TGS_TEST_REPO_SLUG: ${{ github.repository }}

- name: Store Code Coverage
uses: actions/upload-artifact@v4
Expand All @@ -500,8 +504,6 @@ jobs:
matrix:
configuration: ["Debug", "Release"]
env:
TGS_TEST_DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
TGS_TEST_IRC_CONNECTION_STRING: ${{ secrets.IRC_CONNECTION_STRING }}
TGS_TELEMETRY_KEY_FILE: C:/tgs_telemetry_key.txt
runs-on: windows-latest
steps:
Expand Down Expand Up @@ -550,6 +552,12 @@ jobs:

- name: Run Unit Tests
run: dotnet test --no-build --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" --filter TestCategory!=RequiresDatabase -c ${{ matrix.configuration }}NoWix --collect:"XPlat Code Coverage" --settings build/ci.runsettings --results-directory ./TestResults tgstation-server.sln
env:
TGS_TEST_DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
TGS_TEST_IRC_CONNECTION_STRING: ${{ secrets.IRC_CONNECTION_STRING }}
TGS_TEST_APP_ID: ${{ secrets.APP_ID }}
TGS_TEST_APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
TGS_TEST_REPO_SLUG: ${{ github.repository }}

- name: Store Code Coverage
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ All users with access to an instance have an InstanceUser object associated with

The `Repository` folder is a git repository containing the code of the game you wish to host. It can be cloned from any public or private remote repository and has capabilities to affect changes back to it. All the standard benefits of git are utilized (i.e. check out any revision or reference).

Additional features become available if the remote repository is hosted on https://github.com/. Namely the Test Merge feature, which allows you to take a pull request opened on the repository and compile it into a game deployment for testing. Information about test merges is available in game via the DMAPI and via the main API as well.
Additional features become available if the remote repository is hosted on https://github.com/. Namely the Test Merge feature, which allows you to take a pull request opened on the repository and compile it into a game deployment for testing. Information about test merges is available in game via the DMAPI and via the main API as well. These require a valid personal access token with `repo` scope or an installed GitHub App with the following permissions: `contents: write`, `pull_requests: write`, and `deployments: write`.

Manual operations on the repository while an instance is running may lead to git data corruption. Thankfully, it's simple enough to delete and reclone the repository via the API.

Expand Down
14 changes: 7 additions & 7 deletions build/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<!-- Integration tests will ensure they match across the board -->
<Import Project="WebpanelVersion.props" />
<PropertyGroup>
<TgsCoreVersion>6.9.2</TgsCoreVersion>
<TgsCoreVersion>6.10.0</TgsCoreVersion>
<TgsConfigVersion>5.2.0</TgsConfigVersion>
<TgsApiVersion>10.7.0</TgsApiVersion>
<TgsApiVersion>10.8.0</TgsApiVersion>
<TgsCommonLibraryVersion>7.0.0</TgsCommonLibraryVersion>
<TgsApiLibraryVersion>13.7.0</TgsApiLibraryVersion>
<TgsClientVersion>16.0.0</TgsClientVersion>
<TgsDmapiVersion>7.2.1</TgsDmapiVersion>
<TgsInteropVersion>5.9.0</TgsInteropVersion>
<TgsHostWatchdogVersion>1.4.1</TgsHostWatchdogVersion>
<TgsApiLibraryVersion>14.0.0</TgsApiLibraryVersion>
<TgsClientVersion>17.0.0</TgsClientVersion>
<TgsDmapiVersion>7.3.0</TgsDmapiVersion>
<TgsInteropVersion>5.10.0</TgsInteropVersion>
<TgsHostWatchdogVersion>1.5.0</TgsHostWatchdogVersion>
<TgsContainerScriptVersion>1.2.1</TgsContainerScriptVersion>
<TgsMigratorVersion>2.0.0</TgsMigratorVersion>
<TgsNugetNetFramework>netstandard2.0</TgsNugetNetFramework>
Expand Down
2 changes: 1 addition & 1 deletion build/tgstation-server.service
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ User=tgstation-server
Type=notify-reload
NotifyAccess=all
WorkingDirectory=/opt/tgstation-server
ExecStart=/usr/bin/dotnet Tgstation.Server.Host.Console.dll --appsettings-base-path=/etc/tgstation-server --General:SetupWizardMode=Never --Internal:UsingSystemD=true
ExecStart=/usr/bin/dotnet Tgstation.Server.Host.Console.dll --appsettings-base-path=/etc/tgstation-server --General:SetupWizardMode=Never
TimeoutStartSec=600
Restart=always
KillMode=process
Expand Down
2 changes: 1 addition & 1 deletion src/DMAPI/tgs.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tgstation-server DMAPI
// The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in IETF RFC 2119.

#define TGS_DMAPI_VERSION "7.2.1"
#define TGS_DMAPI_VERSION "7.3.0"

// All functions and datums outside this document are subject to change with any version and should not be relied on.

Expand Down
2 changes: 1 addition & 1 deletion src/DMAPI/tgs/v5/__interop_version.dm
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"5.9.0"
"5.10.0"
1 change: 1 addition & 0 deletions src/DMAPI/tgs/v5/_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
#define DMAPI5_TOPIC_PARAMETER_NEW_SERVER_VERSION "newServerVersion"
#define DMAPI5_TOPIC_PARAMETER_BROADCAST_MESSAGE "broadcastMessage"

#define DMAPI5_TOPIC_RESPONSE_CLIENT_COUNT "clientCount"
#define DMAPI5_TOPIC_RESPONSE_COMMAND_RESPONSE "commandResponse"
#define DMAPI5_TOPIC_RESPONSE_COMMAND_RESPONSE_MESSAGE "commandResponseMessage"
#define DMAPI5_TOPIC_RESPONSE_CHAT_RESPONSES "chatResponses"
Expand Down
4 changes: 3 additions & 1 deletion src/DMAPI/tgs/v5/topic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@
if(DMAPI5_TOPIC_COMMAND_HEALTHCHECK)
if(event_handler && event_handler.receive_health_checks)
event_handler.HandleEvent(TGS_EVENT_HEALTH_CHECK)
return TopicResponse()
var/list/health_check_response = TopicResponse()
health_check_response[DMAPI5_TOPIC_RESPONSE_CLIENT_COUNT] = TGS_CLIENT_COUNT
return health_check_response;

if(DMAPI5_TOPIC_COMMAND_WATCHDOG_REATTACH)
detached = FALSE
Expand Down
2 changes: 1 addition & 1 deletion src/DMAPI/tgs/v5/undefs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#undef DMAPI5_PARAMETER_ACCESS_IDENTIFIER
#undef DMAPI5_PARAMETER_CUSTOM_COMMANDS
#undef DMAPI5_PARAMETER_TOPIC_PORT

#undef DMAPI5_CHUNK
#undef DMAPI5_CHUNK_PAYLOAD
Expand Down Expand Up @@ -95,6 +94,7 @@
#undef DMAPI5_TOPIC_PARAMETER_NEW_SERVER_VERSION
#undef DMAPI5_TOPIC_PARAMETER_BROADCAST_MESSAGE

#undef DMAPI5_TOPIC_RESPONSE_CLIENT_COUNT
#undef DMAPI5_TOPIC_RESPONSE_COMMAND_RESPONSE
#undef DMAPI5_TOPIC_RESPONSE_COMMAND_RESPONSE_MESSAGE
#undef DMAPI5_TOPIC_RESPONSE_CHAT_RESPONSES
Expand Down
18 changes: 12 additions & 6 deletions src/Tgstation.Server.Api/Models/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public enum ErrorCode : uint
SwarmIntegrityCheckFailed,

/// <summary>
/// One of <see cref="Internal.RepositorySettings.AccessUser"/> and <see cref="Internal.RepositorySettings.AccessToken"/> is set while the other isn't.
/// One of <see cref="RepositorySettings.AccessUser"/> and <see cref="RepositorySettings.AccessToken"/> is set while the other isn't.
/// </summary>
[Description("Either both accessUser and accessToken must be set or neither!")]
RepoMismatchUserAndAccessToken,
Expand Down Expand Up @@ -239,13 +239,13 @@ public enum ErrorCode : uint
RepoDuplicateTestMerge,

/// <summary>
/// Attempted to set a whitespace <see cref="Internal.RepositorySettings.CommitterName"/>.
/// Attempted to set a whitespace <see cref="RepositorySettings.CommitterName"/>.
/// </summary>
[Description("committerName cannot be whitespace!")]
RepoWhitespaceCommitterName,

/// <summary>
/// Attempted to set a whitespace <see cref="Internal.RepositorySettings.CommitterEmail"/>.
/// Attempted to set a whitespace <see cref="RepositorySettings.CommitterEmail"/>.
/// </summary>
[Description("committerEmail cannot be whitespace!")]
RepoWhitespaceCommitterEmail,
Expand Down Expand Up @@ -377,19 +377,19 @@ public enum ErrorCode : uint
InstanceMissingDreamMakerSettings,

/// <summary>
/// Missing <see cref="Internal.RepositorySettings"/> in database.
/// Missing <see cref="RepositorySettings"/> in database.
/// </summary>
[Description("Could not retrieve Repository settings from the database!")]
InstanceMissingRepositorySettings,

/// <summary>
/// Performing an automatic update with the <see cref="Internal.RepositorySettings.AutoUpdatesKeepTestMerges"/> flag resulted in merge conflicts.
/// Performing an automatic update with the <see cref="RepositorySettings.AutoUpdatesKeepTestMerges"/> flag resulted in merge conflicts.
/// </summary>
[Description("Performing this automatic update as a merge would result in conficts. Aborting!")]
InstanceUpdateTestMergeConflict,

/// <summary>
/// <see cref="Internal.RepositorySettings.AccessUser"/> and <see cref="Internal.RepositorySettings.AccessToken"/> are required for this operation.
/// <see cref="RepositorySettings.AccessUser"/> and <see cref="RepositorySettings.AccessToken"/> are required for this operation.
/// </summary>
[Description("Git credentials are required for this operation!")]
RepoCredentialsRequired,
Expand Down Expand Up @@ -657,5 +657,11 @@ public enum ErrorCode : uint
/// </summary>
[Description("Could not load configured .dme due to it being outside the deployment directory! This should be a relative path.")]
DeploymentWrongDme,

/// <summary>
/// Entered wrong <see cref="RepositorySettings.AccessUser"/> for a <see cref="RepositorySettings.AccessToken"/>.
/// </summary>
[Description("Provided repository username doesn't match the user of the corresponding access token!")]
RepoTokenUsernameMismatch,
}
}
16 changes: 15 additions & 1 deletion src/Tgstation.Server.Api/Models/Internal/DreamDaemonApiBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Tgstation.Server.Api.Models.Internal
using System;

namespace Tgstation.Server.Api.Models.Internal
{
/// <summary>
/// Base class for DreamDaemon API models.
Expand All @@ -11,6 +13,18 @@ public abstract class DreamDaemonApiBase : DreamDaemonSettings
[ResponseOptions]
public long? SessionId { get; set; }

/// <summary>
/// When the current server execution was started.
/// </summary>
[ResponseOptions]
public DateTimeOffset? LaunchTime { get; set; }

/// <summary>
/// The last known count of connected players. Requires <see cref="DreamDaemonLaunchParameters.HealthCheckSeconds"/> to not be 0 and a game server interop version >= 5.10.0 to populate.
/// </summary>
[ResponseOptions]
public uint? ClientCount { get; set; }

/// <summary>
/// If the server is undergoing a soft reset. This may be automatically set by changes to other fields.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Tgstation.Server.Api/Models/RemoteGitProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Indicates the remote git host.
/// </summary>
public enum RemoteGitProvider
public enum RemoteGitProvider // Note if adding more: There's an assumption that all but unknown can derive a slug
{
/// <summary>
/// Unknown remote git provider.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using System.ComponentModel.DataAnnotations;

namespace Tgstation.Server.Api.Models.Internal
namespace Tgstation.Server.Api.Models
{
/// <summary>
/// Represents configurable settings for a git repository.
/// </summary>
public class RepositorySettings
public abstract class RepositorySettings
{
/// <summary>
/// Prefix for TGS encoded app private keys. This is encoded in the format PREFIX + (APP_ID OR CLIENT_ID) + ':' + BASE64(APP_PRIVATE_KEY).
/// </summary>
public const string TgsAppPrivateKeyPrefix = "TGS_PK_";

/// <summary>
/// The name of the committer.
/// </summary>
Expand All @@ -23,14 +28,14 @@ public class RepositorySettings
public string? CommitterEmail { get; set; }

/// <summary>
/// The username to access the git repository with.
/// The username to access the git repository with. If using a TGS encoded app private key for <see cref="AccessToken"/>, this should be the app's name.
/// </summary>
[StringLength(Limits.MaximumStringLength)]
[ResponseOptions]
public string? AccessUser { get; set; }

/// <summary>
/// The token/password to access the git repository with.
/// The token/password to access the git repository with. Can also be a TGS encoded app private key. <see cref="TgsAppPrivateKeyPrefix"/> for details.
/// </summary>
[StringLength(Limits.MaximumStringLength)]
[ResponseOptions(Presence = FieldPresence.Ignored)]
Expand Down
10 changes: 5 additions & 5 deletions src/Tgstation.Server.Api/Rights/RepositoryRights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum RepositoryRights : ulong
CancelPendingChanges = 1 << 0,

/// <summary>
/// User may clone the repository if it does not exist. This also allows setting <see cref="Models.Internal.RepositorySettings.UpdateSubmodules"/>, <see cref="Models.Internal.RepositorySettings.AccessUser"/>, and <see cref="Models.Internal.RepositorySettings.AccessToken"/> at clone time.
/// User may clone the repository if it does not exist. This also allows setting <see cref="Models.RepositorySettings.UpdateSubmodules"/>, <see cref="Models.RepositorySettings.AccessUser"/>, and <see cref="Models.RepositorySettings.AccessToken"/> at clone time.
/// </summary>
SetOrigin = 1 << 1,

Expand All @@ -39,17 +39,17 @@ public enum RepositoryRights : ulong
UpdateBranch = 1 << 4,

/// <summary>
/// User may change <see cref="Models.Internal.RepositorySettings.CommitterName"/> and <see cref="Models.Internal.RepositorySettings.CommitterEmail"/>.
/// User may change <see cref="Models.RepositorySettings.CommitterName"/> and <see cref="Models.RepositorySettings.CommitterEmail"/>.
/// </summary>
ChangeCommitter = 1 << 5,

/// <summary>
/// User may change <see cref="Models.Internal.RepositorySettings.PushTestMergeCommits"/>, <see cref="Models.Internal.RepositorySettings.PostTestMergeComment"/>, and <see cref="Models.Internal.RepositorySettings.CreateGitHubDeployments"/>.
/// User may change <see cref="Models.RepositorySettings.PushTestMergeCommits"/>, <see cref="Models.RepositorySettings.PostTestMergeComment"/>, and <see cref="Models.RepositorySettings.CreateGitHubDeployments"/>.
/// </summary>
ChangeTestMergeCommits = 1 << 6,

/// <summary>
/// User may read and change <see cref="Models.Internal.RepositorySettings.AccessUser"/> and <see cref="Models.Internal.RepositorySettings.AccessToken"/>.
/// User may read and change <see cref="Models.RepositorySettings.AccessUser"/> and <see cref="Models.RepositorySettings.AccessToken"/>.
/// </summary>
ChangeCredentials = 1 << 7,

Expand All @@ -64,7 +64,7 @@ public enum RepositoryRights : ulong
Read = 1 << 9,

/// <summary>
/// User may change <see cref="Models.Internal.RepositorySettings.AutoUpdatesKeepTestMerges"/> and <see cref="Models.Internal.RepositorySettings.AutoUpdatesSynchronize"/>.
/// User may change <see cref="Models.RepositorySettings.AutoUpdatesKeepTestMerges"/> and <see cref="Models.RepositorySettings.AutoUpdatesSynchronize"/>.
/// </summary>
ChangeAutoUpdateSettings = 1 << 10,

Expand Down
Loading

0 comments on commit d0d506f

Please sign in to comment.