i am getting some pull requests from other branches to merge it to main branch, but before merging I need to check whether the pull request affecting filepath is already exists or not in main branch, because I don’t want to overwrite the old one. If it exists it should echo this file path already exists with complete filepath of pull request (adding PR number along with the complete filepath to the message will be good if possible) and may have many subfolders in all branches, need to check all.
Consider for example:
- branch1 has folder1/subfolder1/file1.txt
- main branch also have folder1/subfolder1/file1.txt with same names
- maybe I have changed some data to branch1 text file and created a pull request to merge it
It should not merge (should not overwrite). It should say already exists and if we don’t have the same path in main branch with same names, then it should create.
name: Check and Create Folder
on:
workflow_dispatch: # Trigger on push to branches
jobs:
check_and_create:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # Checkout code
- name: Check if folder exists
run: |
if [ ! -d "$folderpath" ]; then
echo "Folder does not exist. Creating."
#mkdir "$folderpath"
else
echo "Folder already exists. Skipping creation."
fi
Tried to create one workflow to check folder path of current repo. When we give folder path manually in script it is checking folder path, but I’m stuck to fetch the affecting folder path from pull request because I have lots of PRs, I can’t check each and every one. I don’t want to overwrite old one.