wearerequired / lint-action

✨ GitHub Action for detecting and auto-fixing lint errors
MIT License
567 stars 136 forks source link

Action does not work on pull_request or pull_request_traget #817

Open alonapester opened 1 month ago

alonapester commented 1 month ago

Hello, I am trying to add the action to run on PR but it only fails for me with cannot force update the branch '<BRANCH_NAME>' used by worktree.

I tried to do all the the suggestions under limitations but changing permissions, giving token with all permissions, changing to pull_request_target, nothing worked for me, all got the same error as before.

The actions is working on push but I need it to work on PRs.

The current workflow:

name: Build-Dev

env:
  BUILD_MODE: dev
  NODE_VERSION: "18"
  NODE_ENV: generic

on:
  pull_request:
    branches:
      - "**"
    paths:
      - "**"
      - "!.github/**"
      - "!.gitignore"
      - "!README.md"
  push:
    tags:
      - "**-v[0-9].[0-9]+.[0-9]+-dev[0-9]+"

permissions:
  checks: write
  contents: write
  pull-requests: write

jobs:
  build-dev:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout branch
        uses: actions/checkout@v4
        with:
          ref: ${{ github.head_ref || github.ref_name }}
          token: ${{ secrets.GH_TOKEN }}
          fetch-depth: 0
          persist-credentials: false

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}

      - name: Setup npm cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.npm
            node_modules
          key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-${{ env.NODE_VERSION }}

      - name: Install dependencies
        run: npm ci

      - name: Save node_modules cache
        uses: actions/cache@v4
        with:
          path: node_modules
          key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-modules

##############################
##############################

      - name: Run linters
        uses: wearerequired/lint-action@v2.3.0
        with:
          eslint: true
          prettier: true

##############################
##############################

      - name: Run npm tests
        run: npm test

      - name: Build project
        run: npm run build

      - name: Upload build artifacts
        uses: actions/upload-artifact@v4
        with:
          name: node-build
          path: build/*

  trigger-deploy:
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/')
    needs: build-dev
    steps:
      - name: Repository Dispatch
        uses: peter-evans/repository-dispatch@v3
        with:
          token: ${{ secrets.GH_TOKEN }}
          repository: ${{ github.repository }}
          event-type: trigger-deploy-dev
          client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "ref_name": "${{ github.ref_name }}", "run_id": "${{ github.run_id }}"}'
IliyanKostov9 commented 1 week ago

Hey @alonapester ,

You can use ref: ${{ github.event.pull_request.head.sha }}.