Skip to content

Commit

Permalink
Updates workflow to find the previous successful run date and search …
Browse files Browse the repository at this point in the history
…from then, falling back to 1 day if not found
  • Loading branch information
tippmar-nr committed Jul 11, 2024
1 parent 2a21bdb commit 6e7a336
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
28 changes: 17 additions & 11 deletions .github/workflows/nuget_slack_notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,24 @@ jobs:
dotnet add nugetSlackNotifications.csproj package NewRelic.Agent
dotnet publish -o ${{ env.scan-tool-publish-path }}
- name: Find timestamp of most recent run of this workflow and set as an environment variable
run: |
echo "LAST_RUN_TIMESTAMP=$(gh run list --workflow nuget_slack_notifications.yml --branch main --status completed --limit 1 --json updatedAt | jq -r '.[0].updatedAt')" >> $GITHUB_ENV
shell: bash

- name: Check for updates to core technology packages
env:
DOTTY_WEBHOOK: ${{ secrets.SLACK_NUGET_NOTIFICATIONS_WEBHOOK }}
DOTTY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CORECLR_ENABLE_PROFILING: 1
CORECLR_NEWRELIC_HOME: ${{ env.scan-tool-publish-path }}/newrelic
CORECLR_PROFILER: "{36032161-FFC0-4B61-B559-F6C5D41BAE5A}"
CORECLR_PROFILER_PATH: ${{ env.scan-tool-publish-path }}/newrelic/libNewRelicProfiler.so
NEW_RELIC_APP_NAME: Dotty
NEW_RELIC_HOST: staging-collector.newrelic.com
NEW_RELIC_LICENSE_KEY: ${{ secrets.STAGING_LICENSE_KEY }}
DOTTY_LAST_RUN_TIMESTAMP: ${{ env.LAST_RUN_TIMESTAMP }}

run: |
if [ ${{ inputs.daysToSearch }} != "" ]; then
export DOTTY_DAYS_TO_SEARCH=${{ inputs.daysToSearch }}
Expand All @@ -60,15 +77,4 @@ jobs:
cd ${{ env.scan-tool-publish-path }}
dotnet ./nugetSlackNotifications.dll ${{ env.nugets }}
shell: bash

env:
DOTTY_WEBHOOK: ${{ secrets.SLACK_NUGET_NOTIFICATIONS_WEBHOOK }}
DOTTY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CORECLR_ENABLE_PROFILING: 1
CORECLR_NEWRELIC_HOME: ${{ env.scan-tool-publish-path }}/newrelic
CORECLR_PROFILER: "{36032161-FFC0-4B61-B559-F6C5D41BAE5A}"
CORECLR_PROFILER_PATH: ${{ env.scan-tool-publish-path }}/newrelic/libNewRelicProfiler.so
NEW_RELIC_APP_NAME: Dotty
NEW_RELIC_HOST: staging-collector.newrelic.com
NEW_RELIC_LICENSE_KEY: ${{ secrets.STAGING_LICENSE_KEY }}

24 changes: 16 additions & 8 deletions .github/workflows/scripts/nugetSlackNotifications/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ public class Program
private static readonly bool _testMode = bool.TryParse(Environment.GetEnvironmentVariable("DOTTY_TEST_MODE"), out var testMode) ? testMode : false;
private static readonly string _webhook = Environment.GetEnvironmentVariable("DOTTY_WEBHOOK");
private static readonly string _githubToken = Environment.GetEnvironmentVariable("DOTTY_TOKEN");
private static readonly DateTimeOffset _lastRunTimestamp = DateTimeOffset.TryParse(Environment.GetEnvironmentVariable("DOTTY_LAST_RUN_TIMESTAMP"), out var timestamp) ? timestamp : DateTimeOffset.MinValue;
private const string PackageInfoFilename = "packageInfo.json";


