-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (116 loc) · 4.25 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: Test Package
on:
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
paths:
- "packages/**"
- "package.json"
- ".github/workflows/test.yml"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
paths-filter:
name: Filter Changed Packages (Test Package)
runs-on: ubuntu-24.04
permissions:
pull-requests: read
timeout-minutes: 5
outputs:
eslint: ${{ steps.filter.outputs.eslint }}
prettier: ${{ steps.filter.outputs.prettier }}
stylelint: ${{ steps.filter.outputs.stylelint }}
steps:
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
# package.json を含めているのは、ビルド環境が変わった場合にすべてのパッケージをテストするようにするため
filters: |
eslint:
- 'packages/eslint-config/**'
- 'package.json'
prettier:
- 'packages/prettier-config/**'
- 'package.json'
stylelint:
- 'packages/stylelint-config/**'
- 'package.json'
test:
needs: paths-filter
name: Vitest (Test Package)
if: ${{ needs.paths-filter.outputs.eslint == 'true' || needs.paths-filter.outputs.prettier == 'true' || needs.paths-filter.outputs.stylelint == 'true' }}
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Node.js and pnpm
uses: ./.github/common/setup-node-pnpm
- name: Test ESLint Config
id: eslint
if: ${{ needs.paths-filter.outputs.eslint == 'true' }}
run: pnpm run build:eslint && pnpm run test --project eslint-config
- name: Test Prettier Config
id: prettier
if: ${{ needs.paths-filter.outputs.prettier == 'true' }}
run: pnpm run build:prettier && pnpm run test --project prettier-config
- name: Test Stylelint Config
id: stylelint
if: ${{ needs.paths-filter.outputs.stylelint == 'true' }}
run: pnpm run build:stylelint && pnpm run test --project stylelint-config
- name: Comment if success
run: |
# Create a comment body
cat << EOF > COMMENT.md
## ✅ Snapshot test success
See the details: [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
EOF
- name: Comment if any Error
if: ${{ always() && (steps.eslint.outcome == 'failure' || steps.prettier.outcome == 'failure' || steps.stylelint.outcome == 'failure') }}
run: |
# Create a comment body
cat << EOF > COMMENT.md
## 🚨 Snapshot test failed
See the details: [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
### Errors
EOF
# Append the error message to the comment body
if [ ${{ steps.eslint.outcome }} == 'failure' ]; then
echo "- ESLint" >> COMMENT.md
fi
if [ ${{ steps.prettier.outcome }} == 'failure' ]; then
echo "- Prettier" >> COMMENT.md
fi
if [ ${{ steps.stylelint.outcome }} == 'failure' ]; then
echo "- Stylelint" >> COMMENT.md
fi
# Append the next steps to the comment body
cat << EOF >> COMMENT.md
---
### ⏭️ Next Steps
If snapshot changes are...
**expected**: update the snapshots by adding \`update-snapshot\` label
**unexpected**: check diff and fix rules
EOF
- name: Comment to PR
if: always()
run: |
if [ ! -f COMMENT.md ]; then
echo "::warning::comment body not found."
exit 0
fi
gh pr comment ${{ github.event.number }} --body-file COMMENT.md --edit-last \
|| gh pr comment ${{ github.event.number }} --body-file COMMENT.md
env:
GH_TOKEN: ${{ github.token }}