配置creyD/prettier_action遇403权限错误,请求技术协助
解决creyD/prettier_action推送代码时的403权限问题
你配置的creyD/prettier_action已成功完成代码格式化,但推送阶段触发403错误,核心原因是github-actions[bot]没有仓库写入权限。以下是具体修复方案:
1. 调整actions/checkout凭证设置
修改actions/checkout@v4步骤,禁用默认的只读凭证,为后续使用权限凭证铺路:
- uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} fetch-depth: 0 persist-credentials: false # 禁用默认只读凭证
2. 开启仓库Workflow写入权限
进入GitHub仓库设置页面:
- 点击「Settings」→ 左侧菜单「Actions」→「General」
- 找到「Workflow permissions」区域,勾选「Read and write permissions」
- 点击「Save」保存设置
3. 配置Action使用权限令牌
在creyD/prettier_action步骤中添加github_token参数,让Action使用具备写入权限的内置令牌:
- name: Run Prettier uses: creyD/prettier_action@v4.3 with: prettier_options: --write **/*.{js,ts,jsx,tsx,css} --tab-width 4 prettier_plugins: "prettier-plugin-tailwindcss" github_token: ${{ secrets.GITHUB_TOKEN }} # 新增此行
4. 优化pnpm安装步骤(可选)
你当前配置重复调用了pnpm安装步骤,建议合并为一次避免版本冲突:
- uses: pnpm/action-setup@v4 name: Install pnpm with: version: ^9 run_install: false
修复后的完整配置示例
name: Format Codebase w/ Prettier run-name: ${{ github.actor }} is attempting to ${{github.event_name}} to ${{github.repository}} on: pull_request: push: branches: - main jobs: prettier: runs-on: ubuntu-latest env: RUNNER_TOOL_CACHE: /toolcache steps: - uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} fetch-depth: 0 persist-credentials: false - uses: actions/setup-node@v4 with: node-version: 20 - uses: pnpm/action-setup@v4 name: Install pnpm with: version: ^9 run_install: false - name: Install dependencies run: pnpm install - name: Run Prettier uses: creyD/prettier_action@v4.3 with: prettier_options: --write **/*.{js,ts,jsx,tsx,css} --tab-width 4 prettier_plugins: "prettier-plugin-tailwindcss" github_token: ${{ secrets.GITHUB_TOKEN }}
内容的提问来源于stack exchange,提问作者Adebayo Anuoluwa
相关产品推荐
相关产品推荐

