From 4cb1811b10abaf49cf2587b1558029ce54e72ed2 Mon Sep 17 00:00:00 2001 From: Mauro Morales Date: Wed, 25 Aug 2021 22:27:52 +0200 Subject: [PATCH] Switch entrypoint to fetch from upstream --- action.yml | 14 +++----------- entrypoint.sh | 40 +++++++++++++++------------------------- 2 files changed, 18 insertions(+), 36 deletions(-) diff --git a/action.yml b/action.yml index b82e227..bb7d42d 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -30,9 +24,7 @@ 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 }} @@ -40,4 +32,4 @@ runs: - ${{ inputs.pull-request-reviewers }} branding: icon: 'git-commit' - color: 'green' \ No newline at end of file + color: 'green' diff --git a/entrypoint.sh b/entrypoint.sh index d6907ad..99f237a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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'" @@ -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