ci.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. name: CI
  2. on:
  3. pull_request:
  4. push:
  5. branches:
  6. - main
  7. - master
  8. - "releases/*"
  9. permissions:
  10. contents: read
  11. env:
  12. CI: true
  13. TZ: Asia/Shanghai
  14. jobs:
  15. test:
  16. name: Test
  17. if: github.actor != 'dependabot[bot]' && !contains(github.event.head_commit.message, '[skip ci]')
  18. runs-on: ${{ matrix.os }}
  19. strategy:
  20. matrix:
  21. node-version: [20]
  22. os:
  23. - ubuntu-latest
  24. # - macos-latest
  25. # - windows-latest
  26. timeout-minutes: 20
  27. steps:
  28. - name: Checkout code
  29. uses: actions/checkout@v4
  30. with:
  31. fetch-depth: 0
  32. - name: Install pnpm
  33. uses: pnpm/action-setup@v4
  34. with:
  35. run_install: false
  36. - name: Use Node.js ${{ matrix.node-version }}
  37. uses: actions/setup-node@v4
  38. with:
  39. node-version: ${{ matrix.node-version }}
  40. cache: "pnpm"
  41. - name: Find pnpm store path
  42. shell: bash
  43. run: |
  44. echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
  45. - name: Setup pnpm cache
  46. uses: actions/cache@v4
  47. with:
  48. path: ${{ env.STORE_PATH }}
  49. key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
  50. restore-keys: |
  51. ${{ runner.os }}-pnpm-store-
  52. - name: Install dependencies
  53. run: pnpm install --frozen-lockfile
  54. # - name: Check Git version
  55. # run: git --version
  56. # - name: Setup mock Git user
  57. # run: git config --global user.email "you@example.com" && git config --global user.name "Your Name"
  58. - name: Vitest tests
  59. run: pnpm run test:unit
  60. # - name: Upload coverage
  61. # uses: codecov/codecov-action@v4
  62. # with:
  63. # token: ${{ secrets.CODECOV_TOKEN }}
  64. lint:
  65. name: Lint
  66. if: github.actor != 'dependabot[bot]' && !contains(github.event.head_commit.message, '[skip ci]')
  67. runs-on: ${{ matrix.os }}
  68. strategy:
  69. matrix:
  70. node-version: [20]
  71. os:
  72. - ubuntu-latest
  73. # - macos-latest
  74. # - windows-latest
  75. steps:
  76. - name: Checkout code
  77. uses: actions/checkout@v4
  78. with:
  79. fetch-depth: 0
  80. - name: Install pnpm
  81. uses: pnpm/action-setup@v4
  82. - name: Use Node.js ${{ matrix.node-version }}
  83. uses: actions/setup-node@v4
  84. with:
  85. node-version: ${{ matrix.node-version }}
  86. cache: "pnpm"
  87. - name: Install dependencies
  88. run: pnpm install --frozen-lockfile
  89. - name: Lint
  90. run: pnpm run lint
  91. check:
  92. name: Check
  93. runs-on: ubuntu-latest
  94. timeout-minutes: 20
  95. strategy:
  96. matrix:
  97. node-version: [20]
  98. steps:
  99. - name: Checkout code
  100. uses: actions/checkout@v4
  101. with:
  102. fetch-depth: 0
  103. - name: Install pnpm
  104. uses: pnpm/action-setup@v4
  105. - name: Use Node.js ${{ matrix.node-version }}
  106. uses: actions/setup-node@v4
  107. with:
  108. node-version: ${{ matrix.node-version }}
  109. cache: "pnpm"
  110. - name: Install dependencies
  111. run: pnpm install --frozen-lockfile
  112. - name: Typecheck
  113. run: pnpm check:type
  114. # From https://github.com/rhysd/actionlint/blob/main/docs/usage.md#use-actionlint-on-github-actions
  115. - name: Check workflow files
  116. run: |
  117. bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
  118. ./actionlint -color -shellcheck=""
  119. ci-ok:
  120. name: CI OK
  121. runs-on: ubuntu-latest
  122. if: github.actor != 'dependabot[bot]' && !contains(github.event.head_commit.message, '[skip ci]') && always()
  123. needs: [test, check, lint]
  124. env:
  125. FAILURE: ${{ contains(join(needs.*.result, ','), 'failure') }}
  126. steps:
  127. - name: Check for failure
  128. run: |
  129. echo $FAILURE
  130. if [ "$FAILURE" = "false" ]; then
  131. exit 0
  132. else
  133. exit 1
  134. fi