WIP: Use hashed uses string as cache dir name #100

Closed
Kwonunn wants to merge 8 commits from Kwonunn/act:fs-credential-leak into main
Member

Apply fix from https://gitea.com/gitea/act/pulls/117

Added at the request of pj in Forgejo Matrix chat.

Apply fix from https://gitea.com/gitea/act/pulls/117 Added at the request of pj in Forgejo Matrix chat.
Contributor

cascading-pr updated at forgejo/runner#462

cascading-pr updated at https://code.forgejo.org/forgejo/runner/pulls/462
@ -717,0 +719,4 @@
// UsesHash returns a hash of the uses string.
// For Gitea.
func (s *Step) UsesHash() string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(s.Uses)))

i would suggest to use an additional subdir, so we don't get too many folders on one level

hash := sha256.Sum256([]byte(s.Uses))
return fmt.Sprintf("%x/%x", hash[:2], hash)
i would suggest to use an additional subdir, so we don't get too many folders on one level ```go hash := sha256.Sum256([]byte(s.Uses)) return fmt.Sprintf("%x/%x", hash[:2], hash) ```
Author
Member

in this case if the hash were deadbeef your code would produce the path de/deadbeef whereas other implementations of this pattern (like git itself) would do de/adbeef. i'm just going to go with the second one, unless that's causing some problem i'm missing?

in this case if the hash were `deadbeef` your code would produce the path `de/deadbeef` whereas other implementations of this pattern (like git itself) would do `de/adbeef`. i'm just going to go with the second one, unless that's causing some problem i'm missing?

sure, please do

