diff --git a/.github/workflows/nuget_slack_notifications.yml b/.github/workflows/nuget_slack_notifications.yml index f8c0b78ad..ec60d4601 100644 --- a/.github/workflows/nuget_slack_notifications.yml +++ b/.github/workflows/nuget_slack_notifications.yml @@ -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 }} @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/scripts/nugetSlackNotifications/Program.cs b/.github/workflows/scripts/nugetSlackNotifications/Program.cs index 05f21ea1e..a3f5e5dbf 100644 --- a/.github/workflows/scripts/nugetSlackNotifications/Program.cs +++ b/.github/workflows/scripts/nugetSlackNotifications/Program.cs @@ -27,6 +27,7 @@ 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"; @@ -34,6 +35,13 @@ 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); @@ -53,7 +61,7 @@ static async Task Main() { try { - await CheckPackage(package, metadataResource, sourceCacheContext); + await CheckPackage(package, metadataResource, sourceCacheContext, searchTime); } catch (Exception ex) { @@ -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; @@ -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)) { @@ -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; } } @@ -108,7 +116,7 @@ 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; } } @@ -116,12 +124,12 @@ static async Task CheckPackage(PackageInfo package, PackageMetadataResource meta 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."); } }