Skip to content

Commit

Permalink
Merge pull request #8 from solenova-tech/fixing-the-make-shift
Browse files Browse the repository at this point in the history
Fixing the make shift solution caused by actions/checkout
  • Loading branch information
UmairJibran authored May 24, 2023
2 parents 7da8009 + de2a3fa commit 3461bd6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
with:
target-branch: 'staging' # replace this name with your testing branch
token: ${{ secrets.GITHUB_TOKEN }} # Read below on how to get this

```
This action requires a personal access token (PAT) with appropriate permissions to perform the merge operation. Make sure you provide the token input with a valid GitHub Personal Access Token. Create a PAT with the REPO permission using the following steps:
Expand All @@ -56,6 +55,16 @@ This action requires a personal access token (PAT) with appropriate permissions
- Click on the "Add secret" button to save the secret.
**Note that, PAT grants significant access to your GitHub account, so treat them like passwords and keep them secure.**
### Using actions/checkout
If your pre-existing yml file (that your including this action to) is already using checkout, please use it with `persist-credentials` and set the value to `false`

```YML
- name: checkout code
uses: actions/checkout@v3
with:
persist-credentials: false
```
## Inputs

`target-branch` (optional): The branch in which you want to merge the pull request. Defaults to 'alpha'.
Expand Down
33 changes: 11 additions & 22 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,18 @@ runs:
run: |
echo "DECLARING DEFAULT BRANCH"
BRANCH=${{ github.event.repository.default_branch }}
# THIS IS DESPERATE MAKESHIFT SOLUTION, NEEDS TO BE FIXED!
# if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
# echo "INITIALIZING GIT REPO"
# git init
# echo "SETTING DEFAULT BRANCH"
# git branch -m $BRANCH
# else
# echo "REMOVING REMOTE ORIGIN FOR PRE EXISTING REPO"
# git remote remove origin
# fi
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "REMOVING ACTIVE REPO"
echo "SORRY, FOR DOING THIS THE HARD WAY"
echo "IF YOU CAN SOLVE THIS FOR EVERYONE, PLEASE DO"
rm -r ./* .[!.]*
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "INITIALIZING GIT REPO"
git init
echo "SETTING DEFAULT BRANCH"
git branch -m $BRANCH
echo "SETTING UP GIT REMOTE ORIGIN"
git remote add origin https://${{ github.repository_owner }}:${{ env.GITHUB_PAT }}@github.com/${{ github.repository }}.git
else
echo "UPDATING REMOTE ORIGIN FOR PRE EXISTING REPO"
git config --unset http.https://github.com/.extraheader
git remote set-url origin https://${{ github.repository_owner }}:${{ env.GITHUB_PAT }}@github.com/${{ github.repository }}.git
fi
echo "INITIALIZING GIT REPO"
git init
echo "SETTING DEFAULT BRANCH"
git branch -m $BRANCH
echo "SETTING UP GIT REMOTE ORIGIN"
git remote add origin https://${{ github.repository_owner }}:${{ env.GITHUB_PAT }}@github.com/${{ github.repository }}.git
git fetch
if ! git ls-remote --exit-code --heads origin ${{ env.TARGET_BRANCH }} >/dev/null 2>&1; then
echo "CHECKING OUT \`$BRANCH\`"
Expand Down

0 comments on commit 3461bd6

Please sign in to comment.