ci.yml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. name: CI
  2. on:
  3. push:
  4. pull_request:
  5. defaults:
  6. run:
  7. # PowerShell's behavior for -flag=value is undesirable, so run all commands with bash.
  8. shell: bash
  9. jobs:
  10. test:
  11. name: Run tests
  12. strategy:
  13. matrix:
  14. os: [ubuntu, macos, windows]
  15. go-version: [1.19.x]
  16. include:
  17. # Test old supported Go version
  18. - os: ubuntu
  19. go-version: 1.18.x
  20. env:
  21. ELVISH_TEST_TIME_SCALE: 20
  22. runs-on: ${{ matrix.os }}-latest
  23. steps:
  24. # autocrlf is problematic for fuzz testdata.
  25. - name: Turn off autocrlf
  26. if: matrix.os == 'windows'
  27. run: git config --global core.autocrlf false
  28. - name: Checkout code
  29. uses: actions/checkout@v2
  30. - name: Set up cache
  31. uses: actions/cache@v2
  32. with:
  33. path: |
  34. ~/go/pkg/mod
  35. ~/.cache/go-build
  36. ~/Library/Caches/go-build
  37. ~/AppData/Local/go-build
  38. key: test/${{ matrix.os }}/${{ matrix.go-version }}/${{ hashFiles('go.sum') }}/${{ github.sha }}
  39. restore-keys: test/${{ matrix.os }}/${{ matrix.go-version }}/${{ hashFiles('go.sum') }}/
  40. - name: Set up Go
  41. uses: actions/setup-go@v2
  42. with:
  43. go-version: ${{ matrix.go-version }}
  44. - name: Test with race detection
  45. run: |
  46. go test -race ./...
  47. cd website; go test -race ./...
  48. - name: Set ostype to ${{ matrix.os }}
  49. run: echo ostype=${{ matrix.os }} >> $GITHUB_ENV
  50. - name: Set ostype to linux
  51. if: matrix.os == 'ubuntu'
  52. run: echo ostype=linux >> $GITHUB_ENV
  53. - name: Generate test coverage
  54. if: matrix.go-version == '1.19.x'
  55. run: go test -coverprofile=cover -coverpkg=./pkg/... ./pkg/...
  56. - name: Save test coverage
  57. if: matrix.go-version == '1.19.x'
  58. uses: actions/upload-artifact@v2
  59. with:
  60. name: cover-${{ env.ostype }}
  61. path: cover
  62. # The purpose of running benchmarks in GitHub Actions is primarily to ensure
  63. # that the benchmark code runs and doesn't crash. GitHub Action runners don't
  64. # have a stable enough environment to produce reliable benchmark numbers.
  65. benchmark:
  66. name: Run benchmarks
  67. runs-on: ubuntu-latest
  68. steps:
  69. - name: Checkout code
  70. uses: actions/checkout@v2
  71. - name: Set up Go
  72. uses: actions/setup-go@v2
  73. with:
  74. go-version: 1.19.x
  75. - name: Run benchmarks
  76. run: go test -bench=. -run='^$' ./...
  77. upload-coverage:
  78. name: Upload test coverage
  79. strategy:
  80. matrix:
  81. ostype: [linux, macos, windows]
  82. needs: test
  83. runs-on: ubuntu-latest
  84. steps:
  85. - name: Checkout code
  86. uses: actions/checkout@v2
  87. - name: Download test coverage
  88. uses: actions/download-artifact@v2
  89. with:
  90. name: cover-${{ matrix.ostype }}
  91. - name: Upload coverage to codecov
  92. uses: codecov/codecov-action@v1
  93. with:
  94. files: ./cover
  95. flags: ${{ matrix.ostype }}
  96. checkstyle-go:
  97. name: Check style of **.go
  98. runs-on: ubuntu-latest
  99. steps:
  100. - name: Checkout code
  101. uses: actions/checkout@v2
  102. - name: Set up Go
  103. uses: actions/setup-go@v2
  104. with:
  105. go-version: 1.19.x
  106. - name: Set up goimports
  107. run: go install golang.org/x/tools/cmd/goimports@latest
  108. - name: Check style
  109. run: ./tools/checkstyle-go.sh
  110. checkstyle-md:
  111. name: Check style of **.md
  112. runs-on: ubuntu-latest
  113. steps:
  114. - name: Checkout code
  115. uses: actions/checkout@v2
  116. - name: Set up Go
  117. uses: actions/setup-go@v2
  118. with:
  119. go-version: 1.19.x
  120. - name: Check style
  121. run: ./tools/checkstyle-md.sh
  122. codespell:
  123. name: Check spelling
  124. runs-on: ubuntu-latest
  125. steps:
  126. - name: Checkout code
  127. uses: actions/checkout@v2
  128. - name: Set up Python
  129. uses: actions/setup-python@v2
  130. - name: Install codespell
  131. run: pip install codespell==2.2.1
  132. - name: Run codespell
  133. run: codespell
  134. check-content:
  135. name: Check content
  136. runs-on: ubuntu-latest
  137. steps:
  138. - name: Checkout code
  139. uses: actions/checkout@v2
  140. - name: Run check-content.sh
  141. run: ./tools/check-content.sh
  142. check-rellinks:
  143. name: Check relative links
  144. runs-on: ubuntu-latest
  145. container:
  146. image: theelves/up
  147. # Git commands (invoked by Go when stamping VCS info) can fail
  148. # if the running user is not the same as the owner of .git
  149. # (https://github.blog/2022-04-12-git-security-vulnerability-announced/).
  150. #
  151. # The checkout action uses UID 1001, so use that for the container too.
  152. options: --user 1001
  153. defaults:
  154. run:
  155. shell: sh
  156. env:
  157. CGO_ENABLED: 0
  158. steps:
  159. - name: Checkout code
  160. uses: actions/checkout@v2
  161. - name: Check relative links
  162. run: make -C website check-rellinks
  163. lint:
  164. name: Run linters
  165. runs-on: ubuntu-latest
  166. steps:
  167. - name: Checkout code
  168. uses: actions/checkout@v2
  169. - name: Set up Go
  170. uses: actions/setup-go@v2
  171. with:
  172. go-version: 1.19.x
  173. - name: Set up staticcheck
  174. run: go install honnef.co/go/tools/cmd/staticcheck@v0.3.2
  175. - name: Run linters
  176. run: ./tools/lint.sh
  177. lsif:
  178. name: Upload SourceGraph LSIF
  179. if: github.repository == 'elves/elvish' && github.event_name == 'push'
  180. runs-on: ubuntu-latest
  181. container: sourcegraph/lsif-go:latest
  182. steps:
  183. - name: Checkout code
  184. uses: actions/checkout@v2
  185. - name: Generate LSIF data
  186. run: lsif-go
  187. - name: Upload LSIF data
  188. run: src lsif upload -github-token=${{ secrets.GITHUB_TOKEN }} -ignore-upload-failure