mirror of
https://github.com/cpina/github-action-push-to-another-repository.git
synced 2025-09-08 01:25:46 -06:00
Compare commits
117 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7c1bd869f3 | ||
|
07c4d7b3de | ||
|
b2e2c48ca5 | ||
|
d63a102c8f | ||
|
cbe757f8d8 | ||
|
33585ea95a | ||
|
0a14457bb2 | ||
|
9e487f2958 | ||
|
f4b9c90516 | ||
|
6cb505d32f | ||
|
74596b72fa | ||
|
9391058a7d | ||
|
e775fb8544 | ||
|
cda33b879b | ||
|
f8f86f8d8f | ||
|
e9f59d2faa | ||
|
ab68811c3a | ||
|
b5ac509f7b | ||
|
47ce62aef3 | ||
|
1cdcd11404 | ||
|
1ff90e4a65 | ||
|
f973f49c62 | ||
|
3f9ba1ff0a | ||
|
9543f7e15d | ||
|
aa2fdffb28 | ||
|
ac0bb2c8f9 | ||
|
483689a71c | ||
|
084156bc22 | ||
|
418e6e7a36 | ||
|
f5b6d14ea8 | ||
|
164a872083 | ||
|
2e729bfae7 | ||
|
9077ab5399 | ||
|
23869efe3d | ||
|
331033bc0f | ||
|
b8ba82a17f | ||
|
7096925caa | ||
|
e6c065d351 | ||
|
e7314057a0 | ||
|
24c550e8a7 | ||
|
c200780764 | ||
|
6e36e20d0e | ||
|
cdae6bf3fc | ||
|
460cd93e14 | ||
|
66ead10846 | ||
|
5ca36a784d | ||
|
371fdd6652 | ||
|
df5ac1b335 | ||
|
f7a5c6e388 | ||
|
9ed2368a01 | ||
|
eb81a2a185 | ||
|
af82da7f2b | ||
|
d4122690a7 | ||
|
aa69941031 | ||
|
44d7a5c0f9 | ||
|
2708e223bc | ||
|
38d751da52 | ||
|
ed4074dd02 | ||
|
52acf3c68c | ||
|
7a8c60c186 | ||
|
b4480ee4f3 | ||
|
b646e274db | ||
|
b97d556c1d | ||
|
67a3a057c8 | ||
|
12ff072138 | ||
|
f87dd89716 | ||
|
520a9d8c28 | ||
|
448b7dad95 | ||
|
84dc6cc070 | ||
|
69e1f423c8 | ||
|
280163351f | ||
|
c3f0aa4db9 | ||
|
2ebe0cc15f | ||
|
6b89adc168 | ||
|
940a2857e5 | ||
|
637a257cca | ||
|
5c472514b3 | ||
|
cb0e53ecbe | ||
|
8e9bfb00e6 | ||
|
9b1e7ac6a5 | ||
|
3a9dc3773c | ||
|
88287f5737 | ||
|
85a0ac138a | ||
|
bb3e4ea525 | ||
|
f30895310c | ||
|
f5a3797d5b | ||
|
ec672cbc0a | ||
|
e7bc77c21d | ||
|
3d4da26ca5 | ||
|
976916018a | ||
|
ea29b5b83f | ||
|
edbe7a0efc | ||
|
9852c86807 | ||
|
eae1cf2f70 | ||
|
61d842d233 | ||
|
c26a144ee1 | ||
|
79e1b1b20b | ||
|
c6421df38d | ||
|
cfb5cb5949 | ||
|
5a00473a58 | ||
|
61d0646c22 | ||
|
da21c6b08d | ||
|
884b652fa7 | ||
|
5d8dc0fe1a | ||
|
160c443d67 | ||
|
80a683b9ad | ||
|
26fe0168e2 | ||
|
db81c54e24 | ||
|
4b313f1b76 | ||
|
a76c6fd84a | ||
|
dc3ca8455d | ||
|
b511d6418a | ||
|
b174d4c1a3 | ||
|
a69edf2ee5 | ||
|
f32c463e11 | ||
|
ece5884654 | ||
|
807f8fa4f7 |
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Bug report with a problem
|
||||||
|
title: ''
|
||||||
|
labels: bug
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
> [!WARNING]
|
||||||
|
> TL;DR: this repository is not maintained for any new development. I plan to
|
||||||
|
> fix issues if they arise due to changes on GitHub, to minimise disruption of
|
||||||
|
> existing usage.
|
||||||
|
>
|
||||||
|
> My circumstances changed since I started the GitHub Action in 2020. I am not
|
||||||
|
> able to add functionality to it or fix issues.
|
||||||
|
>
|
||||||
|
> The action is 175 lines of shell script. Feel free to fork it and modify it
|
||||||
|
> for your own use case.
|
||||||
|
>
|
||||||
|
> If you create a fork that might replace this one, I will add a note in the
|
||||||
|
> documentation and the README.md. Please, open an issue and I will do it.
|
||||||
|
|
||||||
|
|
||||||
|
Suggestion: read carefully the GitHub Action output. It might contain information that might help fixing the problem. If not please keep opening the bug report.
|
||||||
|
|
||||||
|
The [documentation](https://github.com/cpina/push-to-another-repository-docs)
|
||||||
|
might have information on what you could do to fix the problem. See the [FAQ](https://cpina.github.io/push-to-another-repository-docs/faq.html)
|
||||||
|
|
||||||
|
<!--
|
||||||
|
**Copy-paste the output of the GitHub Action**
|
||||||
|
|
||||||
|
Full output might contain useful information including the git command, git output and settings used. It also helps to search for the problem later on.
|
||||||
|
|
||||||
|
**URL to the execution**
|
||||||
|
|
||||||
|
Paste the URL of the execution where it's possible to see the problem. This will help me to see the configuration and the output in more context.
|
||||||
|
-->
|
10
.github/ISSUE_TEMPLATE/windows_mac_nodocker.md
vendored
Normal file
10
.github/ISSUE_TEMPLATE/windows_mac_nodocker.md
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
name: Windows/Mac/No Docker
|
||||||
|
about: Questions about Windows/Mac/No Docker runners
|
||||||
|
title: ''
|
||||||
|
labels: Windows-Mac-NoDocker
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Suggestion: see the relevant FAQ entry: https://cpina.github.io/push-to-another-repository-docs/faq.html#could-it-work-on-mac-os-windows-or-no-docker-environments
|
@ -1,6 +1,6 @@
|
|||||||
FROM alpine:3.10
|
FROM alpine:latest
|
||||||
|
|
||||||
RUN apk add --no-cache git
|
RUN apk add --no-cache git git-lfs openssh-client
|
||||||
|
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
|
||||||
|
72
README.md
72
README.md
@ -1,61 +1,19 @@
|
|||||||
# github-action-push-to-another-repository
|
# github-action-push-to-another-repository
|
||||||
|
|
||||||
Used to push generated files from a directory from Git Action step into another repository on Github.
|
> [!WARNING]
|
||||||
|
> TL;DR: this repository is not maintained for any new development. I plan to
|
||||||
|
> fix issues if they arise due to changes on GitHub, to minimise disruption of
|
||||||
|
> existing usage.
|
||||||
|
>
|
||||||
|
> My circumstances changed since I started the GitHub Action in 2020. I am not
|
||||||
|
> able to add functionality to it or fix issues.
|
||||||
|
>
|
||||||
|
> The action is 175 lines of shell script. Feel free to fork it and modify it
|
||||||
|
> for your own use case.
|
||||||
|
>
|
||||||
|
> If you create a fork that might replace this one, I will add a note in the
|
||||||
|
> documentation and the README.md. Please, open an issue and I will do it.
|
||||||
|
|
||||||
E.g.
|
See the extensive documentation in https://cpina.github.io/push-to-another-repository-docs/ (includes examples, FAQ, troubleshooting, etc.).
|
||||||
Repository pandoc-test contains Markdown and a Git Action to generate, using Pandoc, an output: HTML, PDF, odt, epub, etc.
|
|
||||||
|
|
||||||
Repository pandoc-test-output: contains only the generated files from the first Git Action. Pushed here with github-action-push-to-another-repository
|
GitHub repository of the documentation: https://github.com/cpina/push-to-another-repository-docs
|
||||||
|
|
||||||
And pandoc-test-output can have Git Pages to give access to the files (or just links to the raw version of the files)
|
|
||||||
|
|
||||||
## Inputs
|
|
||||||
### `source-directory` (argument)
|
|
||||||
From the repository that this Git Action is executed the directory that contains the files to be pushed into the repository.
|
|
||||||
|
|
||||||
### `destination-github-username` (argument)
|
|
||||||
For the repository `https://github.com/cpina/push-to-another-repository-output` is `cpina`. It's also used for the `Author:` in the generated git messages.
|
|
||||||
|
|
||||||
### `destination-repository-name` (argument)
|
|
||||||
For the repository `https://github.com/cpina/push-to-another-repository-output` is `push-to-another-repository-output`
|
|
||||||
|
|
||||||
### `user-email` (argument)
|
|
||||||
The email that will be used for the commit in the destination-repository-name.
|
|
||||||
|
|
||||||
### `API_TOKEN_GITHUB` (environment)
|
|
||||||
E.g.:
|
|
||||||
`API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}`
|
|
||||||
|
|
||||||
Generate your personal token following the steps:
|
|
||||||
* Go to the Github Settings (on the right hand side on the profile picture)
|
|
||||||
* On the left hand side pane click on "Developer Settings"
|
|
||||||
* Click on "Personal Access Tokens" (also available at https://github.com/settings/tokens)
|
|
||||||
* Generate a new token, choose "Repo". Copy the token.
|
|
||||||
|
|
||||||
Then make the token available to the Github Action following the steps:
|
|
||||||
* Go to the Github page for the repository that you push from, click on "Settings"
|
|
||||||
* On the left hand side pane click on "Secrets"
|
|
||||||
* Click on "Add a new secret" and name it "API_TOKEN_GITHUB"
|
|
||||||
|
|
||||||
## Example usage
|
|
||||||
```yaml
|
|
||||||
- name: Pushes to another repository
|
|
||||||
uses: cpina/github-action-push-to-another-repository@master
|
|
||||||
env:
|
|
||||||
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
|
|
||||||
with:
|
|
||||||
source-directory: 'output'
|
|
||||||
destination-github-username: 'cpina'
|
|
||||||
destination-repository-name: 'pandoc-test-output'
|
|
||||||
user-email: carles3@pina.cat
|
|
||||||
```
|
|
||||||
|
|
||||||
Working example:
|
|
||||||
|
|
||||||
https://github.com/cpina/push-to-another-repository-example/blob/master/.github/workflows/ci.yml
|
|
||||||
|
|
||||||
It generates files from:
|
|
||||||
https://github.com/cpina/push-to-another-repository-example
|
|
||||||
|
|
||||||
To:
|
|
||||||
https://github.com/cpina/push-to-another-repository-output
|
|
||||||
|
78
action.yml
78
action.yml
@ -1,26 +1,76 @@
|
|||||||
name: 'Push directory to another repository'
|
name: Push directory to another repository
|
||||||
description: 'Useful to push files to another repository to be used, for example, via github pages'
|
description: >-
|
||||||
|
Useful to push files to another repository to be used, for example, via github
|
||||||
|
pages
|
||||||
inputs:
|
inputs:
|
||||||
|
source-before-directory:
|
||||||
|
description: Source before directory from the origin directory
|
||||||
|
required: false
|
||||||
source-directory:
|
source-directory:
|
||||||
description: 'Source directory from the origin directory'
|
description: Source directory from the origin directory
|
||||||
required: true
|
required: true
|
||||||
destination-github-username:
|
destination-github-username:
|
||||||
description: 'Name of the destination username/organization'
|
description: Name of the destination username/organization
|
||||||
required: true
|
required: true
|
||||||
destination-repository-name:
|
destination-repository-name:
|
||||||
description: 'Destination repository'
|
description: Destination repository
|
||||||
required: true
|
required: true
|
||||||
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:
|
||||||
|
description: >-
|
||||||
|
[Optional] Name for the git commit. Defaults to the destination
|
||||||
|
username/organization name
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
destination-repository-username:
|
||||||
|
description: '[Optional] Username/organization for the destination repository'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
target-branch:
|
||||||
|
description: >-
|
||||||
|
[Optional] set target branch name for the destination repository. Defaults
|
||||||
|
to "main"
|
||||||
|
default: main
|
||||||
|
required: false
|
||||||
|
commit-message:
|
||||||
|
description: >-
|
||||||
|
[Optional] commit message for the output repository. ORIGIN_COMMIT is
|
||||||
|
replaced by the URL@commit in the origin repo
|
||||||
|
default: Update from ORIGIN_COMMIT
|
||||||
|
required: false
|
||||||
|
target-directory:
|
||||||
|
description: '[Optional] The directory to wipe and replace in the target repository'
|
||||||
|
default: ''
|
||||||
|
required: false
|
||||||
|
create-target-branch-if-needed:
|
||||||
|
type: boolean
|
||||||
|
description: >-
|
||||||
|
[Optional] create target branch if not exist. Defaults to `false`
|
||||||
|
default: false
|
||||||
|
required: false
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: docker
|
||||||
image: 'Dockerfile'
|
image: Dockerfile
|
||||||
args:
|
args:
|
||||||
- ${{ inputs.source-directory }}
|
- '${{ inputs.source-before-directory }}'
|
||||||
- ${{ inputs.destination-github-username }}
|
- '${{ inputs.source-directory }}'
|
||||||
- ${{ inputs.destination-repository-name }}
|
- '${{ inputs.destination-github-username }}'
|
||||||
- ${{ inputs.user-email }}
|
- '${{ inputs.destination-repository-name }}'
|
||||||
|
- '${{ inputs.github-server }}'
|
||||||
|
- '${{ inputs.user-email }}'
|
||||||
|
- '${{ inputs.user-name }}'
|
||||||
|
- '${{ inputs.destination-repository-username }}'
|
||||||
|
- '${{ inputs.target-branch }}'
|
||||||
|
- '${{ inputs.commit-message }}'
|
||||||
|
- '${{ inputs.target-directory }}'
|
||||||
|
- '${{ inputs.create-target-branch-if-needed }}'
|
||||||
branding:
|
branding:
|
||||||
icon: 'git-commit'
|
icon: git-commit
|
||||||
color: 'green'
|
color: green
|
||||||
|
172
entrypoint.sh
172
entrypoint.sh
@ -1,29 +1,175 @@
|
|||||||
#!/bin/sh -l
|
#!/bin/sh -l
|
||||||
|
|
||||||
echo "Starts"
|
set -e # if a command fails it stops the execution
|
||||||
FOLDER="$1"
|
set -u # script fails if trying to access to an undefined variable
|
||||||
GITHUB_USERNAME="$2"
|
|
||||||
GITHUB_REPO="$3"
|
echo "[+] Action start"
|
||||||
USER_EMAIL="$4"
|
SOURCE_BEFORE_DIRECTORY="${1}"
|
||||||
|
SOURCE_DIRECTORY="${2}"
|
||||||
|
DESTINATION_GITHUB_USERNAME="${3}"
|
||||||
|
DESTINATION_REPOSITORY_NAME="${4}"
|
||||||
|
GITHUB_SERVER="${5}"
|
||||||
|
USER_EMAIL="${6}"
|
||||||
|
USER_NAME="${7}"
|
||||||
|
DESTINATION_REPOSITORY_USERNAME="${8}"
|
||||||
|
TARGET_BRANCH="${9}"
|
||||||
|
COMMIT_MESSAGE="${10}"
|
||||||
|
TARGET_DIRECTORY="${11}"
|
||||||
|
CREATE_TARGET_BRANCH_IF_NEEDED="${12}"
|
||||||
|
|
||||||
|
if [ -z "$DESTINATION_REPOSITORY_USERNAME" ]
|
||||||
|
then
|
||||||
|
DESTINATION_REPOSITORY_USERNAME="$DESTINATION_GITHUB_USERNAME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$USER_NAME" ]
|
||||||
|
then
|
||||||
|
USER_NAME="$DESTINATION_GITHUB_USERNAME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify that there (potentially) some access to the destination repository
|
||||||
|
# and set up git (with GIT_CMD variable) and GIT_CMD_REPOSITORY
|
||||||
|
if [ -n "${SSH_DEPLOY_KEY:=}" ]
|
||||||
|
then
|
||||||
|
echo "[+] Using SSH_DEPLOY_KEY"
|
||||||
|
|
||||||
|
# Inspired by https://github.com/leigholiver/commit-with-deploy-key/blob/main/entrypoint.sh , thanks!
|
||||||
|
mkdir --parents "$HOME/.ssh"
|
||||||
|
DEPLOY_KEY_FILE="$HOME/.ssh/deploy_key"
|
||||||
|
echo "${SSH_DEPLOY_KEY}" > "$DEPLOY_KEY_FILE"
|
||||||
|
chmod 600 "$DEPLOY_KEY_FILE"
|
||||||
|
|
||||||
|
SSH_KNOWN_HOSTS_FILE="$HOME/.ssh/known_hosts"
|
||||||
|
ssh-keyscan -H "$GITHUB_SERVER" > "$SSH_KNOWN_HOSTS_FILE"
|
||||||
|
|
||||||
|
export GIT_SSH_COMMAND="ssh -i "$DEPLOY_KEY_FILE" -o UserKnownHostsFile=$SSH_KNOWN_HOSTS_FILE"
|
||||||
|
|
||||||
|
GIT_CMD_REPOSITORY="git@$GITHUB_SERVER:$DESTINATION_REPOSITORY_USERNAME/$DESTINATION_REPOSITORY_NAME.git"
|
||||||
|
|
||||||
|
elif [ -n "${API_TOKEN_GITHUB:=}" ]
|
||||||
|
then
|
||||||
|
echo "[+] Using API_TOKEN_GITHUB"
|
||||||
|
GIT_CMD_REPOSITORY="https://$DESTINATION_REPOSITORY_USERNAME:$API_TOKEN_GITHUB@$GITHUB_SERVER/$DESTINATION_REPOSITORY_USERNAME/$DESTINATION_REPOSITORY_NAME.git"
|
||||||
|
else
|
||||||
|
echo "::error::API_TOKEN_GITHUB and SSH_DEPLOY_KEY are empty. Please fill one (recommended the SSH_DEPLOY_KEY)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
CLONE_DIR=$(mktemp -d)
|
CLONE_DIR=$(mktemp -d)
|
||||||
|
|
||||||
|
echo "[+] Git version"
|
||||||
|
git --version
|
||||||
|
|
||||||
|
echo "[+] Enable git lfs"
|
||||||
|
git lfs install
|
||||||
|
|
||||||
|
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 "$GITHUB_USERNAME"
|
git config --global user.name "$USER_NAME"
|
||||||
git clone "https://$API_TOKEN_GITHUB@github.com/$GITHUB_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR"
|
|
||||||
|
|
||||||
|
# workaround for https://github.com/cpina/github-action-push-to-another-repository/issues/103
|
||||||
|
git config --global http.version HTTP/1.1
|
||||||
|
|
||||||
|
{
|
||||||
|
git clone --single-branch --depth 1 --branch "$TARGET_BRANCH" "$GIT_CMD_REPOSITORY" "$CLONE_DIR"
|
||||||
|
} || {
|
||||||
|
if [ "$CREATE_TARGET_BRANCH_IF_NEEDED" = "true" ]
|
||||||
|
then
|
||||||
|
# Default branch of the repository is cloned. Later on the required branch
|
||||||
|
# will be created
|
||||||
|
git clone --single-branch --depth 1 "$GIT_CMD_REPOSITORY" "$CLONE_DIR"
|
||||||
|
else
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
} || {
|
||||||
|
echo "::error::Could not clone the destination repository. Command:"
|
||||||
|
echo "::error::git clone --single-branch --branch $TARGET_BRANCH $GIT_CMD_REPOSITORY $CLONE_DIR"
|
||||||
|
echo "::error::(Note that if they exist USER_NAME and API_TOKEN is redacted by GitHub)"
|
||||||
|
echo "::error::Please verify that the target repository exist AND that it contains the destination branch name, and is accesible by the API_TOKEN_GITHUB OR SSH_DEPLOY_KEY"
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
}
|
||||||
ls -la "$CLONE_DIR"
|
ls -la "$CLONE_DIR"
|
||||||
|
|
||||||
# Copy files into the git and deletes all git
|
TEMP_DIR=$(mktemp -d)
|
||||||
find "$CLONE_DIR" | grep -v "^$CLONE_DIR/\.git" | grep -v "^$CLONE_DIR$" | xargs rm -rf # delete all files (to handle deletions)
|
# This mv has been the easier way to be able to remove files that were there
|
||||||
|
# but not anymore. Otherwise we had to remove the files from "$CLONE_DIR",
|
||||||
|
# including "." and with the exception of ".git/"
|
||||||
|
mv "$CLONE_DIR/.git" "$TEMP_DIR/.git"
|
||||||
|
|
||||||
ls -la "$CLONE_DIR"
|
# $TARGET_DIRECTORY is '' by default
|
||||||
|
ABSOLUTE_TARGET_DIRECTORY="$CLONE_DIR/$TARGET_DIRECTORY/"
|
||||||
|
|
||||||
cp -r "$FOLDER"/* "$CLONE_DIR"
|
echo "[+] Deleting $ABSOLUTE_TARGET_DIRECTORY"
|
||||||
|
rm -rf "$ABSOLUTE_TARGET_DIRECTORY"
|
||||||
|
|
||||||
|
echo "[+] Creating (now empty) $ABSOLUTE_TARGET_DIRECTORY"
|
||||||
|
mkdir -p "$ABSOLUTE_TARGET_DIRECTORY"
|
||||||
|
|
||||||
|
echo "[+] Listing Current Directory Location"
|
||||||
|
ls -al
|
||||||
|
|
||||||
|
echo "[+] Listing root Location"
|
||||||
|
ls -al /
|
||||||
|
|
||||||
|
mv "$TEMP_DIR/.git" "$CLONE_DIR/.git"
|
||||||
|
|
||||||
|
echo "[+] List contents of $SOURCE_DIRECTORY"
|
||||||
|
ls "$SOURCE_DIRECTORY"
|
||||||
|
|
||||||
|
echo "[+] Checking if local $SOURCE_DIRECTORY exist"
|
||||||
|
if [ ! -d "$SOURCE_DIRECTORY" ]
|
||||||
|
then
|
||||||
|
echo "ERROR: $SOURCE_DIRECTORY does not exist"
|
||||||
|
echo "This directory needs to exist when push-to-another-repository is executed"
|
||||||
|
echo
|
||||||
|
echo "In the example it is created by ./build.sh: https://github.com/cpina/push-to-another-repository-example/blob/main/.github/workflows/ci.yml#L19"
|
||||||
|
echo
|
||||||
|
echo "If you want to copy a directory that exist in the source repository"
|
||||||
|
echo "to the target repository: you need to clone the source repository"
|
||||||
|
echo "in a previous step in the same build section. For example using"
|
||||||
|
echo "actions/checkout@v2. See: https://github.com/cpina/push-to-another-repository-example/blob/main/.github/workflows/ci.yml#L16"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[+] Copying contents of source repository folder $SOURCE_DIRECTORY to folder $TARGET_DIRECTORY in git repo $DESTINATION_REPOSITORY_NAME"
|
||||||
|
cp -ra "$SOURCE_DIRECTORY"/. "$CLONE_DIR/$TARGET_DIRECTORY"
|
||||||
cd "$CLONE_DIR"
|
cd "$CLONE_DIR"
|
||||||
|
|
||||||
|
echo "[+] Files that will be pushed"
|
||||||
|
ls -la
|
||||||
|
|
||||||
|
ORIGIN_COMMIT="https://$GITHUB_SERVER/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
|
||||||
|
COMMIT_MESSAGE="${COMMIT_MESSAGE/ORIGIN_COMMIT/$ORIGIN_COMMIT}"
|
||||||
|
COMMIT_MESSAGE="${COMMIT_MESSAGE/\$GITHUB_REF/$GITHUB_REF}"
|
||||||
|
|
||||||
|
echo "[+] Set directory is safe ($CLONE_DIR)"
|
||||||
|
# Related to https://github.com/cpina/github-action-push-to-another-repository/issues/64
|
||||||
|
git config --global --add safe.directory "$CLONE_DIR"
|
||||||
|
|
||||||
|
if [ "$CREATE_TARGET_BRANCH_IF_NEEDED" = "true" ]
|
||||||
|
then
|
||||||
|
echo "[+] Switch to the TARGET_BRANCH"
|
||||||
|
# || true: if the $TARGET_BRANCH already existed in the destination repo:
|
||||||
|
# it is already the current branch and it cannot be switched to
|
||||||
|
# (it's not needed)
|
||||||
|
# If the branch did not exist: it switches (creating) the branch
|
||||||
|
git switch -c "$TARGET_BRANCH" || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[+] Adding git commit"
|
||||||
git add .
|
git add .
|
||||||
git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA)"
|
|
||||||
git push origin master
|
echo "[+] git status:"
|
||||||
|
git status
|
||||||
|
|
||||||
|
echo "[+] git diff-index:"
|
||||||
|
# git diff-index : to avoid doing the git commit failing if there are no changes to be commit
|
||||||
|
git diff-index --quiet HEAD || git commit --message "$COMMIT_MESSAGE"
|
||||||
|
|
||||||
|
echo "[+] Pushing git commit"
|
||||||
|
# --set-upstream: sets de branch when pushing to a branch that does not exist
|
||||||
|
git push "$GIT_CMD_REPOSITORY" --set-upstream "$TARGET_BRANCH"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user