Skip to content

Version Packages

Version Packages #338

Workflow file for this run

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 }}