Skip to content

Commit

Permalink
Switch entrypoint to fetch from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
mauromorales committed Aug 25, 2021
1 parent 5fa3d62 commit 4cb1811
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 36 deletions.
14 changes: 3 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
name: 'Pull Request another repository'
description: 'Used for pull request a copy of a folder to another repository'
name: 'Merge Upstream PR'
description: 'Used to keep a downstream repo up to date with upstream changes'
inputs:
source_folder:
description: 'Source folder from origin'
required: true
destination_repo:
description: 'Destination repository'
required: true
destination_folder:
description: 'Destination folder to push the origin folder'
required: false
user_email:
description: 'Email for the git commit'
required: true
Expand All @@ -30,14 +24,12 @@ runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.source-folder }}
- ${{ inputs.destination-repo }}
- ${{ inputs.destination-folder }}
- ${{ inputs.user-email }}
- ${{ inputs.user-name }}
- ${{ inputs.destination-head-branch }}
- ${{ inputs.destination-base-branch }}
- ${{ inputs.pull-request-reviewers }}
branding:
icon: 'git-commit'
color: 'green'
color: 'green'
40 changes: 15 additions & 25 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
set -e
set -x

if [ -z "$INPUT_SOURCE_FOLDER" ]
then
echo "Source folder must be defined"
return -1
fi

if [ $INPUT_DESTINATION_HEAD_BRANCH == "main" ] || [ $INPUT_DESTINATION_HEAD_BRANCH == "master"]
then
echo "Destination head branch cannot be 'main' nor 'master'"
Expand All @@ -32,25 +26,21 @@ git config --global user.name "$INPUT_USER_NAME"
echo "Cloning destination git repository"
git clone "https://$API_TOKEN_GITHUB@github.com/$INPUT_DESTINATION_REPO.git" "$CLONE_DIR"

echo "Copying contents to git repo"
mkdir -p $CLONE_DIR/$INPUT_DESTINATION_FOLDER/
cp $INPUT_SOURCE_FOLDER "$CLONE_DIR/$INPUT_DESTINATION_FOLDER/"
cd "$CLONE_DIR"
git remote add upstream "https://$API_TOKEN_GITHUB@github.com/$GITHUB_REPOSITORY.git"
git checkout -b "$INPUT_DESTINATION_HEAD_BRANCH"

echo "Adding git commit"
git add .
if git status | grep -q "Changes to be committed"
then
git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
echo "Pushing git commit"
git push -u origin HEAD:$INPUT_DESTINATION_HEAD_BRANCH
echo "Creating a pull request"
gh pr create -t $INPUT_DESTINATION_HEAD_BRANCH \
-b $INPUT_DESTINATION_HEAD_BRANCH \
-B $INPUT_DESTINATION_BASE_BRANCH \
-H $INPUT_DESTINATION_HEAD_BRANCH \
$PULL_REQUEST_REVIEWERS
else
echo "No changes detected"
fi
echo "Fetching upstream"
git fetch upstream

echo "Merging"
git merge upstream/master --log -m 'Merge upstream/master'

echo "Pushing git commit"
git push -u origin HEAD:$INPUT_DESTINATION_HEAD_BRANCH
echo "Creating a pull request"
gh pr create -t $INPUT_DESTINATION_HEAD_BRANCH \
-b $INPUT_DESTINATION_HEAD_BRANCH \
-B $INPUT_DESTINATION_BASE_BRANCH \
-H $INPUT_DESTINATION_HEAD_BRANCH \
$PULL_REQUEST_REVIEWERS

0 comments on commit 4cb1811

Please sign in to comment.