Skip to content

Commit fd0666b

Browse files
authored
Merge pull request #43 from Songmu/revert-41-fix-location
Revert "refactor: simplify workspace handling"
2 parents 1c1460b + 415d77a commit fd0666b

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

action.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ runs:
4848
persist-credentials: false
4949
path: .push-to-another-repository
5050
- id: prepare
51-
name: "Prepare the destination repository in the worktree before committing"
51+
name: "Prepare the destination repository in the workspace before committing"
5252
run: $GITHUB_ACTION_PATH/entrypoint.sh
5353
shell: bash
5454
env:
@@ -63,7 +63,6 @@ runs:
6363
repository: ${{ inputs.destination-repository }}
6464
commit_message: ${{ steps.prepare.outputs.commit-message }}
6565
branch: ${{ inputs.destination-branch }}
66-
working-directory: .push-to-another-repository
6766
continue-on-error: true
6867
- id: fallback
6968
name: fallback to git command for large assets
@@ -82,12 +81,14 @@ runs:
8281
COMMIT_MESSAGE: ${{ steps.prepare.outputs.commit-message }}
8382
DESTINATION_BRANCH: ${{ inputs.destination-branch }}
8483
DESTINATION_REPOSITORY: ${{ inputs.destination-repository }}
85-
working-directory: .push-to-another-repository
8684
continue-on-error: true
8785
shell: bash
88-
- name: remove worktree
86+
- name: restore stashed original workspace from worktree
8987
run: |
90-
rm -rf "$WORKTREE_DIR"
88+
TEMP_DIR="$(mktemp -d)/$WORKTREE_DIR"
89+
mv ./$WORKTREE_DIR "$TEMP_DIR"
90+
rm -rf "$GITHUB_WORKSPACE"
91+
mv "$TEMP_DIR" "$GITHUB_WORKSPACE"
9192
shell: bash
9293
if: always()
9394
env:

entrypoint.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@ mkdir -p "$ABSOLUTE_DESTINATION_DIRECTORY"
2424

2525
mv "$TEMP_WORKDIR/.git" "$CLONE_DIR/.git"
2626

27-
echo "[+] Evacuating source .git directory to avoid conflicts when mirroring the root directory"
28-
mv "./.git" "$TEMP_WORKDIR/.git"
27+
echo "[+] evacuate source .git directory to avoid conflicts when mirroring the root directory"
28+
mv "$GITHUB_WORKSPACE/.git" "$TEMP_WORKDIR/.git"
2929

3030
echo "[+] Copying contents of source repository folder $SOURCE_DIRECTORY to folder $DESTINATION_DIRECTORY in destination repository"
3131
cp -ra "$SOURCE_DIRECTORY"/. "$CLONE_DIR/$DESTINATION_DIRECTORY"
3232

33-
echo "[+] Restoring source .git directory"
34-
mv "$TEMP_WORKDIR/.git" "./.git"
35-
36-
echo "[+] Moving cloned repository to $WORKTREE_DIR in the workspace"
37-
mv "$CLONE_DIR" "./$WORKTREE_DIR"
38-
33+
cd "$CLONE_DIR"
3934
echo "[+] Building commit message"
4035
COMMIT_MESSAGE="${COMMIT_MESSAGE/LAST_COMMIT_MESSAGE/$LAST_COMMIT_MESSAGE}"
4136
ORIGIN_COMMIT="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
@@ -46,3 +41,14 @@ COMMIT_MESSAGE="${COMMIT_MESSAGE/GITHUB_REF/$GITHUB_REF}"
4641
echo "$COMMIT_MESSAGE"
4742
echo 'EOF'
4843
} >> "$GITHUB_OUTPUT"
44+
45+
echo "[+] Swap github.workspace with the cloned repository to work with commit-action"
46+
mv "$GITHUB_WORKSPACE" "$TEMP_WORKDIR/$WORKTREE_DIR"
47+
mv "$TEMP_WORKDIR/.git" "$TEMP_WORKDIR/$WORKTREE_DIR/.git"
48+
mv "$CLONE_DIR" "$GITHUB_WORKSPACE"
49+
50+
# Stash the original workspace in a ignored worktree directory.
51+
mv "$TEMP_WORKDIR/$WORKTREE_DIR" "$GITHUB_WORKSPACE/$WORKTREE_DIR"
52+
cd "$GITHUB_WORKSPACE"
53+
# The stash directory is ignored from version control.
54+
echo "$WORKTREE_DIR" >> .git/info/exclude

0 commit comments

Comments
 (0)