pr-auto-fix.yaml 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. name: PR AutoFix
  2. on: [push]
  3. jobs:
  4. PRAutoFix:
  5. runs-on: ubuntu-latest
  6. steps:
  7. # Cache bazel build
  8. - name: Get current time
  9. uses: srfrnk/current-time@master
  10. id: current-time
  11. with:
  12. format: YYYYWW
  13. - name: Cache bazel
  14. uses: actions/cache@v2
  15. env:
  16. cache-name: bazel-cache
  17. with:
  18. path: ~/.cache/bazel
  19. # formattedTime here is like 202132 - the year concatenated with the week
  20. # as this changes every week, we cycle to a new cache once per week.
  21. key: ${{ runner.os }}-${{ steps.current-time.outputs.formattedTime }}
  22. # Cancel current runs if they're still running
  23. # (saves processing on fast pushes)
  24. - name: Cancel Previous Runs
  25. uses: styfle/cancel-workflow-action@0.9.1
  26. with:
  27. access_token: ${{ github.token }}
  28. # Allow opt-out for some users
  29. - name: Should I Stay Or Should I Go
  30. uses: actions/github-script@v4
  31. id: check
  32. with:
  33. script: |
  34. // If you'd like not to run this code on your commits, add your github user id here:
  35. NO_AUTOFIX_USERS = []
  36. const { owner, repo } = context.repo
  37. if (NO_AUTOFIX_USERS.includes(context.actor)) {
  38. console.log('Cancelling');
  39. const run_id = "${{ github.run_id }}";
  40. await github.actions.cancelWorkflowRun({ owner, repo, run_id });
  41. return 'go';
  42. } else {
  43. return 'stay';
  44. }
  45. - name: Wait for cancellation
  46. run: sleep 60
  47. if: steps.check.outputs.result == 'go'
  48. - name: Should build?
  49. run: test "${{ steps.check.outputs.result }}" = "stay"
  50. # Setup to run sanity suite
  51. - name: Install Python Interpreter
  52. uses: actions/setup-python@v2
  53. with:
  54. python-version: 3.8
  55. - name: Install Python Packages
  56. run: |
  57. python -m pip install --upgrade pip
  58. pip install pyyaml mako virtualenv
  59. sudo apt-get install python-dev
  60. - name: Check out repository code
  61. uses: actions/checkout@v2
  62. with:
  63. submodules: True
  64. fetch-depth: 0
  65. # Run the things!
  66. - name: clang-tidy fixes
  67. run: ${{ github.workspace }}/tools/distrib/clang_tidy_code.sh --fix --only-changed || true
  68. - name: Run sanitize
  69. run: ${{ github.workspace }}/tools/distrib/sanitize.sh
  70. # Report back with a PR if things are broken
  71. - name: Create Pull Request
  72. uses: peter-evans/create-pull-request@v3
  73. with:
  74. delete-branch: true
  75. branch-suffix: short-commit-hash
  76. commit-message: "Automated change: Fix sanity tests"
  77. title: Automated fix for ${{ github.ref }}
  78. body: |
  79. PanCakes to the rescue!
  80. We noticed that our 'sanity' test was going to fail, but we think we can fix that automatically, so we put together this PR to do just that!
  81. If you'd like to opt-out of these PR's, add yourself to NO_AUTOFIX_USERS in .github/workflows/pr-auto-fix.yaml