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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable using worktrees #829

Closed
wants to merge 7 commits into from
Closed

enable using worktrees #829

wants to merge 7 commits into from

Conversation

lvlrt
Copy link

@lvlrt lvlrt commented Sep 27, 2021

  • Enables using act in a worktree of Git (needs to follow the .git file directions)

@lvlrt lvlrt requested a review from a team as a code owner September 27, 2021 15:42
@mergify mergify bot added the needs-work Extra attention is needed label Sep 27, 2021
@codecov
Copy link

codecov bot commented Sep 27, 2021

Codecov Report

Merging #829 (4918f2f) into master (0f04942) will increase coverage by 9.75%.
The diff coverage is 66.24%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #829      +/-   ##
==========================================
+ Coverage   49.27%   59.02%   +9.75%     
==========================================
  Files          23       25       +2     
  Lines        2401     4288    +1887     
==========================================
+ Hits         1183     2531    +1348     
- Misses       1090     1569     +479     
- Partials      128      188      +60     
Impacted Files Coverage Δ
pkg/container/docker_run.go 7.08% <25.22%> (+5.15%) ⬆️
pkg/common/git.go 46.27% <25.45%> (-13.52%) ⬇️
pkg/model/planner.go 49.78% <42.50%> (+16.70%) ⬆️
pkg/model/workflow.go 52.14% <63.63%> (+26.42%) ⬆️
pkg/container/docker_pull.go 39.18% <65.51%> (+21.00%) ⬆️
pkg/runner/runner.go 76.72% <70.96%> (+0.25%) ⬆️
pkg/runner/expression.go 85.71% <72.09%> (-0.93%) ⬇️
pkg/runner/step_context.go 86.18% <89.47%> (+17.23%) ⬆️
pkg/runner/run_context.go 87.15% <92.72%> (+10.74%) ⬆️
pkg/container/docker_build.go 76.13% <100.00%> (+76.13%) ⬆️
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a0d3602...4918f2f. Read the comment docs.

@mergify

This comment has been minimized.

@nektos nektos deleted a comment from mergify bot Sep 27, 2021
@mergify
Copy link
Contributor

mergify bot commented Sep 27, 2021

@lvlrt this pull request has failed checks 🛠

Copy link
Member

