ci.yml 3.9 KB

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