create-pull-request
create-pull-request copied to clipboard
PR creation while checking out from tag
Subject of the issue:
I am trying to create a pull request from checking out to a tag. I have supplied input base as main. Nevertheless I am facing the error fatal: ref HEAD is not a symbolic ref.
Goal:
I have the required the changes in the tag. peter-evans/create-pull-request@v6 has to create a pull request for the new changes in the existing tag to main branch from the branch "release/${{inputs.product}}-test-to-production" to be created. How to achieve this?
Steps to reproduce
name: "Start Promotion Staging->Production"
permissions:
contents: write
issues: write
pull-requests: write
on:
workflow_call:
inputs:
product:
description: 'ping product to promote'
required: true
type: string
tag:
description: 'tag to deploy'
required: true
type: string
jobs:
promote:
runs-on: ubuntu-latest
name: Promoting from test to production
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
fetch-depth: 0
- name: Copy PingDirectory
if: inputs.product == 'pingdirectory'
run: |
rm -rf ./nuuday-ciam/production/pingdirectory
cp -r nuuday-ciam/test/pingdirectory/ nuuday-ciam/production/pingdirectory
find ./nuuday-ciam/production/pingdirectory/ -name '*_test.*' -type f -delete
- name: Copy PingFederate
if: inputs.product == 'pingfederate'
run: |
npm install --dev --prefix .build
rm -rf nuuday-ciam/production/pingfederate
cp -r nuuday-ciam/test/pingfederate nuuday-ciam/production/pingfederate
find ./nuuday-ciam/production/pingfederate/ -name '*.css.map*' -type f -delete
npm run config:production --prefix .build
- name: Git status
run: git status
- name: Commit and push files to the tag
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add -A
git commit -a -m "Add changes"
git tag -d ${{ inputs.tag }}
git tag ${{ inputs.tag }}
git push origin :${{ inputs.tag }}
git push origin ${{ inputs.tag }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.REPOSITORY_ROBOT_PAT }}
branch: "release/${{inputs.product}}-test-to-production"
commit-message: "chore(release): promoting ${{inputs.product}} from test to production"
title: "chore(release): promoting ${{inputs.product}} from test to production"
base: main
assignees: ${{ github.actor }}
labels: "automated promotion"
body: |
THIS IS AN AUTOMATED PROMOTION FROM THE TEST ENVIRONMENT TO PRODUCTION ENVIRONMENT.
PLEASE REVIEW THE FILE CHANGES IN THIS PR AND MERGE IT WHEN YOU ARE READY.
WHEN THIS PR IS MERGED, THE CHANGES WILL BE AUTOMATICALLY DEPLOYED TO PRODUCTION.
Log
_usr/bin/git symbolic-ref HEAD --short
fatal: ref HEAD is not a symbolic ref
/usr/bin/git rev-parse HEAD
498fcbf8de6fe8927789fb9298d841d9a0128761
Working base is commit '498fcbf8de6fe8927789fb9298d841d9a0128761'
/usr/bin/git checkout --progress -B 8f322fbc-0a73-4359-85c3-4ab3bf1b2bd6 HEAD --
Switched to a new branch '8f322fbc-0a73-4359-85c3-4ab3bf1b2bd6'
/usr/bin/git status --porcelain -unormal --
/usr/bin/git diff --quiet --
/usr/bin/git diff --quiet --staged --
/usr/bin/git stash push --include-untracked
No local changes to save
Rebasing commits made to commit '498fcbf8de6fe8927789fb9298d841d9a0128761' on to base branch 'main'
/usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --force --depth=1 origin main:main
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
From https://github.com/nuuday/ciam-server-profiles
* [new branch] main -> main
/usr/bin/git checkout --progress main --
Switched to branch 'main'
/usr/bin/git rev-list --reverse 498fcbf8de6fe8927789fb9298d841d9a0128761..8f322fbc-0a73-4359-85c3-4ab3bf1b2bd6 .
/usr/bin/git checkout --progress -B 8f322fbc-0a73-4359-85c3-4ab3bf1b2bd6 HEAD --
Switched to and reset branch '8f322fbc-0a73-4359-85c3-4ab3bf1b2bd6'
/usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --force --depth=1 origin main:main
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
/usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --force origin release/pingfederate-test-to-production:refs/remotes/origin/release/pingfederate-test-to-production
fatal: couldn't find remote ref release/pingfederate-test-to-production
Pull request branch 'release/pingfederate-test-to-production' does not exist yet.
/usr/bin/git checkout --progress -B release/pingfederate-test-to-production 8f322fbc-0a73-4359-85c3-4ab3bf1b2bd6 --
Switched to a new branch 'release/pingfederate-test-to-production'
/usr/bin/git rev-list --right-only --count main...release/pingfederate-test-to-production
0
Branch 'release/pingfederate-test-to-production' is not ahead of base 'main' and will not be created
/usr/bin/git rev-parse HEAD
dc00c[55](https://github.com/nuuday/ciam-server-profiles/actions/runs/8260672625/job/22596580532#step:7:61)82c5fe5b474d5b8bebba1a15eaa8bf5aa
/usr/bin/git branch --delete --force 8f322fbc-0a73-4359-85c3-4ab3bf1b2bd6
Deleted branch 8f322fbc-0a73-4359-85c3-4ab3bf1b2bd6 (was dc00c5[58](https://github.com/nuuday/ciam-server-profiles/actions/runs/8260672625/job/22596580532#step:7:64)).
/usr/bin/git checkout --progress 498fcbf8de6fe8927789fb9298d841d9a01287[61](https://github.com/nuuday/ciam-server-profiles/actions/runs/8260672625/job/22596580532#step:7:67) --
Note: switching to '498fcbf8de6fe8927789fb9298d841d9a0128[76](https://github.com/nuuday/ciam-server-profiles/actions/runs/8260672625/job/22596580532#step:7:82)1'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false_
Hi @Poornachand200
The reason this isn't working is not the message you see in the logs about detached HEAD, it's this line here:
Branch 'release/pingfederate-test-to-production' is not ahead of base 'main' and will not be created
Please follow this example: https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md#keep-a-branch-up-to-date-with-another
My understanding is that you want to update main from the specified tag. So your solution should look something like this:
jobs:
productionPromotion:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Reset main branch to match the specified tag
run: |
git fetch origin ${{ inputs.tag }}:${{ inputs.tag }}
git reset --hard ${{ inputs.tag }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
branch: "release/${{inputs.product}}-test-to-production"
I've never tried to use this method with a tag before, so it will be interesting to hear if it works ok.
I tried updating the workflow like this. Attached the screen shot of the pull request and the extracted logs.
The below screen shot in create pull request steps shows only file is modified and will be added. But the created PR has the file which is copied in copy step in below. I need to ignore the file in test folder after copy step. The PR shouldn't have the test folder changes.
- name: Copy PingDirectory
if: inputs.product == 'pingdirectory'
run: |
rm -rf ./nuuday-ciam/production/pingdirectory
cp -r nuuday-ciam/test/pingdirectory/ nuuday-ciam/production/pingdirectory
find ./nuuday-ciam/production/pingdirectory/ -name '*_test.*' -type f -delete
- name: Copy PingFederate
if: inputs.product == 'pingfederate'
run: |
npm install --dev --prefix .build
rm -rf nuuday-ciam/production/pingfederate
cp -r nuuday-ciam/test/pingfederate nuuday-ciam/production/pingfederate
find ./nuuday-ciam/production/pingfederate/ -name '*.css.map*' -type f -delete
npm run config:production --prefix .build
name: "Start Promotion Staging->Production"
permissions:
contents: write
issues: write
pull-requests: write
on:
workflow_call:
inputs:
product:
description: 'ping product to promote'
required: true
type: string
tag:
description: 'tag to deploy'
required: true
type: string
jobs:
promote:
runs-on: ubuntu-latest
name: Promoting from test to production
steps:
- uses: actions/checkout@v4
with:
ref: main
#- uses: actions/checkout@v4
# with:
# ref: ${{ inputs.tag }}
# fetch-depth: 0
- name: Reset main branch to match the specified tag
run: |
git fetch origin ${{ inputs.tag }}:${{ inputs.tag }}
git reset --hard ${{ inputs.tag }}
- name: Git status
run: git status
- name: Copy PingDirectory
if: inputs.product == 'pingdirectory'
run: |
rm -rf ./nuuday-ciam/production/pingdirectory
cp -r nuuday-ciam/test/pingdirectory/ nuuday-ciam/production/pingdirectory
find ./nuuday-ciam/production/pingdirectory/ -name '*_test.*' -type f -delete
- name: Copy PingFederate
if: inputs.product == 'pingfederate'
run: |
npm install --dev --prefix .build
rm -rf nuuday-ciam/production/pingfederate
cp -r nuuday-ciam/test/pingfederate nuuday-ciam/production/pingfederate
find ./nuuday-ciam/production/pingfederate/ -name '*.css.map*' -type f -delete
npm run config:production --prefix .build
- name: Git status
run: git status
#- name: Commit and push files to the tag
# run: |
# git config --local user.email "github-actions[bot]@users.noreply.github.com"
# git config --local user.name "github-actions[bot]"
# git add -A
# git commit -a -m "Add changes"
# git tag -d ${{ inputs.tag }}
# git tag ${{ inputs.tag }}
# git push origin :${{ inputs.tag }}
# git push origin ${{ inputs.tag }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.REPOSITORY_ROBOT_PAT }}
branch: "release/${{inputs.product}}-test-to-production"
commit-message: "chore(release): promoting ${{inputs.product}} from test to production"
title: "chore(release): promoting ${{inputs.product}} from test to production"
assignees: ${{ github.actor }}
base: main
labels: "automated promotion"
body: |
THIS IS AN AUTOMATED PROMOTION FROM THE TEST ENVIRONMENT TO PRODUCTION ENVIRONMENT.
PLEASE REVIEW THE FILE CHANGES IN THIS PR AND MERGE IT WHEN YOU ARE READY.
WHEN THIS PR IS MERGED, THE CHANGES WILL BE AUTOMATICALLY DEPLOYED TO PRODUCTION.
add-paths doesn't seem to work as expected. It also add nuuday-ciam/test which doesn't match.
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.REPOSITORY_ROBOT_PAT }}
branch: "release/${{inputs.product}}-test-to-production"
commit-message: "chore(release): promoting ${{inputs.product}} from test to production"
title: "chore(release): promoting ${{inputs.product}} from test to production"
assignees: ${{ github.actor }}
base: main
labels: "automated promotion"
add-paths: nuuday-ciam/production/
body: |
THIS IS AN AUTOMATED PROMOTION FROM THE TEST ENVIRONMENT TO PRODUCTION ENVIRONMENT.
PLEASE REVIEW THE FILE CHANGES IN THIS PR AND MERGE IT WHEN YOU ARE READY.
WHEN THIS PR IS MERGED, THE CHANGES WILL BE AUTOMATICALLY DEPLOYED TO PRODUCTION.