Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split with new files #13

Closed
ajardin opened this issue Jun 15, 2021 · 12 comments 路 Fixed by #14
Closed

Split with new files #13

ajardin opened this issue Jun 15, 2021 · 12 comments 路 Fixed by #14

Comments

@ajardin
Copy link
Contributor

ajardin commented Jun 15, 2021

Hello and thanks for your amazing work (@rectorphp user here)! 馃槈

From what I understand, the split only works with existing files on both sides. If I add a new file, the split does nothing ([NOTE] No files to change instead of [NOTE] Adding git commit). Is it possible to force the indexation of new changes?

I assume it's related to this line, but I wanted your point of view before submitting any changes.

@TomasVotruba
Copy link
Collaborator

TomasVotruba commented Jun 15, 2021

Hi, thanks for reaching out :)

The split works on existing file on the split repository.
New files are split too :)

Maybe a different question... what exactly is your issue with the splitting right now?

@ajardin
Copy link
Contributor Author

ajardin commented Jun 15, 2021

Thanks for your quick response!

Basically, I have a repository where I store all my Docker images and I want to split it to take advantage of the build on Docker Hub instead of GitHub Actions.

Here are some logs with an empty repository.

[NOTE] Starting...



[NOTE] Cloning "https://github.com/origamiphp/docker-blackfire-entrypoint.git" repository to "/tmp/monorepo_split/clone_directory" directory



[NOTE] Running: git clone -- https://***@github.com/origamiphp/docker-blackfire-entrypoint.git /tmp/monorepo_split/clone_directory

Cloning into '/tmp/monorepo_split/clone_directory'...
warning: You appear to have cloned an empty repository.


[NOTE] Cleaning destination repository of old files



[NOTE] Copying contents to git repo of 'main' branch

fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.

Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

[NOTE] Files that will be pushed

total 28
drwxr-xr-x 3 1001  121 4096 Jun 15 22:11 .
drwxr-xr-x 3 root root 4096 Jun 15 22:11 ..
drwxr-xr-x 7 root root 4096 Jun 15 22:11 .git
-rw-r--r-- 1 1001  121  436 Jun 15 22:11 Dockerfile
-rw-r--r-- 1 1001  121 1086 Jun 15 22:11 LICENSE
-rw-r--r-- 1 1001  121  585 Jun 15 22:11 README.md
-rw-r--r-- 1 1001  121 1010 Jun 15 22:11 entrypoint.sh

[NOTE] Changing directory from "/github/workspace" to "/tmp/monorepo_split/build_directory"

On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	Dockerfile
	LICENSE
	README.md
	entrypoint.sh

nothing added to commit but untracked files present (use "git add" to track)

[NOTE] No files to change



[NOTE] Changing directory from "/tmp/monorepo_split/build_directory" to "/github/workspace"

Here are some logs with an already initialised repository.

[NOTE] Starting...



[NOTE] Cloning "https://github.com/origamiphp/docker-blackfire-entrypoint.git" repository to "/tmp/monorepo_split/clone_directory" directory



[NOTE] Running: git clone -- https://***@github.com/origamiphp/docker-blackfire-entrypoint.git /tmp/monorepo_split/clone_directory

Cloning into '/tmp/monorepo_split/clone_directory'...


[NOTE] Cleaning destination repository of old files



[NOTE] Copying contents to git repo of 'main' branch



[NOTE] Files that will be pushed

total 28
drwxr-xr-x 3 1001  121 4096 Jun 15 22:18 .
drwxr-xr-x 3 root root 4096 Jun 15 22:18 ..
drwxr-xr-x 8 root root 4096 Jun 15 22:18 .git
-rw-r--r-- 1 1001  121  436 Jun 15 22:18 Dockerfile
-rw-r--r-- 1 1001  121 1086 Jun 15 22:18 LICENSE
-rw-r--r-- 1 1001  121  585 Jun 15 22:18 README.md
-rw-r--r-- 1 1001  121 1010 Jun 15 22:18 entrypoint.sh

[NOTE] Changing directory from "/github/workspace" to "/tmp/monorepo_split/build_directory"

On branch main
Your branch is up to date with 'origin/main'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	LICENSE

nothing added to commit but untracked files present (use "git add" to track)

[NOTE] No files to change