@catthehacker catthehacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+ // nolint:gocyclo
  func findGitDirectory(fromFile string) (string, error) {

@mergify

This comment has been minimized.

@mergify mergify bot removed the needs-work Extra attention is needed label Sep 27, 2021
@mergify mergify bot requested a review from a team September 27, 2021 21:20
@catthehacker
Copy link
Member

Is it possible to have a git worktree on GitHub or some easy instructions to test the change? @lvlrt

Copy link
Member

@catthehacker catthehacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, it looks good to me but I never used git worktree nor know how they work

@mergify mergify bot requested a review from a team September 27, 2021 22:22
@lvlrt
Copy link
Author

lvlrt commented Sep 28, 2021

Is it possible to have a git worktree on GitHub or some easy instructions to test the change? @lvlrt

Absolutely,
A description how you'd typically use them is here: https://infrequently.org/2021/07/worktrees-step-by-step/

Tldr;

# create a directory for your worktree(s) to keep them clean & neat
mkdir act.git
cd act.git

# clone the bare repo for git operations & point to it
git clone --bare git@github.com:nektos/act.git .bare
echo "gitdir: ./.bare" > .git

# (start actual work) create a worktree
git worktree add master

# go in the worktree & test my change ;)
cd master
act # no errors should pop-up

Let me know if this clarifies the change

@catthehacker
Copy link
Member

I'm asking this since it would be great if it's possible to add a testcase

@github-actions
Copy link
Contributor

PR is stale and will be closed in 14 days unless there is new activity

@github-actions github-actions bot added the stale label Oct 29, 2021
@github-actions github-actions bot closed this Nov 12, 2021
@catthehacker catthehacker reopened this Nov 13, 2021
@catthehacker
Copy link
Member

this doesn't seem to work for me

  ~/go/src/github.com/nektos/act git-worktrees *25 !1 ?5 ❯ go run main.go -C pkg/runner/testdata/git-worktree/master/                                                                                                                                                                                                                                                                                                                                                          03:40:45 PM
WARN[0000] unable to get git revision: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git ref: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
[release/release] 🚀  Start image=catthehacker/ubuntu:act-latest
WARN[0000] unable to get git revision: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git ref: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
[release/release]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=false
[release/release]   🐳  docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[release/release]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[release/release]   🐳  docker exec cmd=[mkdir -m 0777 -p /var/run/act] user=root workdir=
[release/release]   🐳  docker cp src=/home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/master/. dst=/home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/master
[release/release]   🐳  docker exec cmd=[mkdir -p /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/master] user= workdir=
WARN[0000] unable to get git revision: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git ref: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git revision: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git ref: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git revision: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git ref: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
[release/release] ⭐  Run actions/checkout@v2
WARN[0000] unable to get git revision: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git ref: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git revision: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git ref: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git revision: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git ref: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
[release/release]   ✅  Success - actions/checkout@v2
WARN[0000] unable to get git revision: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git ref: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git revision: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git ref: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git revision: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git ref: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
[release/release] ⭐  Run actions/setup-go@v2
WARN[0000] unable to get git revision: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
WARN[0000] unable to get git ref: open /home/cat/go/src/github.com/nektos/act/pkg/runner/testdata/git-worktree/.bare/refs/heads/master: no such file or directory
INFO[0000]   ☁  git clone 'https://github.com/actions/setup-go' # ref=v2
[release/release]   🐳  docker cp src=/home/cat/.cache/act/actions-setup-go@v2/ dst=/var/run/act/actions/actions-setup-go@v2/
[release/release]   🐳  docker exec cmd=[mkdir -p /var/run/act/actions/actions-setup-go@v2/] user= workdir=
[release/release]   🐳  docker exec cmd=[node /var/run/act/actions/actions-setup-go@v2/dist/index.js] user= workdir=

@catthehacker catthehacker added stale-exempt Exempt from stale and removed stale labels Nov 13, 2021
@KnisterPeter
Copy link
Member

@lvlrt This doesn't work as expected, since act is not working with bare repositories right now.

Act expects the .git folder to be a regular checkout. As you can see in this example, act is navigating from the .git folder.
Also other operations might need patches if the clone is a bare clone.

@jasonk
Copy link

jasonk commented Dec 1, 2021

Support for a bare clone should probably be something different from support for worktrees. You can use worktrees without a bare clone too.

❯ git clone https://github.com/nektos/act
Cloning into 'act'...
remote: Enumerating objects: 6186, done.
remote: Counting objects: 100% (1274/1274), done.
remote: Compressing objects: 100% (289/289), done.
remote: Total 6186 (delta 1132), reused 1003 (delta 981), pack-reused 4912
Receiving objects: 100% (6186/6186), 5.22 MiB | 5.78 MiB/s, done.
Resolving deltas: 100% (3169/3169), done.

❯ cd act

❯ git worktree add ../pr-829
Preparing worktree (new branch 'pr-829')
HEAD is now at b910a42 Docker auth (#891)

❯ cd ../pr-829

❯ cat .git
gitdir: /Users/jasonk/act/.git/worktrees/pr-829

@KnisterPeter
Copy link
Member

But it will still not work with the current implementation, as act is working on the root working copy.
That need to be changed in this PR.

@grigorye
Copy link
Contributor

Just in case, really looking for this to be implemented. If you need some help with worktrees/testing, please just let me know.

@catthehacker
Copy link
Member

@grigorye as stated above, it doesn't currently work and original PR author is not responding.
Me and (probably rest of maintainers) don't have time nor see it as priority to work on this.
I also barely know worktrees and whole concept is rather confusing to me.
I'm going to close this unless original PR author responds. You can checkout their branch and improve upon it.

@grigorye
Copy link
Contributor

grigorye commented May 19, 2022

@catthehacker Thanks for letting me know – I'll try to take a look. I have basically zero Go knowledge, though.

Btw, I can highly recommend taking a look at Git worktrees - if you like act, I guess you'll like worktrees as well: act makes GHA iteration cheaper/faster, worktrees make Git cloning/branching cheaper/faster/more effective as well. (And, just to mention it, it's now a standard Git feature, so it's supported by every valid Git client "out-of-box").

@catthehacker
Copy link
Member

if you like act

to be completely honest, I don't use it 😳

Btw, I can highly recommend taking a look at Git worktrees

I'll figure it out someday when I'll have time 😉 and look at implementing it in act

@grigorye
Copy link
Contributor

grigorye commented May 27, 2022

Just in case, at quick glance, this PR works fine in my case (I really appreciate it, @lvlrt). I don't use bare clones though, rather just add worktrees to a "normal clone". This is probably in sync with the note from @jasonk.

Ah, never mind - I used act -b, so it looks like that Git-related code path was not exercised at all... :-( Sorry for the confusion!

Will investigate it further.

@grigorye
Copy link
Contributor

grigorye commented May 27, 2022

But it will still not work with the current implementation, as act is working on the root working copy.
That need to be changed in this PR.

@KnisterPeter Can you please explain/elaborate on this a bit? Git worktree does not change the root of working copy. It just changes the real location of .git data. And the latter seems to be reflected in this very PR?

@lavigne958
Copy link
Contributor

Hi everyone, I had a look at the PR, ran a couple of scenarios with bare clone -> worktree and regular clone -> worktree.
I noticed a difference between both for sure, but I have an idea on how to solve it.

Any new on how I can give it chance to solve it opening some PR and mention @lvlrt as contributor too (as I will use most of his code in my fix ) ? 🤔

I though I can cherry-pick his/her commits may be ?

Thank you.

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

Successfully merging this pull request may close these issues.

None yet

6 participants