sure, please do
viceice marked this conversation as resolved
@ -533,3 +533,3 @@
if _, ok := step.(*stepActionRemote); ok {
actionPath = newRemoteAction(stepModel.Uses).Path
actionDir = fmt.Sprintf("%s/%s", rc.ActionCacheDir(), safeFilename(stepModel.Uses))
actionDir = fmt.Sprintf("%s/%s", rc.ActionCacheDir(), stepModel.UsesHash())

this should probably use filepath.Join()

this should probably use `filepath.Join()`
Kwonunn marked this conversation as resolved
Contributor

cascading-pr updated at forgejo/runner#462

cascading-pr updated at https://code.forgejo.org/forgejo/runner/pulls/462
Contributor

cascading-pr updated at forgejo/runner#462

cascading-pr updated at https://code.forgejo.org/forgejo/runner/pulls/462
Contributor

cascading-pr updated at forgejo/runner#462

cascading-pr updated at https://code.forgejo.org/forgejo/runner/pulls/462
@ -717,0 +720,4 @@
// For Gitea.
func (s *Step) UsesHash() string {
hash := sha256.Sum256([]byte(s.Uses))
return fmt.Sprintf("%x/%x", hash[:1], hash[1:])

will pad %x the byte always to two chars?

will pad `%x` the byte always to two chars?

🤔 technically we should use filepath.Join here too for proper dir delimitter. not sure if we really need it as only windows uses a backslash but also works with forward slashes since a long time.

🤔 technically we should use `filepath.Join` here too for proper dir delimitter. not sure if we really need it as only windows uses a backslash but also works with forward slashes since a long time.
Author
Member

@viceice wrote in #100 (comment):

will pad %x the byte always to two chars?

it looks like it might not always. https://go.dev/play/p/3x9KLphPi8r

@viceice wrote in https://code.forgejo.org/forgejo/act/pulls/100#issuecomment-31266: > will pad `%x` the byte always to two chars? it looks like it might not always. https://go.dev/play/p/3x9KLphPi8r

@Kwonunn wrote in #100 (comment):

we should find a ways to force two char padding for consistency

@Kwonunn wrote in https://code.forgejo.org/forgejo/act/pulls/100#issuecomment-31273: > we should find a ways to force two char padding for consistency
it does: https://go.dev/play/p/nSDdFYVrmKM
Author
Member

i think i've used hex.EncodeToString() for this before, so i'll use that here as well

i think i've used hex.EncodeToString() for this before, so i'll use that here as well
Kwonunn marked this conversation as resolved
Contributor

cascading-pr updated at forgejo/runner#462

cascading-pr updated at https://code.forgejo.org/forgejo/runner/pulls/462
viceice left a comment

otherwise lgtm

otherwise lgtm
@ -12,2 +14,4 @@
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
"github.com/nektos/act/pkg/common"

wonder why this import moved 🤔

wonder why this import moved 🤔
Kwonunn marked this conversation as resolved
@ -717,0 +722,4 @@
// For Gitea.
func (s *Step) UsesHash() string {
hashBytes := sha256.Sum256([]byte(s.Uses))
hashString := hex.EncodeToString(hashBytes[:])

isn't hex.EncodeToString(hashBytes) the same? 🤔 do we really need the extra hashBytes variable?

isn't `hex.EncodeToString(hashBytes)` the same? 🤔 do we really need the extra `hashBytes` variable?
Author
Member

i tried that first but Sum256 returns a [32]byte value, and EncodeToString takes a []byte value. For some reason those aren't compatible (Go is weird) and the easiest way i found to make them work is to take a full slice of the [32]byte.

i tried that first but Sum256 returns a `[32]byte` value, and EncodeToString takes a `[]byte` value. For some reason those aren't compatible (Go is weird) and the easiest way i found to make them work is to take a full slice of the `[32]byte`.
viceice marked this conversation as resolved
Contributor

cascading-pr updated at forgejo/runner#462

cascading-pr updated at https://code.forgejo.org/forgejo/runner/pulls/462
viceice approved these changes 2025-01-29 10:11:11 +00:00
Dismissed
Kwonunn force-pushed fs-credential-leak from 221c9c89a7
Some checks failed
checks / unit (pull_request) Successful in 52s
checks / integration (pull_request) Successful in 32s
/ cascade (pull_request_target) Failing after 12m18s
to 2f189952f8
Some checks failed
checks / unit (pull_request) Successful in 55s
checks / integration (pull_request) Successful in 26s
/ cascade (pull_request_target) Failing after 33s
2025-01-29 10:13:49 +00:00
Compare
Contributor

cascading-pr updated at forgejo/runner#462

cascading-pr updated at https://code.forgejo.org/forgejo/runner/pulls/462
viceice approved these changes 2025-01-29 11:05:28 +00:00
Dismissed
Owner
@earl-warren I don't see why this fails, can we make failures more obvious in logs? https://code.forgejo.org/forgejo/end-to-end/actions/runs/2456/jobs/2#jobstep-4-1
Author
Member

i agree the logs are really hard to find/read..

i think the logs are telling me that the example-context action failed. however, if i run that same action on my end-to-end setup it works just fine so i'm not really sure what's breaking here...

i agree the logs are really hard to find/read.. i think the logs are telling me that the `example-context` action failed. however, if i run that same action on my end-to-end setup it works just fine so i'm not really sure what's breaking here...
Contributor

I would go as far as to say the logs are impossible to read. Here is the failed line:

https://code.forgejo.org/forgejo/end-to-end/actions/runs/2456/jobs/2#jobstep-5-1911

It is much easier to debug when running the failed test locally.

I would go as far as to say the logs are impossible to read. Here is the failed line: https://code.forgejo.org/forgejo/end-to-end/actions/runs/2456/jobs/2#jobstep-5-1911 It is **much** easier to debug when running the failed test locally.
Contributor

I think you could propose a pull request to end-to-end that verifies the action path is either what it was before this PR or what it is now. So that it is successful in both cases because both cases are ok. This is a sanity check more than anything so matching @main or */* would be fine by me.

I think you could propose a pull request to end-to-end that verifies the action path is either what it was before this PR or what it is now. So that it is successful in both cases because both cases are ok. This is a sanity check more than anything so matching `@main` or `*/*` would be fine by me.
Contributor

@Kwonunn gentle ping?

@Kwonunn gentle ping?
earl-warren changed title from Use hashed uses string as cache dir name to WIP: Use hashed uses string as cache dir name 2025-05-26 05:12:22 +00:00
Kwonunn force-pushed fs-credential-leak from 2f189952f8
Some checks failed
checks / unit (pull_request) Successful in 55s
checks / integration (pull_request) Successful in 26s
/ cascade (pull_request_target) Failing after 33s
to b518760a8c
All checks were successful
checks / unit (pull_request) Successful in 1m41s
checks / integration (pull_request) Successful in 33s
/ cascade (pull_request_target) Successful in 25s
2025-05-26 07:28:49 +00:00
Compare
Kwonunn dismissed viceice's review 2025-05-26 07:28:49 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

Contributor

cascading-pr updated at forgejo/runner#579

cascading-pr updated at https://code.forgejo.org/forgejo/runner/pulls/579
Author
Member

I unfortunately don't have time to debug the cascade failure right now, I'm very busy with school.

I had hoped the failure was transient/had been fixed by now, but it seems that isn't the case.

I unfortunately don't have time to debug the cascade failure right now, I'm very busy with school. I had hoped the failure was transient/had been fixed by now, but it seems that isn't the case.
Contributor

I'll work on polishing this today (as well as other cache related PRs maybe).

I'll work on polishing this today (as well as other cache related PRs maybe).
earl-warren closed this pull request 2025-07-16 08:54:48 +00:00
Commenting is not possible because the repository is archived.
No reviewers
No milestone
No assignees
4 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
forgejo/act!100
No description provided.