Merge branch 'patch-1' into main

This commit is contained in:
Carles Pina i Estany 2021-10-25 23:41:08 +01:00
commit df5ac1b335
2 changed files with 16 additions and 9 deletions

View File

@ -18,6 +18,10 @@ inputs:
user-email: user-email:
description: Email for the git commit description: Email for the git commit
required: true required: true
github-server:
description: 'Github server'
default: 'github.com'
required: false
user-name: user-name:
description: >- description: >-
[Optional] Name for the git commit. Defaults to the destination [Optional] Name for the git commit. Defaults to the destination
@ -44,6 +48,7 @@ inputs:
description: '[Optional] The directory to wipe and replace in the target repository' description: '[Optional] The directory to wipe and replace in the target repository'
default: . default: .
required: false required: false
runs: runs:
using: docker using: docker
image: Dockerfile image: Dockerfile
@ -52,6 +57,7 @@ runs:
- '${{ inputs.source-directory }}' - '${{ inputs.source-directory }}'
- '${{ inputs.destination-github-username }}' - '${{ inputs.destination-github-username }}'
- '${{ inputs.destination-repository-name }}' - '${{ inputs.destination-repository-name }}'
- '${{ inputs.github-server }}'
- '${{ inputs.user-email }}' - '${{ inputs.user-email }}'
- '${{ inputs.user-name }}' - '${{ inputs.user-name }}'
- '${{ inputs.destination-repository-username }}' - '${{ inputs.destination-repository-username }}'

View File

@ -8,12 +8,13 @@ SOURCE_BEFORE_DIRECTORY="$1"
SOURCE_DIRECTORY="$2" SOURCE_DIRECTORY="$2"
DESTINATION_GITHUB_USERNAME="$3" DESTINATION_GITHUB_USERNAME="$3"
DESTINATION_REPOSITORY_NAME="$4" DESTINATION_REPOSITORY_NAME="$4"
USER_EMAIL="$5" GITHUB_SERVER="$5"
USER_NAME="$6" USER_EMAIL="$6"
DESTINATION_REPOSITORY_USERNAME="$7" USER_NAME="$7"
TARGET_BRANCH="$8" DESTINATION_REPOSITORY_USERNAME="$8"
COMMIT_MESSAGE="$9" TARGET_BRANCH="$9"
TARGET_DIRECTORY="${10}" COMMIT_MESSAGE="${10}"
TARGET_DIRECTORY="${11}"
if [ -z "$DESTINATION_REPOSITORY_USERNAME" ] if [ -z "$DESTINATION_REPOSITORY_USERNAME" ]
then then
@ -31,7 +32,7 @@ echo "[+] Cloning destination git repository $DESTINATION_REPOSITORY_NAME"
# Setup git # Setup git
git config --global user.email "$USER_EMAIL" git config --global user.email "$USER_EMAIL"
git config --global user.name "$USER_NAME" git config --global user.name "$USER_NAME"
git clone --single-branch --branch "$TARGET_BRANCH" "https://$USER_NAME:$API_TOKEN_GITHUB@github.com/$DESTINATION_REPOSITORY_USERNAME/$DESTINATION_REPOSITORY_NAME.git" "$CLONE_DIR" git clone --single-branch --branch "$TARGET_BRANCH" "https://$USER_NAME:$API_TOKEN_GITHUB@$GITHUB_SERVER/$DESTINATION_REPOSITORY_USERNAME/$DESTINATION_REPOSITORY_NAME.git" "$CLONE_DIR"
ls -la "$CLONE_DIR" ls -la "$CLONE_DIR"
TEMP_DIR=$(mktemp -d) TEMP_DIR=$(mktemp -d)
@ -90,7 +91,7 @@ cd "$CLONE_DIR"
echo "[+] Files that will be pushed" echo "[+] Files that will be pushed"
ls -la ls -la
ORIGIN_COMMIT="https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" ORIGIN_COMMIT="https://$GITHUB_SERVER/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
COMMIT_MESSAGE="${COMMIT_MESSAGE/ORIGIN_COMMIT/$ORIGIN_COMMIT}" COMMIT_MESSAGE="${COMMIT_MESSAGE/ORIGIN_COMMIT/$ORIGIN_COMMIT}"
COMMIT_MESSAGE="${COMMIT_MESSAGE/\$GITHUB_REF/$GITHUB_REF}" COMMIT_MESSAGE="${COMMIT_MESSAGE/\$GITHUB_REF/$GITHUB_REF}"
@ -106,4 +107,4 @@ git diff-index --quiet HEAD || git commit --message "$COMMIT_MESSAGE"
echo "[+] Pushing git commit" echo "[+] Pushing git commit"
# --set-upstream: sets de branch when pushing to a branch that does not exist # --set-upstream: sets de branch when pushing to a branch that does not exist
git push "https://$USER_NAME:$API_TOKEN_GITHUB@github.com/$DESTINATION_REPOSITORY_USERNAME/$DESTINATION_REPOSITORY_NAME.git" --set-upstream "$TARGET_BRANCH" git push "https://$USER_NAME:$API_TOKEN_GITHUB@$GITHUB_SERVER/$DESTINATION_REPOSITORY_USERNAME/$DESTINATION_REPOSITORY_NAME.git" --set-upstream "$TARGET_BRANCH"