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

Branch is not created from default branch and it is creating from base branch #3364

Closed
Poornachand200 opened this issue Sep 19, 2024 · 11 comments

Comments

@Poornachand200
Copy link

Poornachand200 commented Sep 19, 2024

Branch is not created from default branch and it is creating from base branch

Describe your issue here.

I need to create a pull request to target branch test1 or test2. But I want to create the branch with reference to main. This means branch should be created or checked out from main branch. But the branch doesn't have changes from main. Instead it is getting created from test1 branch. Below is the example. The workflow actions runs on main branch.

Steps to reproduce

name: "kickstart the creation of a dynamic environment"

permissions:
  contents: write
  issues: write
  pull-requests: write
  id-token: write

on:
  workflow_dispatch:
    inputs:
      JIRA-ID:
        description: "Jira ticket number, e.g. ID-1234"
        required: true
        default: "ID-1234"
      PR-type:
        type: choice
        description: "choose the PR type from the given options"
        options:
          - fix
          - feat
          - breaking-change
          - build
          - chore
          - ci
          - docs
          - style
          - refactor
          - perf
        required: true
        default: "feat"
      PR-title:
        description: "PR title in the format - e.g: Adding Refresh token to Oauth client"
        required: true
      label:
        type: choice
        description: "label to be added to PR"
        required: true
        options:
          - AD
          - AM
        default: "AD"
      test-environment:
        type: choice
        description: "test environment to promote to"
        options:
          - test1
          - test2
        required: true
        default: "test1"

env:
  PING_HELM_CHART_VERSION: 0.9.12

jobs:
  kickstart_dynamic_environment:
    if: inputs.JIRA-ID && inputs.JIRA-ID != '' && contains(inputs.JIRA-ID, 'ID-')
    runs-on: ubuntu-latest
    name: Kick start dynamic environment
    environment: conf-${{ inputs.JIRA-ID }}
    steps:
      - uses: actions/checkout@v2

      - name: Dump GitHub context
        id: github_context_step
        run: echo '${{ toJSON(github) }}'

      - name: Convert JIRA ticket number to lowercase
        run: |
          head_ref_TEMP="${{ inputs.JIRA-ID }}"
          echo "LOWERCASE_JIRA_ID=${head_ref_TEMP,,}" >>${GITHUB_ENV}

      - name: Create a random tmp file
        run: |
          touch ./.github/tmp/${{ inputs.JIRA-ID}}.txt

      - name: check if branch exists
        id: set_branch
        run: |
          if git ls-remote --exit-code --heads origin ${{ inputs.JIRA-ID }}; then
            echo "branch variable :  ${{ inputs.JIRA-ID}}"
          else
            echo "branch variable :  ${{ inputs.JIRA-ID}}"
            echo "branch_not_exists=yes" >> $GITHUB_ENV
            echo "not exists"
          fi
          
      - name: Create Pull Request
        if: env.branch_not_exists != ' ' 
        uses: peter-evans/create-pull-request@v5
        with:
          token: ${{ secrets.REPOSITORY_ROBOT_PAT }}
          branch: ${{ inputs.JIRA-ID }}
          commit-message: "Kickstart the creation of a Dynamic Environment"
          title: "${{ inputs.PR-type }}(${{inputs.JIRA-ID}}): ${{ inputs.PR-title }}"
          assignees: ${{ github.actor }}
          base: ${{ inputs.test-environment }}
          draft: true
          labels: ${{ inputs.label }}
          body: |
            Jira ticket: ${{ env.LOWERCASE_JIRA_ID }}

            The dynamic environment will be available at the following addresses when it's ready:
            - https://${{ env.LOWERCASE_JIRA_ID }}-federate.dev.ciam.non-prod.managed-eks.aws.nuuday.nu
            - https://${{ env.LOWERCASE_JIRA_ID }}-federate-engine.dev.ciam.non-prod.managed-eks.aws.nuuday.nu
            - https://${{ env.LOWERCASE_JIRA_ID }}-directory.dev.ciam.non-prod.managed-eks.aws.nuuday.nu

If this issue is describing a possible bug please provide (or link to) your GitHub Actions workflow.

@Poornachand200
Copy link
Author

@peter-evans Please update on this.

@peter-evans
Copy link
Owner

Hi @Poornachand200

This is not a particularly common workflow, so I'm not 100% sure if what you want to do will work, but it looks like it should.

First of all, check that main is being checked out properly in the first step. You could explicitly check it out by adding ref. Also, just in case, update checkout to v4.

- uses: actions/checkout@v4
  with:
    ref: main

@rwader-swi
Copy link

rwader-swi commented Sep 23, 2024

I already had a branch and wanted to create a pullrequest whose base will be the other branch which I had defined while calling this action. But what this action does is just resets my already present PR branch to make it same as base branch and then says "this branch no longer differs from the base". Then I also tried creating another branch from my already created PR branch by giving different input to branch but then it just says Branch 'new_branch' is not ahead of base '***' and will not be created

@rwader-swi
Copy link

rwader-swi commented Sep 23, 2024

can you suggest me a workaround for above? @peter-evans

@Poornachand200
Copy link
Author

@peter-evans checkout is updated as below. It seems the reference is still from the target branch test1 or test2.

  • uses: actions/checkout@v4
    with:
    ref: main

@Poornachand200
Copy link
Author

@peter-evans We are also encountering conflicts because of this case.

@Poornachand200
Copy link
Author

@peter-evans Please update

@Poornachand200
Copy link
Author

@peter-evans We are facing conflicts because of this issue. Please assist.

@peter-evans
Copy link
Owner

@Poornachand200 I'm afraid I don't have a lot of time at the moment. The next thing you can do is provide a log of the complete run so I can see what is happening.

@Poornachand200
Copy link
Author

logs_28879649215.zip
PFA of PR creation workflow log

@peter-evans
Copy link
Owner

@Poornachand200 I think I understand what you mean now. You need to follow the example here: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md#keep-a-branch-up-to-date-with-another

i.e. Checkout the target, e.g. test1, then reset the branch using main. Then call this action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@peter-evans @rwader-swi @Poornachand200 and others