Skip to content

fix(deps): update eslint (eslint-config) #111

fix(deps): update eslint (eslint-config)

fix(deps): update eslint (eslint-config) #111

name: Update Snapshot
on:
workflow_dispatch:
inputs:
eslint:
description: "Update ESLint Config Snapshot"
required: true
default: false
type: boolean
prettier:
description: "Update Prettier Config Snapshot"
required: true
default: false
type: boolean
stylelint:
description: "Update Stylelint Config Snapshot"
required: true
default: false
type: boolean
issue_comment:
types: [created]
jobs:
filter-packages:
name: Check Changed Packages (Update Snapshot)
runs-on: ubuntu-24.04
if: github.event_name == 'issue_comment' && github.event.issue.pull_request && !contains(github.event.comment.user.name, 'bot') && contains(github.event.comment.body, '/update-snapshot')
outputs:
head_ref: ${{ fromJson(steps.pr-request.outputs.data).head.ref }}
eslint: ${{ false || steps.filter.outputs.eslint }}
prettier: ${{ false || steps.filter.outputs.prettier }}
stylelint: ${{ false || steps.filter.outputs.stylelint }}
permissions:
contents: read
steps:
- name: Get PR information
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: Exit if invalid PR
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
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ fromJson(steps.pr-request.outputs.data).head.ref }}
- name: Check changed packages (PR Comment)
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
ref: ${{ fromJson(steps.pr-request.outputs.data).head.ref }}
filters: |
eslint:
- 'packages/eslint-config/**'
prettier:
- 'packages/prettier-config/**'
stylelint:
- 'packages/stylelint-config/**'
check-target-packages:
name: Check target packages (Update Snapshot)
if: always()
needs: filter-packages
runs-on: ubuntu-24.04
outputs:
eslint: ${{ steps.check.outputs.eslint }}
prettier: ${{ steps.check.outputs.prettier }}
stylelint: ${{ steps.check.outputs.stylelint }}
head_ref: ${{ steps.set-head-ref.outputs.head_ref }}
steps:
- name: Check target packages
id: check
run: |
if [ ${{ github.event_name }} == 'workflow_dispatch' ]; then
echo "eslint=${{ github.event.inputs.eslint }}" >> $GITHUB_OUTPUT
echo "prettier=${{ github.event.inputs.prettier }}" >> $GITHUB_OUTPUT
echo "stylelint=${{ github.event.inputs.stylelint }}" >> $GITHUB_OUTPUT
elif [ ${{ github.event_name }} == 'issue_comment' ]; then
echo "eslint=${{ needs.filter-packages.outputs.eslint }}" >> $GITHUB_OUTPUT
echo "prettier=${{ needs.filter-packages.outputs.prettier }}" >> $GITHUB_OUTPUT
echo "stylelint=${{ needs.filter-packages.outputs.stylelint }}" >> $GITHUB_OUTPUT
else
echo "::error::Workflow called by unexpected event."
exit 1
fi
- name: Set head ref
id: set-head-ref
run: |
if [ ${{ github.event_name }} == 'workflow_dispatch' ]; then
echo "head_ref=${{ github.ref }}" >> $GITHUB_OUTPUT
elif [ ${{ github.event_name }} == 'issue_comment' ]; then
echo "head_ref=${{ needs.filter-packages.outputs.head_ref }}" >> $GITHUB_OUTPUT
else
echo "::error::Workflow called by unexpected event."
exit 1
fi
update-snapshot:
name: Update Snapshot (Update Snapshot)
needs: check-target-packages
if: always() && (needs.check-target-packages.outputs.eslint == 'true' || needs.check-target-packages.outputs.prettier == 'true' || needs.check-target-packages.outputs.stylelint == 'true')
runs-on: ubuntu-24.04
permissions:
contents: write
pull-requests: write
timeout-minutes: 10
steps:
- uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
id: app-token
with:
app-id: ${{ vars.ACTIONS_MIKU_APP_ID }}
private-key: ${{ secrets.ACTIONS_MIKU_PRIVATE_KEY }}
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ needs.check-target-packages.outputs.head_ref }}
token: ${{ steps.app-token.outputs.token }}
- name: Configure Git Identity
run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
if [ ${{ github.event_name }} == 'workflow_dispatch' ]; then
git switch -c "bot/update-snapshot-$(TZ=UTC-9 date +'%Y%m')-${SHA:0:7}"
fi
- name: Setup Node.js and pnpm
uses: ./.github/common/setup-node-pnpm
- name: Update ESLint Config Snapshot
if: needs.check-target-packages.outputs.eslint == 'true'
run: pnpm run build:eslint && pnpm run test --project eslint-config -u
- name: Update Prettier Config Snapshot
if: needs.check-target-packages.outputs.prettier == 'true'
run: pnpm run build:prettier && pnpm run test --project prettier-config -u
- name: Update Stylelint Config Snapshot
if: needs.check-target-packages.outputs.stylelint == 'true'
run: pnpm run build:stylelint && pnpm run test --project stylelint-config -u
- name: Commit and Push Changes
run: |
set -eu
git add .
git commit -m "chore: update snapshot (github-actions)"
git push origin HEAD
- name: Create change summary markdown
run: |
set -eu
echo "## 🚚 Updated snapshots" >> CHANGES.md
if [ ${{ needs.check-target-packages.outputs.eslint }} == 'true' ]; then
echo "- ESLint" >> CHANGES.md
fi
if [ ${{ needs.check-target-packages.outputs.prettier }} == 'true' ]; then
echo "- Prettier" >> CHANGES.md
fi
if [ ${{ needs.check-target-packages.outputs.stylelint }} == 'true' ]; then
echo "- Stylelint" >> CHANGES.md
fi
- name: Comment to PR (Issue Comment)
if: github.event_name == 'issue_comment'
run: |
set -eu
if [ ! -f CHANGES.md ]; then
echo "::warning::comment body not found."
exit 0
fi
gh pr comment ${{ github.event.issue.number }} --body-file CHANGES.md --edit-last \
|| gh pr comment ${{ github.event.issue.number}} --body-file CHANGES.md
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Create Pull Request (Workflow Dispatch)
if: github.event_name == 'workflow_dispatch'
run: |
set -eu
if [ ! -f CHANGES.md ]; then
echo "::warning::comment body not found."
exit 0
fi
gh pr create --base "main" --body-file CHANGES.md --title "update snapshot (github-actions)"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}