Skip to content

React / Stylistic ルールの調整 #38

React / Stylistic ルールの調整

React / Stylistic ルールの調整 #38

Workflow file for this run

name: Test Package
on:
pull_request:
branches:
- "**"
types:
- opened
- synchronize
- reopened
paths:
- "packages/**"
- "package.json"
- ".github/workflows/test.yml"
issue_comment:
types: [created]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
paths-filter:
name: Filter Changed Packages
runs-on: ubuntu-24.04
if: github.event_name == 'pull_request' || (github.event_name == 'issue_comment' && github.event.issue.pull_request && !contains(github.event.comment.user.name, 'bot') && contains(github.event.comment.body, '/run-snapshot'))
permissions:
contents: read
pull-requests: read
timeout-minutes: 5
outputs:
eslint: ${{ steps.filter.outputs.eslint-config }}
prettier: ${{ steps.filter.outputs.prettier-config }}
stylelint: ${{ steps.filter.outputs.stylelint-config }}
head_ref: ${{ steps.head-ref.outputs.head_ref }}
pr_number: ${{ steps.pr-number.outputs.pr_number }}
steps:
- name: Get PR information (issue_comment)
if: github.event_name == 'issue_comment'
id: pr-request
uses: octokit/request-action@dad4362715b7fb2ddedf9772c8670824af564f0d # v2.4.0
with:
route: ${{ github.event.issue.pull_request.url }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Check PR (issue_comment)
if: github.event_name == 'issue_comment'
run: |
if [ "${{ fromJson(steps.pr-request.outputs.data).base.ref }}" != 'main' ]; then
echo "::error::PR base branch is not main."
exit 1
fi
if [ "${{ fromJson(steps.pr-request.outputs.data).state }}" != 'open' ]; then
echo "::error::PR is not open."
exit 1
fi
if [ "${{ fromJson(steps.pr-request.outputs.data).draft }}" == 'true' ]; then
echo "::error::Cannot update snapshot for draft PR."
exit 1
fi
echo "head_ref=${{ fromJson(steps.pr-request.outputs.data).head.ref }}" >> $GITHUB_ENV
- name: Define head ref
id: head-ref
run: |
if [ "${{ github.event_name }}" == 'pull_request' ]; then
echo "head_ref=${{ github.head_ref }}" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" == 'issue_comment' ]; then
echo "head_ref=${{ env.head_ref }}" >> $GITHUB_OUTPUT
else
echo "::error::Unexpected event name: ${{ github.event_name }}"
exit 1
fi
- name: Define PR Number
id: pr-number
run: |
if [ "${{ github.event_name }}" == 'pull_request' ]; then
echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" == 'issue_comment' ]; then
echo "pr_number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT
else
echo "::error::Unexpected event name: ${{ github.event_name }}"
exit 1
fi
- name: Checkout Repo
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
ref: ${{ steps.head-ref.outputs.head_ref }}
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
ref: ${{ steps.head-ref.outputs.head_ref }}
# package.json を含めているのはl、ビルド環境が変わった場合にすべてのパッケージをビルドするようにするため
filters: |
eslint-config:
- 'packages/eslint-config/**'
- 'package.json'
prettier-config:
- 'packages/prettier-config/**'
- 'package.json'
stylelint-config:
- 'packages/stylelint-config/**'
- 'package.json'
test:
needs: paths-filter
name: Vitest
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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
ref: ${{ needs.paths-filter.outputs.head_ref }}
- run: corepack enable pnpm
- name: Setup Node.js 20.x
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version-file: "package.json"
cache: "pnpm"
- name: Install Dependencies
run: pnpm install --frozen-lockfile
- name: Test ESLint Config
id: eslint
if: ${{ needs.paths-filter.outputs.eslint == 'true' }}
continue-on-error: 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' }}
continue-on-error: 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' }}
continue-on-error: true
run: pnpm run build:stylelint && test --project stylelint-config
- name: Comment if any Error
if: steps.eslint.outcome == 'failure' || steps.prettier.outcome == 'failure' || steps.stylelint.outcome == 'failure'
run: |
set -eu
# Create a comment body
cat << EOF > COMMENT.md
## 🚨 Snapshot test failed
See the details in the [workflow run details](${{ 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 \`/update-snapshot\`
**unexpected**: retry the workflow by \`/run-snapshot\`
EOF
- name: Comment if success
if: steps.eslint.outcome == 'success' && steps.prettier.outcome == 'success' && steps.stylelint.outcome == 'success'
run: |
set -eu
# Create a comment body
cat << EOF > COMMENT.md
## ✅ Snapshot test success
See the details in the [workflow run details](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
EOF
- name: Comment to PR
run: |
# Edit the last comment if it exists
if [ ! -f COMMENT.md ]; then
echo "::warn::comment body not found."
exit 0
fi
gh pr comment ${{ needs.paths-filter.outputs.pr_number }} --body-file COMMENT.md --edit-last \
|| gh pr comment ${{ needs.paths-filter.outputs.pr_number }} --body-file COMMENT.md
env:
GH_TOKEN: ${{ github.token }}
- name: Mark as failure if any Error
if: steps.eslint.outcome == 'failure' || steps.prettier.outcome == 'failure' || steps.stylelint.outcome == 'failure'
run: |
echo "::error::Snapshot test failed."
exit 1