Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ outputs:
runs:
using: composite
steps:
- name: Checkout source repository
- name: Checkout destination repository into a worktree
uses: actions/checkout@v4
with:
repository: ${{ inputs.destination-repository }}
token: ${{ inputs.token }}
ref: ${{ inputs.destination-branch }}
persist-credentials: false
path: .push-to-another-repository
- id: prepare
name: "Prepare the destination repository in the workspace before committing"
run: $GITHUB_ACTION_PATH/entrypoint.sh
shell: bash
env:
Expand All @@ -61,14 +63,15 @@ runs:
repository: ${{ inputs.destination-repository }}
commit_message: ${{ steps.prepare.outputs.commit-message }}
branch: ${{ inputs.destination-branch }}
- name: restore origin
- name: restore stashed original workspace from worktree
run: |
WORKTREE_DIR=".push-to-another-repository"
TEMP_DIR="$(mktemp -d)/$WORKTREE_DIR"
mv ./$WORKTREE_DIR "$TEMP_DIR"
rm -rf "$GITHUB_WORKSPACE"
mv "$TEMP_DIR" $GITHUB_WORKSPACE
mv "$TEMP_DIR" "$GITHUB_WORKSPACE"
shell: bash
env:
WORKTREE_DIR: .push-to-another-repository
branding:
icon: git-commit
color: green
8 changes: 4 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ COMMIT_MESSAGE="${COMMIT_MESSAGE/GITHUB_REF/$GITHUB_REF}"
echo 'EOF'
} >> "$GITHUB_OUTPUT"

echo "[+] Swap github.workspace with the cloned repository"
echo "[+] Swap github.workspace with the cloned repository to work with commit-action"
mv "$GITHUB_WORKSPACE" "$TEMP_WORKDIR/$WORKTREE_DIR"
mv "$TEMP_WORKDIR/.git" "$TEMP_WORKDIR/$WORKTREE_DIR/.git"
mv "$CLONE_DIR" "$GITHUB_WORKSPACE"
# Keep the original repository in a sub directory as worktree.
mv "$TEMP_WORKDIR/$WORKTREE_DIR" "$GITHUB_WORKSPACE/$WORKTREE_DIR"

# Stash the original workspace in a ignored worktree directory.
mv "$TEMP_WORKDIR/$WORKTREE_DIR" "$GITHUB_WORKSPACE/$WORKTREE_DIR"
cd "$GITHUB_WORKSPACE"
# The worktree directory is ignored from version control.
# The stash directory is ignored from version control.
echo "$WORKTREE_DIR" >> .git/info/exclude