[NOTE] Changing directory from "/tmp/monorepo_split/build_directory" to "/github/workspace"

In both cases, my "new" files are not pushed to the split repository. But if I update one of the existing files, the split is correctly handled. 馃槙

@TomasVotruba
Copy link
Collaborator

I don't have any experience with Docker hub splits, so I can't really help there.
On GitHub Actions splits works well. It might help if the remote branch should exist.

@ajardin
Copy link
Contributor Author

ajardin commented Jun 15, 2021

I don't have any experience with Docker hub splits, so I can't really help there.

I probably expressed myself poorly, sorry... Let me rephrase. 馃槄

Here is my expected workflow.

  1. Commit something on the mono-repository
  2. Trigger a split according to subdirectories (example)
  3. Docker Hub automatically detects the change and builds the associated image (not your problem)

On GitHub Actions splits works well. It might help if the remote branch should exist.

I'm not sure to understand as I have a main branch on both repositories.

@TomasVotruba
Copy link
Collaborator

TomasVotruba commented Jun 16, 2021

I see, I understand this more clearly now. Thanks 馃憤

Just to verify, the https://github.com/origamiphp/docker-blackfire-entrypoint is complete, but LICENSE file is missing?

This is the directory that should be split? https://github.com/origamiphp/docker-images/tree/main/common/blackfire-entrypoint

The GitHub Actions setup seems correct, not sure what is wrong.

@ajardin
Copy link
Contributor Author

ajardin commented Jun 16, 2021

Your two assumptions are correct, and I don't understand this either. 馃檭

I will try to take some time today to investigate further.

@TomasVotruba
Copy link
Collaborator

Just a tip: when I try to debug the split, I usually start with single directory and single file. One can get easily lost if there is over 20 files to work with. Often it's some triviality like wrong directory, slashes path, confused setup directory vs repository in the Github action etc.

It saves me some sleep-less night to create just 1 repository with 1 file in 1 directory and try to split it into 1 remote repository that should contain just 1 file.

@ajardin
Copy link
Contributor Author

ajardin commented Jun 16, 2021

I've done some more tests, and I really can't see which error in my setup would cause only changes to existing files to be pushed. So, I tested another approach by looking at the instruction that checks if there are any changes.

I can reproduce the issue locally with raw Git commands only, as you can see in the following snippet. From my point of view, it would be safer to use something like git status --porcelain instead of git diff-index --quiet HEAD.

What do you think?

#!/usr/bin/env bash

# Initialize the local test repository
mkdir -p tests
cd tests
git init --quiet
touch foo.txt
git add foo.txt
git commit --message="Initial commit" --quiet

# Test with an addition of a new file
touch bar.txt
git diff-index --quiet HEAD
echo "Addition exit code = "$?

# Test with a modification to an existing file
echo "Hello world" > foo.txt
git diff-index --quiet HEAD
echo "Modification exit code = "$?

# Remove the local test repository
cd ..
rm -rf tests
$ bash test.sh
Addition exit code = 0
Modification exit code = 1

@TomasVotruba
Copy link
Collaborator

I have no idea how git works on this level. Basically I've hacked this when needed and try to fix if something is broken :)

Would you suggest to change this in GitHub action? Would it solve your issue?
We can give it a try, then you run the action in dev version to verify. Then we can revert in case of troubles

@ajardin
Copy link
Contributor Author

ajardin commented Jun 16, 2021

This change would probably allow the script to handle more cases and solve my issue, but I want to do further testing to ensure there are no side effects. I will send you a pull request if my tests are okay, perhaps tomorrow.

@ajardin
Copy link
Contributor Author

ajardin commented Jun 28, 2021

@TomasVotruba It seems to work as expected. 馃コ

I have configured the split of 1 repository to 10 other repositories with success. My test scenario involved updating one file (README.md) with new ones (at least one Dockerfile).

Just a small note, because I was afraid I had broken something, we'll have to update the documentation before doing the next release. The names of the inputs have indeed been changed in the meantime (source). I could prepare the PR if you want.

Thanks again for your work!

@TomasVotruba
Copy link
Collaborator

Thanks for testing and sharing real repository where I can see the results easily 馃憤

I could prepare the PR if you want.

That would be great 馃檪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants