Skip to content

Commit

Permalink
Replaced GatewayApiVersion with assembly Version/ProductVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
krzlabrdx committed Dec 29, 2022
1 parent 4c53fd3 commit 7d7651e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 62 deletions.
85 changes: 36 additions & 49 deletions .github/actions/set-variables/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
description: "Github action name"
required: true
outputs:
version-suffix:
description: "Value of <VersionSuffix> used by MSBuild"
value: ${{ steps.set_variables.outputs.version-suffix }}
version-tag:
description: "General-purpose image tag"
value: ${{ steps.set_variables.outputs.version-tag }}
Expand Down Expand Up @@ -40,62 +43,46 @@ runs:
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD | sed 's/\//-/g')
GIT_COMMIT=$(git log -1 --format=%h )
DOCKER_TAG=${GIT_BRANCH}-${GIT_COMMIT}
if [[ ! -z $GH_EVENT_NAME ]] && [[ "$GH_EVENT_NAME" == "release" ]] ;then
DOCKER_REPO_DATA_AGGREGATOR="eu.gcr.io/dev-container-repo/babylon-ng-data-aggregator"
DOCKER_REPO_GATEWAY_API="eu.gcr.io/dev-container-repo/babylon-ng-gateway-api"
DOCKER_REPO_DATABASE_MIGRATIONS="eu.gcr.io/dev-container-repo/babylon-ng-database-migrations"
VERSION_SUFFIX=${GIT_BRANCH}-${GIT_COMMIT}
DOCKER_REPO_DATA_AGGREGATOR="eu.gcr.io/dev-container-repo/babylon-ng-data-aggregator"
DOCKER_REPO_GATEWAY_API="eu.gcr.io/dev-container-repo/babylon-ng-gateway-api"
DOCKER_REPO_DATABASE_MIGRATIONS="eu.gcr.io/dev-container-repo/babylon-ng-database-migrations"
case "${GH_EVENT_NAME}" in
release)
DOCKER_REPO_DATA_AGGREGATOR="radixdlt/babylon-ng-data-aggregator"
DOCKER_REPO_DATABASE_MIGRATIONS="radixdlt/babylon-ng-database-migrations"
DOCKER_REPO_GATEWAY_API="radixdlt/babylon-ng-gateway-api"
DATA_AGGREGATOR_TAGS="${DOCKER_REPO_DATA_AGGREGATOR}:${{ github.event.release.tag_name }}"
DATABASE_MIGRATIONS_TAGS="${DOCKER_REPO_DATABASE_MIGRATIONS}:${{ github.event.release.tag_name }}"
GATEWAY_API_TAGS="${DOCKER_REPO_GATEWAY_API}:${{ github.event.release.tag_name }}"
;;
*)
echo "${GH_EVENT_NAME} not implemented yet"
exit 1
;;
esac
case "${GH_EVENT_NAME}" in
release)
VERSION_SUFFIX=""
echo "DATA_AGGREGATOR_TAGS: $DATA_AGGREGATOR_TAGS"
echo "DATABASE_MIGRATIONS_TAGS: $DATABASE_MIGRATIONS_TAGS"
echo "GATEWAY_API_TAGS: $GATEWAY_API_TAGS"
DOCKER_REPO_DATA_AGGREGATOR="radixdlt/babylon-ng-data-aggregator"
DOCKER_REPO_DATABASE_MIGRATIONS="radixdlt/babylon-ng-database-migrations"
DOCKER_REPO_GATEWAY_API="radixdlt/babylon-ng-gateway-api"
echo "::set-output name=version-tag::$DOCKER_TAG"
DATA_AGGREGATOR_TAGS="${DOCKER_REPO_DATA_AGGREGATOR}:${{ github.event.release.tag_name }}"
DATABASE_MIGRATIONS_TAGS="${DOCKER_REPO_DATABASE_MIGRATIONS}:${{ github.event.release.tag_name }}"
GATEWAY_API_TAGS="${DOCKER_REPO_GATEWAY_API}:${{ github.event.release.tag_name }}"
;;
*)
DATA_AGGREGATOR_TAGS="${DOCKER_REPO_DATA_AGGREGATOR}:${DOCKER_TAG}"
DATABASE_MIGRATIONS_TAGS="${DOCKER_REPO_DATABASE_MIGRATIONS}:${DOCKER_TAG}"
GATEWAY_API_TAGS="${DOCKER_REPO_GATEWAY_API}:${DOCKER_TAG}"
;;
esac
echo "::set-output name=data_aggregator_tags::$DATA_AGGREGATOR_TAGS"
echo "::set-output name=gateway_api_tags::$GATEWAY_API_TAGS"
echo "::set-output name=database_migrations_tags::$DATABASE_MIGRATIONS_TAGS"
echo "VERSION_SUFFIX: $VERSION_SUFFIX"
echo "DATA_AGGREGATOR_TAGS: $DATA_AGGREGATOR_TAGS"
echo "DATABASE_MIGRATIONS_TAGS: $DATABASE_MIGRATIONS_TAGS"
echo "GATEWAY_API_TAGS: $GATEWAY_API_TAGS"
echo "::set-output name=data-aggregator-tag::$DOCKER_TAG"
echo "::set-output name=database-migrations-tag::$DOCKER_TAG"
echo "::set-output name=gateway-api-tag::$DOCKER_TAG"
echo "version-suffix=$VERSION_SUFFIX" >> $GITHUB_OUTPUT
echo "version-tag=$DOCKER_TAG" >> $GITHUB_OUTPUT
else
DOCKER_REPO_DATA_AGGREGATOR="eu.gcr.io/dev-container-repo/babylon-ng-data-aggregator"
DOCKER_REPO_GATEWAY_API="eu.gcr.io/dev-container-repo/babylon-ng-gateway-api"
DOCKER_REPO_DATABASE_MIGRATIONS="eu.gcr.io/dev-container-repo/babylon-ng-database-migrations"
echo "data_aggregator_tags=$DATA_AGGREGATOR_TAGS" >> $GITHUB_OUTPUT
echo "gateway_api_tags=$GATEWAY_API_TAGS" >> $GITHUB_OUTPUT
echo "database_migrations_tags=$DATABASE_MIGRATIONS_TAGS" >> $GITHUB_OUTPUT
DATA_AGGREGATOR_TAGS="${DOCKER_REPO_DATA_AGGREGATOR}:${DOCKER_TAG}"
DATABASE_MIGRATIONS_TAGS="${DOCKER_REPO_DATABASE_MIGRATIONS}:${DOCKER_TAG}"
GATEWAY_API_TAGS="${DOCKER_REPO_GATEWAY_API}:${DOCKER_TAG}"
echo "data-aggregator-tag=$DOCKER_TAG" >> $GITHUB_OUTPUT
echo "database-migrations-tag=$DOCKER_TAG" >> $GITHUB_OUTPUT
echo "gateway-api-tag=$DOCKER_TAG" >> $GITHUB_OUTPUT
echo "DATA_AGGREGATOR_TAGS: $DATA_AGGREGATOR_TAGS"
echo "DATABASE_MIGRATIONS_TAGS: $DATABASE_MIGRATION_TAGS"
echo "GATEWAY_API_TAGS: $GATEWAY_API_TAGS"
echo "::set-output name=version-tag::$DOCKER_TAG"
echo "::set-output name=data_aggregator_tags::$DATA_AGGREGATOR_TAGS"
echo "::set-output name=database_migrations_tags::$DATABASE_MIGRATIONS_TAGS"
echo "::set-output name=gateway_api_tags::$GATEWAY_API_TAGS"
echo "::set-output name=data-aggregator-tag::$DOCKER_TAG"
echo "::set-output name=database-migrations-tag::$DOCKER_TAG"
echo "::set-output name=gateway-api-tag::$DOCKER_TAG"
fi
sed -i "s/\(<VersionSuffix>\)[^<>]*\(<\/VersionSuffix>\)/\1$VERSION_SUFFIX\2/g" Directory.Build.props
shell: bash
4 changes: 2 additions & 2 deletions .github/workflows/postman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ jobs:
steps:
- name: Set current date
id: date
run: echo "::set-output name=date::$(date +'%b %d, %H:%M')"
run: echo "date=$(date +'%b %d, %H:%M')" >> $GITHUB_OUTPUT
- name: Checkout gateway repo
uses: actions/checkout@e2f20e631ae6d7dd3b768f56a5d2af784dd54791
with:
fetch-depth: 0
- name: Set git tags
id: gittag
run: echo "::set-output name=gittag::$(git describe --tags --dirty)"
run: echo "gittag=$(git describe --tags --dirty" >> $GITHUB_OUTPUT

# ========== Mapping the network name to postman-related variables ==========
- name: Map network name to its variables
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ jobs:
- name: Build linux binaries
run: |
cd apps/DataAggregator
echo "$( jq '.+{DataAggregatorVersion:"${{ steps.get_release.outputs.tag_name }}"}' appsettings.json )" > appsettings.json
dotnet publish --runtime linux-x64 --configuration Release --self-contained false -p:PublishSingleFile=true -p:PublishReadyToRun=true -p:DebugType=None -p:DebugSymbols=false --output ./output
cd ../DatabaseMigrations
echo "$( jq '.+{DatabaseMigrationsVersion:"${{ steps.get_release.outputs.tag_name }}"}' appsettings.json )" > appsettings.json
dotnet publish --runtime linux-x64 --configuration Release --self-contained false -p:PublishSingleFile=true -p:PublishReadyToRun=true -p:DebugType=None -p:DebugSymbols=false --output ./output
cd ../GatewayApi
echo "$( jq '.+{GatewayApiVersion:"${{ steps.get_release.outputs.tag_name }}"}' appsettings.json )" > appsettings.json
dotnet publish --runtime linux-x64 --configuration Release --self-contained false -p:PublishSingleFile=true -p:PublishReadyToRun=true -p:DebugType=None -p:DebugSymbols=false --output ./output
cd ../..
zip -r data-aggregator.zip apps/DataAggregator/output/
Expand Down
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>0.1.0</VersionPrefix>
<VersionSuffix>develop</VersionSuffix>
</PropertyGroup>

<ItemGroup Condition="$(MSBuildProjectExtension) == '.csproj'">
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="all" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.OpenApi.Readers" Version="1.4.5" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.2" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.1" />
<PackageVersion Include="Polly" Version="7.2.3" />
<PackageVersion Include="prometheus-net" Version="7.0.0" />
<PackageVersion Include="prometheus-net.AspNetCore" Version="7.0.0" />
Expand All @@ -27,7 +27,7 @@

<!-- build time dependencies -->
<PackageVersion Include="coverlet.collector" Version="3.2.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageVersion Include="Moq" Version="4.18.2" />
<PackageVersion Include="FluentAssertions" Version="6.8.0" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.435" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ namespace RadixDlt.NetworkGateway.GatewayApi.Configuration;

public sealed class EndpointOptions
{
// TODO replace with <Version> in Directory.Build.Props
[ConfigurationKeyName("GatewayApiVersion")]
public string GatewayApiVersion { get; set; } = "UNKNOWN";

[ConfigurationKeyName("MaxPageSize")]
public int MaxPageSize { get; set; } = 30;

Expand All @@ -86,7 +82,6 @@ internal class EndpointOptionsValidator : AbstractOptionsValidator<EndpointOptio
{
public EndpointOptionsValidator()
{
RuleFor(x => x.GatewayApiVersion).NotNull();
RuleFor(x => x.MaxPageSize).GreaterThan(0);
RuleFor(x => x.RequestTimeout).GreaterThan(TimeSpan.Zero);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
using RadixDlt.NetworkGateway.PostgresIntegration.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
Expand All @@ -86,6 +87,7 @@ internal class LedgerStateQuerier : ILedgerStateQuerier
{
private static readonly Regex _oasVersionRegex = new("Version of the API: (\\d+\\.\\d+\\.\\d+)", RegexOptions.Compiled | RegexOptions.Multiline);

private static string _gatewayVersion = GetGatewayProductVersion();
private static string _oasVersion = GetOpenApiSchemaVersion();

private readonly ILogger<LedgerStateQuerier> _logger;
Expand Down Expand Up @@ -128,7 +130,7 @@ public LedgerStateQuerier(
ledgerStatus.TopOfLedgerTransaction.RoundInEpoch
),
new GatewayModel.GatewayInfoResponseKnownTarget(ledgerStatus.TargetStateVersion),
new GatewayModel.GatewayInfoResponseReleaseInfo(_endpointOptionsMonitor.CurrentValue.GatewayApiVersion, _oasVersion),
new GatewayModel.GatewayInfoResponseReleaseInfo(_gatewayVersion, _oasVersion),
new GatewayModel.GatewayInformationResponseAllOfWellKnownAddresses(
wellKnownAddresses.AccountPackage,
wellKnownAddresses.Faucet,
Expand Down Expand Up @@ -242,6 +244,13 @@ public async Task<long> GetTopOfLedgerStateVersion(CancellationToken token = def
return ledgerStatus.TopOfLedgerStateVersion;
}

private static string GetGatewayProductVersion()
{
var version = FileVersionInfo.GetVersionInfo(typeof(NetworkGatewayConstants).Assembly.Location).ProductVersion;

return version ?? throw new InvalidOperationException("Unable to determine product version");
}

private static string GetOpenApiSchemaVersion()
{
var match = _oasVersionRegex.Match(GatewayClient.Configuration.ToDebugReport());
Expand Down

0 comments on commit 7d7651e

Please sign in to comment.