ci.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 environment
  117. run: |
  118. echo "NPM_PREFIX=$HOME/npm" >> $GITHUB_ENV
  119. echo "PATH=$HOME/npm/bin:$PATH" >> $GITHUB_ENV
  120. - name: Set up Node
  121. uses: actions/setup-node@v2
  122. - name: Set up Node prefix
  123. run: npm config set prefix $NPM_PREFIX
  124. - name: Set up prettier
  125. run: npm install --global prettier@2.7.1
  126. - name: Check style
  127. run: ./tools/checkstyle-md.sh
  128. codespell:
  129. name: Check spelling
  130. runs-on: ubuntu-latest
  131. steps:
  132. - name: Checkout code
  133. uses: actions/checkout@v2
  134. - name: Set up Python
  135. uses: actions/setup-python@v2
  136. - name: Install codespell
  137. run: pip install codespell==2.2.1
  138. - name: Run codespell
  139. run: codespell
  140. check-content:
  141. name: Check content
  142. runs-on: ubuntu-latest
  143. steps:
  144. - name: Checkout code
  145. uses: actions/checkout@v2
  146. - name: Run check-content.sh
  147. run: ./tools/check-content.sh
  148. check-rellinks:
  149. name: Check relative links
  150. runs-on: ubuntu-latest
  151. container:
  152. image: theelves/up
  153. # Git commands (invoked by Go when stamping VCS info) can fail
  154. # if the running user is not the same as the owner of .git
  155. # (https://github.blog/2022-04-12-git-security-vulnerability-announced/).
  156. #
  157. # The checkout action uses UID 1001, so use that for the container too.
  158. options: --user 1001
  159. defaults:
  160. run:
  161. shell: sh
  162. env:
  163. CGO_ENABLED: 0
  164. steps:
  165. - name: Checkout code
  166. uses: actions/checkout@v2
  167. - name: Check relative links
  168. run: make -C website check-rellinks
  169. lint:
  170. name: Run linters
  171. runs-on: ubuntu-latest
  172. steps:
  173. - name: Checkout code
  174. uses: actions/checkout@v2
  175. - name: Set up Go
  176. uses: actions/setup-go@v2
  177. with:
  178. go-version: 1.19.x
  179. - name: Set up staticcheck
  180. run: go install honnef.co/go/tools/cmd/staticcheck@v0.3.2
  181. - name: Run linters
  182. run: ./tools/lint.sh
  183. lsif:
  184. name: Upload SourceGraph LSIF
  185. if: github.repository == 'elves/elvish' && github.event_name == 'push'
  186. runs-on: ubuntu-latest
  187. container: sourcegraph/lsif-go:latest
  188. steps:
  189. - name: Checkout code
  190. uses: actions/checkout@v2
  191. - name: Generate LSIF data
  192. run: lsif-go
  193. - name: Upload LSIF data
  194. run: src lsif upload -github-token=${{ secrets.GITHUB_TOKEN }} -ignore-upload-failure