Check Platform Sample Dependencies #4155
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check Platform Sample Dependencies | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 * * * 1-5' # Hourly, Monday-Friday | |
defaults: | |
run: | |
shell: pwsh | |
env: | |
GH_TOKEN: ${{ github.token }} | |
jobs: | |
check: | |
name: Check dependencies | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout required for GitHub CLI to work | |
- name: Checkout | |
uses: actions/checkout@v5.0.0 | |
- name: Download deployed dependencies | |
run: | | |
# Compare deployed dependencies to NuGet versions and invoke release if mismatch exists | |
$url = "https://s3.amazonaws.com/particular.downloads/MonitoringDemo/Particular.MonitoringDemo.dependencies.json" | |
echo "Getting currently-deployed dependencies from $url" | |
$current = (Invoke-WebRequest $url).Content | ConvertFrom-Json | |
echo $current | ConvertTo-Json | |
echo "Getting most recent versions from NuGet API" | |
$nugetMeta = (Invoke-WebRequest "https://api.nuget.org/v3/index.json").Content | ConvertFrom-Json | |
$nugetBaseUrl = ($nugetMeta.resources | Where-Object -Property '@type' -eq 'RegistrationsBaseUrl/Versioned')[0].'@id' | |
$platformSample = (Invoke-WebRequest "$($nugetBaseUrl)particular.platformsample/index.json").Content | ConvertFrom-Json | |
$latestPlatformSampleVersion = ($platformSample.items | select -Last 1).upper | |
echo "Most recent Particular.PlatformSample version is $latestPlatformSampleVersion" | |
if ($current.PlatformSample -eq $latestPlatformSampleVersion) { | |
echo "PlatformSample package is up-to-date, nothing to do" | |
exit 0 | |
} | |
echo "PlatformSample version does not match, updates are needed" | |
echo "First notify Slack" | |
$headers = @{ 'Authorization' = "Bearer ${{ secrets.SLACK_TOKEN }}" } | |
$body = @{ | |
channel = 'pulse-and-control' | |
text = "Attempting to auto-update MonitoringDemo due to changes detected in PlatformSample packages: https://github.com/Particular/MonitoringDemo/actions/runs/${{ github.run_id }}" | |
username = 'MonitoringDemo UpdateBot' | |
icon_emoji = 'rocket' | |
unfurl_links = false | |
} | ConvertTo-Json | |
$result = Invoke-RestMethod -Method POST -Uri https://slack.com/api/chat.postMessage -ContentType "application/json; charset=utf-8" -Headers $headers -Body $body | |
echo "Invoking release workflow" | |
gh workflow run release.yml | |
- name: Notify Slack on failure | |
if: ${{ failure() }} | |
shell: pwsh | |
run: | | |
$headers = @{ 'Authorization' = "Bearer ${{ secrets.SLACK_TOKEN }}" } | |
$body = @{ | |
channel = 'pulse-and-control' | |
text = "Failure in MonitoringDemo auto-update workflow: https://github.com/Particular/MonitoringDemo/actions/runs/${{ github.run_id }}" | |
username = 'MonitoringDemo UpdateBot' | |
icon_emoji = 'warning' | |
unfurl_links = false | |
} | ConvertTo-Json | |
$result = Invoke-RestMethod -Method POST -Uri https://slack.com/api/chat.postMessage -ContentType "application/json; charset=utf-8" -Headers $headers -Body $body | |
exit $(If ($result.ok) { 0 } Else { 1 }) |