Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action does not work on pull_request or pull_request_traget #817

Closed
alonapester opened this issue Aug 4, 2024 · 2 comments
Closed

Action does not work on pull_request or pull_request_traget #817

alonapester opened this issue Aug 4, 2024 · 2 comments
Labels

Comments

@alonapester
Copy link

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/[email protected]
        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
Copy link

Hey @alonapester ,

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

Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Nov 20, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants