RunScripts #195
This file contains 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: RunScripts | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 1 * * 1-5' # 1am UTC every weekday | |
env: | |
DOTNET_NOLOGO: true | |
DOTNET_ROLL_FORWARD: Major | |
jobs: | |
run-scripts: | |
name: Run scripts | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Checkout ServicePulse | |
uses: actions/checkout@v4 | |
with: | |
repository: Particular/ServicePulse | |
path: checkout/ServicePulse | |
- name: Checkout ServiceControl | |
uses: actions/checkout@v4 | |
with: | |
repository: Particular/ServiceControl | |
path: checkout/ServiceControl | |
- name: Set environment vars | |
run: | | |
git config user.email "85681268+internalautomation[bot]@users.noreply.github.com" | |
git config user.name "internalautomation[bot]" | |
- uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 9.0.x | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Update Core Dependencies | |
run: | | |
(cd tools/coreDependencies && dotnet run --project coreDependencies.csproj) | |
- name: Update 3rd-Party Licenses | |
run: | | |
(cd tools/3rd-party-licenses && dotnet run --project 3rd-party-licenses.csproj) | |
- name: Commit changes | |
shell: pwsh | |
run: | | |
git diff > ../changes.diff | |
$changes = Get-Item ../changes.diff | |
Write-Output "Diff size is $($changes.Length) bytes" | |
if ($changes.Length -gt 20480) { | |
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "## Changes diff" | |
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "``````" | |
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value $changes | |
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "``````" | |
throw "Changes diff is > 20KB - too much change to trust without verifying" | |
return 1 | |
} | |
if ($changes.Length -eq 0) { | |
Write-Output "No changes to commit" | |
return 0 | |
} | |
Write-Output "Staging changes" | |
git add --all | |
Write-Output "Committing changes" | |
git commit -m "Updates from running scripts in the 'tools' directory" | |
Write-Output "Pushing changes to origin" | |
git push origin master | |
- name: Notify Slack on failure | |
if: ${{ failure() }} | |
shell: pwsh | |
run: | | |
$headers = @{ | |
'Authorization' = "Bearer ${{ secrets.SLACK_TOKEN }}" | |
} | |
$body = @{ | |
channel = 'docs' | |
text = "Failed to run scripts in Docs repo: https://github.com/Particular/docs.particular.net/actions/workflows/run-scripts.yml?query=branch%3Amaster" | |
username = 'Run Scripts' | |
icon_emoji = 'github_actions' | |
unfurl_links = false | |
unfurl_media = 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 | |
Write-Output $result | |
exit $(If ($result.ok) { 0 } Else { 1 }) |