pr_push_checks_go.yaml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. name: Go PR Checks
  2. on:
  3. - pull_request
  4. concurrency:
  5. group: pr-go-${{ github.event.pull_request.number || github.ref }}
  6. cancel-in-progress: true
  7. jobs:
  8. cache:
  9. name: Setup cache
  10. runs-on: ubuntu-latest
  11. outputs:
  12. go-changes: ${{ steps.changed-files.outputs.any_changed }}
  13. steps:
  14. - name: Checkout code
  15. uses: actions/checkout@v4
  16. with:
  17. fetch-depth: 0
  18. - name: Get changed go files
  19. id: changed-files
  20. uses: tj-actions/changed-files@v35
  21. with:
  22. files: |
  23. *.go
  24. *.mod
  25. *.sum
  26. **/*.go
  27. **/*.mod
  28. **/*.sum
  29. - name: List all changed files
  30. run: |
  31. for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
  32. echo "$file was changed"
  33. done
  34. - name: Setup Go Cache
  35. uses: actions/cache@v3
  36. if: steps.changed-files.outputs.any_changed == 'true'
  37. with:
  38. path: |
  39. ~/.cache/go-build
  40. ~/go/pkg/mod
  41. key: porter-go-${{ hashFiles('**/go.sum') }}
  42. restore-keys: porter-go-
  43. - uses: actions/setup-go@v4
  44. if: steps.changed-files.outputs.any_changed == 'true'
  45. with:
  46. cache: false
  47. go-version-file: go.mod
  48. - name: Download Go Modules
  49. if: steps.changed-files.outputs.any_changed == 'true'
  50. run: go mod download
  51. testing_matrix:
  52. name: Running Go Tests
  53. runs-on: ${{ matrix.os }}
  54. needs: cache
  55. strategy:
  56. matrix:
  57. os: [ubuntu-latest]
  58. folder: [cli, api, cmd, internal, provisioner]
  59. steps:
  60. - uses: actions/checkout@v3
  61. - name: Setup Go Cache
  62. uses: actions/cache/restore@v3
  63. if: needs.cache.outputs.go-changes == 'true'
  64. with:
  65. path: |
  66. ~/.cache/go-build
  67. ~/go/pkg/mod
  68. key: porter-go-${{ hashFiles('**/go.sum') }}
  69. - uses: actions/setup-go@v4
  70. if: needs.cache.outputs.go-changes == 'true'
  71. with:
  72. cache: false
  73. go-version-file: go.mod
  74. - name: Download Go Modules
  75. if: needs.cache.outputs.go-changes == 'true'
  76. run: go mod download
  77. - name: Run Go tests
  78. if: needs.cache.outputs.go-changes == 'true'
  79. run: go test ./${{ matrix.folder }}/...
  80. linting:
  81. name: Go Linter
  82. runs-on: ubuntu-latest
  83. needs: cache
  84. steps:
  85. - uses: actions/checkout@v3
  86. - name: Setup Go Cache
  87. uses: actions/cache/restore@v3
  88. if: needs.cache.outputs.go-changes == 'true'
  89. with:
  90. path: |
  91. ~/.cache/go-build
  92. ~/go/pkg/mod
  93. key: porter-go-${{ hashFiles('**/go.sum') }}
  94. - uses: actions/setup-go@v4
  95. if: needs.cache.outputs.go-changes == 'true'
  96. with:
  97. cache: false
  98. go-version-file: go.mod
  99. - name: golangci-lint
  100. uses: golangci/golangci-lint-action@v3
  101. if: needs.cache.outputs.go-changes == 'true'
  102. with:
  103. version: latest
  104. args: -c .github/golangci-lint.yaml --verbose
  105. skip-pkg-cache: true
  106. only-new-issues: true # this is needed until the following is merged: https://github.com/golangci/golangci-lint-action/issues/820