Merge pull request #4 from dmnemec/master

allow separate author and destination repository
This commit is contained in:
Carles Pina Estany 2020-08-12 15:04:22 +02:00 committed by GitHub
commit db81c54e24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View File

@ -22,6 +22,9 @@ For the repository `https://github.com/cpina/push-to-another-repository-output`
### `user-email` (argument)
The email that will be used for the commit in the destination-repository-name.
### `destination-repository-username` (argument) [optional]
The Username/Organization for the destination repository, if different from `destination-github-username`. For the repository `https://github.com/cpina/push-to-another-repository-output` is `cpina`.
### `API_TOKEN_GITHUB` (environment)
E.g.:
`API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}`

View File

@ -13,6 +13,9 @@ inputs:
user-email:
description: 'Email for the git commit'
required: true
destination-repository-username:
description: '[Optional] Username/organization for the destination repository'
required: false
runs:
using: 'docker'
image: 'Dockerfile'
@ -21,6 +24,7 @@ runs:
- ${{ inputs.destination-github-username }}
- ${{ inputs.destination-repository-name }}
- ${{ inputs.user-email }}
- ${{ inputs.destination-repository-username }}
branding:
icon: 'git-commit'
color: 'green'

View File

@ -5,25 +5,36 @@ FOLDER="$1"
GITHUB_USERNAME="$2"
GITHUB_REPO="$3"
USER_EMAIL="$4"
REPO_USERNAME="$5"
if [ -z "$REPO_USERNAME" ]
then
REPO_USERNAME=$GITHUB_USERNAME
fi
CLONE_DIR=$(mktemp -d)
echo "Cloning destination git repository"
# Setup git
git config --global user.email "$USER_EMAIL"
git config --global user.name "$GITHUB_USERNAME"
git clone "https://$API_TOKEN_GITHUB@github.com/$GITHUB_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR"
git clone --single-branch --branch master "https://$API_TOKEN_GITHUB@github.com/$REPO_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR"
ls -la "$CLONE_DIR"
echo "Cleaning destination repository of old files"
# Copy files into the git and deletes all git
find "$CLONE_DIR" | grep -v "^$CLONE_DIR/\.git" | grep -v "^$CLONE_DIR$" | xargs rm -rf # delete all files (to handle deletions)
ls -la "$CLONE_DIR"
echo "Copying contents to to git repo"
cp -r "$FOLDER"/* "$CLONE_DIR"
cd "$CLONE_DIR"
ls -la
echo "Adding git commit"
git add .
git status
git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
echo "Pushing git commit"
git push origin master