ci.yml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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.18.x]
  16. # We usually support building Elvish with Go 1.N-1 too, but since Go
  17. # 1.18 brought a lot of improvements, we dropped support for Go 1.17
  18. # when Go 1.18 is released. When Go 1.19 is released, uncomment the
  19. # stanza below to test on Go 1.18 too.
  20. #include:
  21. # # Test old supported Go version
  22. # - os: ubuntu
  23. # go-version: 1.18.x
  24. env:
  25. ELVISH_TEST_TIME_SCALE: 20
  26. runs-on: ${{ matrix.os }}-latest
  27. steps:
  28. # autocrlf is problematic for fuzz testdata.
  29. - name: Turn off autocrlf
  30. if: matrix.os == 'windows'
  31. run: git config --global core.autocrlf false
  32. - name: Checkout code
  33. uses: actions/checkout@v2
  34. - name: Set up cache
  35. uses: actions/cache@v2
  36. with:
  37. path: |
  38. ~/go/pkg/mod
  39. ~/.cache/go-build
  40. ~/Library/Caches/go-build
  41. ~/AppData/Local/go-build
  42. key: test/${{ matrix.os }}/${{ matrix.go-version }}/${{ hashFiles('go.sum') }}/${{ github.sha }}
  43. restore-keys: test/${{ matrix.os }}/${{ matrix.go-version }}/${{ hashFiles('go.sum') }}/
  44. - name: Set up Go
  45. uses: actions/setup-go@v2
  46. with:
  47. go-version: ${{ matrix.go-version }}
  48. - name: Test with race detection
  49. run: |
  50. go test -race ./...
  51. cd website; go test -race ./...
  52. - name: Set ostype to ${{ matrix.os }}
  53. run: echo ostype=${{ matrix.os }} >> $GITHUB_ENV
  54. - name: Set ostype to linux
  55. if: matrix.os == 'ubuntu'
  56. run: echo ostype=linux >> $GITHUB_ENV
  57. - name: Generate test coverage
  58. if: matrix.go-version == '1.18.x'
  59. run: go test -coverprofile=cover -coverpkg=./pkg/... ./pkg/...
  60. - name: Save test coverage
  61. if: matrix.go-version == '1.18.x'
  62. uses: actions/upload-artifact@v2
  63. with:
  64. name: cover-${{ env.ostype }}
  65. path: cover
  66. # The purpose of running benchmarks in GitHub Actions is primarily to ensure
  67. # that the benchmark code runs and doesn't crash. GitHub Action runners don't
  68. # have a stable enough environment to produce reliable benchmark numbers.
  69. benchmark:
  70. name: Run benchmarks
  71. runs-on: ubuntu-latest
  72. steps:
  73. - name: Checkout code
  74. uses: actions/checkout@v2
  75. - name: Set up Go
  76. uses: actions/setup-go@v2
  77. with:
  78. go-version: 1.18.x
  79. - name: Run benchmarks
  80. run: go test -bench=. -run='^$' ./...
  81. upload-coverage:
  82. name: Upload test coverage
  83. strategy:
  84. matrix:
  85. ostype: [linux, macos, windows]
  86. needs: test
  87. runs-on: ubuntu-latest
  88. steps:
  89. - name: Checkout code
  90. uses: actions/checkout@v2
  91. - name: Download test coverage
  92. uses: actions/download-artifact@v2
  93. with:
  94. name: cover-${{ matrix.ostype }}
  95. - name: Upload coverage to codecov
  96. uses: codecov/codecov-action@v1
  97. with:
  98. files: ./cover
  99. flags: ${{ matrix.ostype }}
  100. buildall:
  101. name: Build binaries
  102. runs-on: ubuntu-latest
  103. steps:
  104. - name: Checkout code
  105. uses: actions/checkout@v2
  106. - name: Set up cache
  107. uses: actions/cache@v2
  108. with:
  109. path: |
  110. ~/go/pkg/mod
  111. ~/.cache/go-build
  112. key: buildall/${{ matrix.os }}/1.18.x/${{ hashFiles('go.sum') }}/${{ github.sha }}
  113. restore-keys: buildall/${{ matrix.os }}/1.18.x/${{ hashFiles('go.sum') }}
  114. - name: Set up Go
  115. uses: actions/setup-go@v2
  116. with:
  117. go-version: 1.18.x
  118. - name: Build binaries
  119. # TODO: Use PR number for suffix when running for PR
  120. run: ELVISH_REPRODUCIBLE=dev ./tools/buildall.sh . bin HEAD
  121. - name: Upload binaries
  122. uses: actions/upload-artifact@v2
  123. with:
  124. name: bin
  125. path: bin/**/*
  126. checkstyle-go:
  127. name: Check style of **.go
  128. runs-on: ubuntu-latest
  129. steps:
  130. - name: Checkout code
  131. uses: actions/checkout@v2
  132. - name: Set up Go
  133. uses: actions/setup-go@v2
  134. with:
  135. go-version: 1.18.x
  136. - name: Set up goimports
  137. run: go install golang.org/x/tools/cmd/goimports@latest
  138. - name: Check style
  139. run: ./tools/checkstyle-go.sh
  140. checkstyle-md:
  141. name: Check style of **.md
  142. runs-on: ubuntu-latest
  143. steps:
  144. - name: Checkout code
  145. uses: actions/checkout@v2
  146. - name: Set up environment
  147. run: |
  148. echo "NPM_PREFIX=$HOME/npm" >> $GITHUB_ENV
  149. echo "PATH=$HOME/npm/bin:$PATH" >> $GITHUB_ENV
  150. - name: Set up Node
  151. uses: actions/setup-node@v2
  152. - name: Set up Node prefix
  153. run: npm config set prefix $NPM_PREFIX
  154. - name: Set up prettier
  155. run: npm install --global prettier@2.3.1
  156. - name: Check style
  157. run: ./tools/checkstyle-md.sh
  158. codespell:
  159. name: Check spelling
  160. runs-on: ubuntu-latest
  161. steps:
  162. - name: Checkout code
  163. uses: actions/checkout@v2
  164. - name: Set up Python
  165. uses: actions/setup-python@v2
  166. - name: Install codespell
  167. run: pip install codespell==2.1.0
  168. - name: Run codespell
  169. run: codespell
  170. check-content:
  171. name: Check content
  172. runs-on: ubuntu-latest
  173. steps:
  174. - name: Checkout code
  175. uses: actions/checkout@v2
  176. - name: Run check-content.sh
  177. run: ./tools/check-content.sh
  178. check-rellinks:
  179. name: Check relative links
  180. runs-on: ubuntu-latest
  181. container:
  182. image: theelves/up
  183. options: --user 0
  184. defaults:
  185. run:
  186. shell: sh
  187. env:
  188. CGO_ENABLED: 0
  189. steps:
  190. - name: Checkout code
  191. uses: actions/checkout@v2
  192. - name: Check relative links
  193. run: make -C website check-rellinks
  194. lint:
  195. name: Run linters
  196. runs-on: ubuntu-latest
  197. steps:
  198. - name: Checkout code
  199. uses: actions/checkout@v2
  200. - name: Set up Go
  201. uses: actions/setup-go@v2
  202. with:
  203. go-version: 1.18.x
  204. - name: Set up staticcheck
  205. run: go install honnef.co/go/tools/cmd/staticcheck@master
  206. - name: Run linters
  207. run: ./tools/lint.sh
  208. lsif:
  209. name: Upload SourceGraph LSIF
  210. if: github.repository == 'elves/elvish' && github.event_name == 'push'
  211. runs-on: ubuntu-latest
  212. container: sourcegraph/lsif-go:latest
  213. steps:
  214. - name: Checkout code
  215. uses: actions/checkout@v2
  216. - name: Generate LSIF data
  217. run: lsif-go
  218. - name: Upload LSIF data
  219. run: src lsif upload -github-token=${{ secrets.GITHUB_TOKEN }} -ignore-upload-failure