cloudflare / pages-action

MIT License
440 stars 91 forks source link

The branch parameter is not defaulted to the branch that triggers a workflow #97

Open apeacock1991 opened 1 year ago

apeacock1991 commented 1 year ago

Based on the documentation, if you omit branch, it should default to the branch for the workflow.

I omitted the parameter, but it always reported deployments in the dashboard to master. Passing the branch using branch: ${{ github.ref_name }} fixed this, but the docs either need updating or the code fixing.

davidlj95 commented 10 months ago

Had the same issue. However, did something a bit different to OP as workaround:

github.ref_name in a pull request refers to the pull request merge branch. Something like 42/merge. Where 42 is the PR number.

So instead, I've used:

branch:  ${{ github.head_ref || github.ref_name }}

github.head_ref refers to the base branch if being triggered in a pull request (i.e. feat-do-some-work). And if not a pull request, assume it's a push workflow and then github.ref_name is the branch that was pushed (i.e. main).

Indeed github.head_ref || github.ref_name is what the action actually tries to do

davidlj95 commented 10 months ago

Btw I'm using reusable workflows. Maybe that's the source of the issue

richardscarrott commented 9 months ago

I ran into the same issue (not using reusable workflows). Without setting the branch in config, deploys run on pull_request were all named HEAD.

Setting to branch: ${{ github.head_ref || github.ref_name }} gives me the source branch on pull_request and the branch name on push 🙌

p4block commented 9 months ago

Same problem for me, fixed by the previous comment. Here's my full config for future ref:

      - name: Build web
        run: |
          if [ "$GITHUB_REF_NAME" == "main" ]; then
            npm run build:web:prod
          elif [ "$GITHUB_REF_NAME" == "staging" ]; then
            npm run build:web:staging
          else 
            npm run build:web
          fi

      - name: Publish site
        uses: cloudflare/pages-action@v1
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          projectName: ${{ matrix.cf-project }}
          directory: www
          gitHubToken: ${{ secrets.GITHUB_TOKEN }}
          branch:  ${{ github.head_ref || github.ref_name }}
harryzcy commented 7 months ago

Also, when the event is triggered by pushing a tag, the Cloudflare deployments just show HEAD

tien commented 7 months ago

Got this exact same issue

druvv commented 1 month ago

I have this issue as well.