static async Task Main()
{
Log.Logger = new LoggerConfiguration().WriteTo.Console().CreateLogger();

// searchTime is the date to search for package updates from.
// If _lastRunTimestamp is not set, search from _daysToSearch days ago.
// Otherwise, search from _lastRunTimestamp.
var searchTime = _lastRunTimestamp == DateTimeOffset.MinValue ? DateTimeOffset.UtcNow.Date.AddDays(-_daysToSearch) : _lastRunTimestamp;

Log.Information($"Searching for package updates between {searchTime.ToUniversalTime():s}Z and {DateTimeOffset.UtcNow.ToUniversalTime():s}Z.");

// initialize nuget repo
var ps = new PackageSource("https://api.nuget.org/v3/index.json");
var sourceRepository = Repository.Factory.GetCoreV3(ps);
Expand All @@ -53,7 +61,7 @@ static async Task Main()
{
try
{
await CheckPackage(package, metadataResource, sourceCacheContext);
await CheckPackage(package, metadataResource, sourceCacheContext, searchTime);
}
catch (Exception ex)
{
Expand All @@ -67,7 +75,7 @@ static async Task Main()
}

[Transaction]
static async Task CheckPackage(PackageInfo package, PackageMetadataResource metadataResource, SourceCacheContext sourceCacheContext)
static async Task CheckPackage(PackageInfo package, PackageMetadataResource metadataResource, SourceCacheContext sourceCacheContext, DateTimeOffset searchTime)
{
var packageName = package.PackageName;

Expand All @@ -86,8 +94,8 @@ static async Task CheckPackage(PackageInfo package, PackageMetadataResource meta
// get the second most recent version of the package (if there is one)
var previous = metaData.Skip(1).FirstOrDefault();

// see if it was published within the last _daysToSearch days
if (latest.Published.Value.Date.Date >= DateTime.Today.AddDays(-_daysToSearch))
// check publish date
if (latest.Published >= searchTime)
{
if (previous != null && (package.IgnorePatch || package.IgnoreMinor))
{
Expand All @@ -98,7 +106,7 @@ static async Task CheckPackage(PackageInfo package, PackageMetadataResource meta
{
if (previousVersion.Major == latestVersion.Major && previousVersion.Minor == latestVersion.Minor)
{
Log.Information($"Package {packageName} ignores Patch version updates; the Minor version ({latestVersion.Major}.{latestVersion.Minor:2}) has not been updated in the past {_daysToSearch} days.");
Log.Information($"Package {packageName} ignores Patch version updates; the Minor version ({latestVersion.Major}.{latestVersion.Minor:2}) has not been updated since {searchTime.ToUniversalTime():s}Z.");
return;
}
}
Expand All @@ -108,20 +116,20 @@ static async Task CheckPackage(PackageInfo package, PackageMetadataResource meta

if (previousVersion.Major == latestVersion.Major)
{
Log.Information($"Package {packageName} ignores Minor version updates; the Major version ({latestVersion.Major}) has not been updated in the past {_daysToSearch} days.");
Log.Information($"Package {packageName} ignores Minor version updates; the Major version ({latestVersion.Major}) has not been updated since {searchTime.ToUniversalTime():s}Z");
return;
}
}
}

var previousVersionDescription = previous?.Identity.Version.ToNormalizedString() ?? "Unknown";
var latestVersionDescription = latest.Identity.Version.ToNormalizedString();
Log.Information($"Package {packageName} was updated from {previousVersionDescription} to {latestVersionDescription} on {latest.Published.Value.Date.ToShortDateString()}.");
Log.Information($"Package {packageName} was updated from {previousVersionDescription} to {latestVersionDescription} at {latest.Published:s}Z.");
_newVersions.Add(new NugetVersionData(packageName, previousVersionDescription, latestVersionDescription, latest.PackageDetailsUrl.ToString(), latest.Published.Value.Date));
}
else
{
Log.Information($"Package {packageName} has NOT been updated in the past {_daysToSearch} days.");
Log.Information($"Package {packageName} has NOT been updated since {searchTime.ToUniversalTime():s}Z.");
}
}

Expand Down

0 comments on commit 6e7a336

Please sign in to comment.