|
| 1 | +name: Unit Test PR |
| 2 | +run-name: Unit Test PR--${{ github.event.pull_request.title }} |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened, synchronize, edited] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: ${{ github.workflow }}-${{ github.event.number || github.sha }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +jobs: |
| 12 | + parse-components: |
| 13 | + name: Parse Affected Components |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + testComponents: ${{ steps.parseTitle.outputs.testComponents }} |
| 17 | + steps: |
| 18 | + - name: Parse Title |
| 19 | + id: parseTitle |
| 20 | + uses: actions/github-script@v6 |
| 21 | + with: |
| 22 | + script: | |
| 23 | + const prTitle = context.payload.pull_request.title |
| 24 | + const regex = /\[(.*?)\]/ |
| 25 | + const matches = prTitle.match(regex) |
| 26 | + if (matches && matches.length > 1 && matches[1]) { |
| 27 | + let components = matches[1] |
| 28 | + .split(',') |
| 29 | + .map((c) => c.trim()) |
| 30 | + .filter((c) => /^[a-z\-\/]+$/.test(c)) |
| 31 | + .map((c) => `${c}`) |
| 32 | + components = [...new Set(components)].slice(0, 3).join(' ') |
| 33 | + core.setOutput('testComponents', components) |
| 34 | + } else { |
| 35 | + const warningString =`**[unit-test-warn]** |
| 36 | + The component to be tested is missing. |
| 37 | +
|
| 38 | + The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug". |
| 39 | + |
| 40 | + Please make sure you've read our [contributing guide](https://github.com/opentiny/tiny-vue/blob/dev/CONTRIBUTING.md) |
| 41 | + ` |
| 42 | + core.setOutput('tip', warningString) |
| 43 | + core.warning(warningString) |
| 44 | + } |
| 45 | + - name: generate user-tip.txt |
| 46 | + if: ${{ steps.parseTitle.outputs.tip }} |
| 47 | + run: | |
| 48 | + cat << EOF > user-tip.txt |
| 49 | + ${{ steps.parseTitle.outputs.tip }} |
| 50 | + EOF |
| 51 | + - name: Upload User Tip |
| 52 | + if: ${{ steps.parseTitle.outputs.tip }} |
| 53 | + uses: actions/upload-artifact@v4 |
| 54 | + with: |
| 55 | + name: user-tip |
| 56 | + path: user-tip.txt |
| 57 | + retention-days: 1 |
| 58 | + - name: Save PR number |
| 59 | + if: ${{ steps.parseTitle.outputs.tip }} |
| 60 | + run: echo ${{ github.event.number }} > ./pr-id.txt |
| 61 | + |
| 62 | + - name: Upload PR number |
| 63 | + if: ${{ steps.parseTitle.outputs.tip }} |
| 64 | + uses: actions/upload-artifact@v4 |
| 65 | + with: |
| 66 | + name: pr |
| 67 | + path: ./pr-id.txt |
| 68 | + |
| 69 | + pr-test: |
| 70 | + name: PR Unit Test |
| 71 | + needs: parse-components |
| 72 | + runs-on: ubuntu-latest |
| 73 | + env: |
| 74 | + TEST_COMPONENTS: ${{ needs.parse-components.outputs.testComponents }} |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v3 |
| 77 | + - name: Setup pnpm |
| 78 | + uses: pnpm/action-setup@v2 |
| 79 | + |
| 80 | + - name: Setup node |
| 81 | + uses: actions/setup-node@v3 |
| 82 | + with: |
| 83 | + node-version: 20 |
| 84 | + - name: Get pnpm store directory |
| 85 | + id: pnpm-cache |
| 86 | + run: | |
| 87 | + echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT |
| 88 | +
|
| 89 | + - uses: actions/cache@v3 |
| 90 | + name: Setup pnpm cache |
| 91 | + with: |
| 92 | + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} |
| 93 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 94 | + restore-keys: | |
| 95 | + ${{ runner.os }}-pnpm-store- |
| 96 | +
|
| 97 | + - name: Install dependencies |
| 98 | + run: pnpm i --no-frozen-lockfile |
| 99 | + |
| 100 | + - name: Unit Test |
| 101 | + run: pnpm test:unit3 ${{ env.TEST_COMPONENTS }} |
0 commit comments