runtime-sync.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. name: AspNetCore-Runtime Code Sync
  2. on:
  3. # Test this script using on: push
  4. # push
  5. schedule:
  6. # * is a special character in YAML so you have to quote this string
  7. # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#scheduled-events-schedule
  8. # Once per day at midnight PST (8 UTC)
  9. - cron: '0 8 * * *'
  10. jobs:
  11. compare_repos:
  12. name: Compare the shared code in the AspNetCore and Runtime repos and notify if they're out of sync.
  13. runs-on: windows-latest
  14. steps:
  15. - name: Checkout aspnetcore
  16. uses: actions/[email protected]
  17. with:
  18. # Test this script using changes in a fork
  19. # repository: 'Tratcher/aspnetcore'
  20. repository: 'dotnet/aspnetcore'
  21. path: aspnetcore
  22. - name: Checkout runtime
  23. uses: actions/[email protected]
  24. with:
  25. # Test this script using changes in a fork
  26. # repository: 'Tratcher/runtime'
  27. repository: 'dotnet/runtime'
  28. path: runtime
  29. - name: Copy
  30. shell: cmd
  31. working-directory: .\runtime\src\libraries\Common\src\System\Net\Http\aspnetcore\
  32. env:
  33. ASPNETCORE_REPO: d:\a\aspnetcore\aspnetcore\aspnetcore\
  34. run: |
  35. dir
  36. CopyToAspNetCore.cmd
  37. - name: Diff
  38. shell: cmd
  39. working-directory: .\aspnetcore\
  40. run: |
  41. mkdir ..\artifacts
  42. git status > ..\artifacts\status.txt
  43. git diff > ..\artifacts\diff.txt
  44. - uses: actions/upload-artifact@v1
  45. with:
  46. name: results
  47. path: artifacts
  48. - name: Check and Notify
  49. shell: pwsh
  50. env:
  51. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  52. run: |
  53. # Check the code is in sync
  54. $changed = (select-string "nothing to commit" artifacts\status.txt).count -eq 0
  55. if (-not $changed) { exit }
  56. # Test this script using an issue in the local forked repo
  57. # $issue = 'https://api.github.com/repos/Tratcher/aspnetcore/issues/1'
  58. $issue = 'https://api.github.com/repos/dotnet/aspnetcore/issues/18943'
  59. # Check if tracking issue is open/closed
  60. $Headers = @{ Authorization = 'token {0}' -f $ENV:GITHUB_TOKEN; };
  61. $result = Invoke-RestMethod -Uri $issue
  62. if ($result.state -eq "closed") {
  63. $json = "{ `"state`": `"open`" }"
  64. $result = Invoke-RestMethod -Method PATCH -Headers $Headers -Uri $issue -Body $json
  65. }
  66. # Add a comment
  67. $status = [IO.File]::ReadAllText("artifacts\status.txt")
  68. $diff = [IO.File]::ReadAllText("artifacts\diff.txt")
  69. $body = @"
  70. The shared code is out of sync.
  71. <details>
  72. <summary>The Diff</summary>
  73. ``````
  74. $status
  75. $diff
  76. ``````
  77. </details>
  78. "@
  79. $json = ConvertTo-Json -InputObject @{ 'body' = $body }
  80. $issue = $issue + '/comments'
  81. $result = Invoke-RestMethod -Method POST -Headers $Headers -Uri $issue -Body $json