mirror of
https://github.com/cpina/github-action-push-to-another-repository.git
synced 2024-12-22 16:16:09 -07:00
Merge pull request #4 from dmnemec/master
allow separate author and destination repository
This commit is contained in:
commit
db81c54e24
|
@ -22,6 +22,9 @@ For the repository `https://github.com/cpina/push-to-another-repository-output`
|
||||||
### `user-email` (argument)
|
### `user-email` (argument)
|
||||||
The email that will be used for the commit in the destination-repository-name.
|
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)
|
### `API_TOKEN_GITHUB` (environment)
|
||||||
E.g.:
|
E.g.:
|
||||||
`API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}`
|
`API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}`
|
||||||
|
|
|
@ -13,6 +13,9 @@ inputs:
|
||||||
user-email:
|
user-email:
|
||||||
description: 'Email for the git commit'
|
description: 'Email for the git commit'
|
||||||
required: true
|
required: true
|
||||||
|
destination-repository-username:
|
||||||
|
description: '[Optional] Username/organization for the destination repository'
|
||||||
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: 'Dockerfile'
|
image: 'Dockerfile'
|
||||||
|
@ -21,6 +24,7 @@ runs:
|
||||||
- ${{ inputs.destination-github-username }}
|
- ${{ inputs.destination-github-username }}
|
||||||
- ${{ inputs.destination-repository-name }}
|
- ${{ inputs.destination-repository-name }}
|
||||||
- ${{ inputs.user-email }}
|
- ${{ inputs.user-email }}
|
||||||
|
- ${{ inputs.destination-repository-username }}
|
||||||
branding:
|
branding:
|
||||||
icon: 'git-commit'
|
icon: 'git-commit'
|
||||||
color: 'green'
|
color: 'green'
|
||||||
|
|
|
@ -5,25 +5,36 @@ FOLDER="$1"
|
||||||
GITHUB_USERNAME="$2"
|
GITHUB_USERNAME="$2"
|
||||||
GITHUB_REPO="$3"
|
GITHUB_REPO="$3"
|
||||||
USER_EMAIL="$4"
|
USER_EMAIL="$4"
|
||||||
|
REPO_USERNAME="$5"
|
||||||
|
|
||||||
|
if [ -z "$REPO_USERNAME" ]
|
||||||
|
then
|
||||||
|
REPO_USERNAME=$GITHUB_USERNAME
|
||||||
|
fi
|
||||||
|
|
||||||
CLONE_DIR=$(mktemp -d)
|
CLONE_DIR=$(mktemp -d)
|
||||||
|
|
||||||
|
echo "Cloning destination git repository"
|
||||||
# Setup git
|
# Setup git
|
||||||
git config --global user.email "$USER_EMAIL"
|
git config --global user.email "$USER_EMAIL"
|
||||||
git config --global user.name "$GITHUB_USERNAME"
|
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"
|
ls -la "$CLONE_DIR"
|
||||||
|
|
||||||
|
echo "Cleaning destination repository of old files"
|
||||||
# Copy files into the git and deletes all git
|
# 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)
|
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"
|
ls -la "$CLONE_DIR"
|
||||||
|
|
||||||
|
echo "Copying contents to to git repo"
|
||||||
cp -r "$FOLDER"/* "$CLONE_DIR"
|
cp -r "$FOLDER"/* "$CLONE_DIR"
|
||||||
|
|
||||||
cd "$CLONE_DIR"
|
cd "$CLONE_DIR"
|
||||||
|
ls -la
|
||||||
|
|
||||||
|
echo "Adding git commit"
|
||||||
git add .
|
git add .
|
||||||
|
git status
|
||||||
git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
|
git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
|
||||||
|
|
||||||
|
echo "Pushing git commit"
|
||||||
git push origin master
|
git push origin master
|
||||||
|
|
Loading…
Reference in New Issue
Block a user