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