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

feat: cli option to enable the new action cache #1954

Merged
merged 19 commits into from
Jan 19, 2024

Conversation

ChristopherHX
Copy link
Contributor

@ChristopherHX ChristopherHX commented Aug 8, 2023

This is my initial code to switch the action cache over to my new implementation

Until all tests are migrated this will be kept as draft to avoid mergify spam.

I would be careful to test this change, to detect known issues of my previous PR's and this change.

Checklist

  • Test symlinked action.yml file in remote actions
  • Test symlinked action.yml file in local actions
  • Test remote docker actions
  • Test using images with a non root container (I expect we still need to fix permissions)
  • Test error messages like
    • action.yml not found
    • Clone failed
  • Make Tests Green (If I add a Feature Toggle for this change the test don't need to change)

Do you prefer to add a Feature Toggle for this change? Then we can merge this while iron out remaining bugs later and make it possible to make use of this change for people affected by the current problems.

Comment on lines +653 to +665
// Mkdir
buf := &bytes.Buffer{}
tw := tar.NewWriter(buf)
_ = tw.WriteHeader(&tar.Header{
Name: destPath,
Mode: 777,
Typeflag: tar.TypeDir,
})
tw.Close()
err := cr.cli.CopyToContainer(ctx, cr.id, "/", buf, types.CopyToContainerOptions{})
if err != nil {
return fmt.Errorf("failed to mkdir to copy content to container: %w", err)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The second CopyToContainer would fail with destPath doesn't exists.
Not using mkdir, works in containers without that tool and use plain docker api.

Comment on lines +671 to +674
// If this fails, then folders have wrong permissions on non root container
if cr.UID != 0 || cr.GID != 0 {
_ = cr.Exec([]string{"chown", "-R", fmt.Sprintf("%d:%d", cr.UID, cr.GID), destPath}, nil, "0", "")(ctx)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As before we need to fix folder ownership

rc := step.getRunContext()
stepModel := step.getStepModel()

if stepModel.Type() != model.StepTypeUsesActionRemote {
if stepModel.Type() != model.StepTypeUsesActionRemote || rc.ActionCache == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is added to avoid a panic in a Test

@@ -47,6 +47,7 @@ type RunContext struct {
Masks []string
cleanUpJobContainer common.Executor
caller *caller // job calling this RunContext (reusable workflows)
ActionCache ActionCache
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move to runner.Config?

Comment on lines 74 to 75
sar.cacheDir = fmt.Sprintf("%s/%s", sar.remoteAction.Org, sar.remoteAction.Repo)
sar.resolvedSha, err = cache.Fetch(ctx, sar.cacheDir, sar.remoteAction.URL+"/"+sar.cacheDir, sar.remoteAction.Ref, github.Token)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolve the action and cache access variables

@codecov
Copy link

codecov bot commented Aug 16, 2023

Codecov Report

Attention: 1013 lines in your changes are missing coverage. Please review.

Comparison is base (4989f44) 61.22% compared to head (cc6ca22) 60.72%.
Report is 298 commits behind head on master.

Files Patch % Lines
pkg/artifactcache/handler.go 65.46% 102 Missing and 42 partials ⚠️
pkg/runner/run_context.go 73.37% 75 Missing and 19 partials ⚠️
pkg/runner/expression.go 55.17% 66 Missing and 12 partials ⚠️
pkg/runner/action_cache.go 50.74% 49 Missing and 17 partials ⚠️
pkg/container/docker_run.go 1.51% 64 Missing and 1 partial ⚠️
pkg/container/docker_network.go 0.00% 56 Missing ⚠️
pkg/model/planner.go 28.57% 53 Missing and 2 partials ⚠️
pkg/runner/reusable_workflow.go 52.00% 42 Missing and 6 partials ⚠️
pkg/model/workflow.go 43.37% 40 Missing and 7 partials ⚠️
pkg/common/outbound_ip.go 0.00% 44 Missing ⚠️
... and 27 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1954      +/-   ##
==========================================
- Coverage   61.22%   60.72%   -0.51%     
==========================================
  Files          46       53       +7     
  Lines        7141     8959    +1818     
==========================================
+ Hits         4372     5440    +1068     
- Misses       2462     3081     +619     
- Partials      307      438     +131     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ChristopherHX ChristopherHX changed the title Enable the new action cache feat: cli option to enable the new action cache Aug 16, 2023
Copy link
Contributor Author

@ChristopherHX ChristopherHX left a comment

Choose a reason for hiding this comment

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

This is a feature preview, a cli flag controls if this feature is on.

Next steps are cli flags for local repository replacements instead of cloning the action.

E.g. developing an actions pre step in act.

@@ -612,6 +613,11 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
ReplaceGheActionTokenWithGithubCom: input.replaceGheActionTokenWithGithubCom,
Matrix: matrixes,
}
if input.useNewActionCache {
config.ActionCache = &runner.GoGitActionCache{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Enabled behind feature cli flag: --use-new-action-cache, old code has been restored.

@ChristopherHX ChristopherHX marked this pull request as ready for review August 16, 2023 15:37
@ChristopherHX ChristopherHX requested a review from a team as a code owner August 16, 2023 15:37
@ChristopherHX
Copy link
Contributor Author

See ChristopherHX#34 for what is possible with substitution.

The filecollector should be moved out of the container package and made public.

cmd/root.go Outdated Show resolved Hide resolved
@mergify mergify bot requested a review from a team August 21, 2023 11:53
Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
@mergify
Copy link
Contributor

mergify bot commented Aug 21, 2023

@ChristopherHX this pull request has failed checks 🛠

@mergify mergify bot added the needs-work Extra attention is needed label Aug 21, 2023
@mergify mergify bot removed the needs-work Extra attention is needed label Aug 21, 2023
@ChristopherHX
Copy link
Contributor Author

ChristopherHX commented Sep 23, 2023

Just added support for remote reusable workflows, should be possible to be redirected them to a local folder via https://github.com/nektos/act/tree/local-repository-action-cache

./act --github-instance ubuntu.fritz.box:3042 --use-new-action-cache -W w.yml -P ubuntu-latest=ubuntu.fritz.box:2000/runner-images:ubuntu22-runner-large-latest --local-repository https://ubuntu.fritz.box:3042/Christopher/re-complex@main=$PWD

w.yml

on: push
jobs:
  caller:
    uses: Christopher/re-complex/.github/workflows/callable.yml@main
    with:
      os: ubuntu-latest
    secrets:
      API_TOKEN: ${{ tojson(github.sha) }}

.github/workflows/callable.yml

on:
  workflow_call:
    inputs:
      os:
        required: true
        type: string
    secrets:
      API_TOKEN:
        required: true
jobs:
  test-scripts:
    runs-on: ${{ inputs.os }}
    steps:
    - run: echo ${{ secrets.API_TOKEN }}

@mergify
Copy link
Contributor

mergify bot commented Oct 23, 2023

@ChristopherHX this pull request is now in conflict 😩

@mergify mergify bot added the conflict PR has conflicts label Oct 23, 2023
@mergify mergify bot removed the conflict PR has conflicts label Jan 8, 2024
@ChristopherHX
Copy link
Contributor Author

Seems like we decided to no longer try to fix concurrent action / reusable workflow updates.

Am I allowed to continue here, or what are your concerns?

Comment on lines +314 to +322
func symlinkJoin(filename, sym, parent string) (string, error) {
dir := path.Dir(filename)
dest := path.Join(dir, sym)
prefix := path.Clean(parent) + "/"
if strings.HasPrefix(dest, prefix) || prefix == "./" {
return dest, nil
}
return "", fmt.Errorf("symlink tries to access file '%s' outside of '%s'", strings.ReplaceAll(dest, "'", "''"), strings.ReplaceAll(parent, "'", "''"))
}
Copy link
Contributor Author

@ChristopherHX ChristopherHX Jan 8, 2024

Choose a reason for hiding this comment

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

I forget that \ are technically allowed here, path wouldn't handle them...
Don't think it is a new problem

Copy link
Contributor

@cplee cplee left a comment

Choose a reason for hiding this comment

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

tested locally 👍

@mergify mergify bot merged commit f7a846d into nektos:master Jan 19, 2024
10 checks passed
jmikedupont2 pushed a commit to meta-introspector/act that referenced this pull request Mar 10, 2024
* Enable the new action cache

* fix

* fix: CopyTarStream (Docker)

* suppress panic in test

* add a cli option for opt in

* fixups

* add package

* fix

* rc.Config nil in test???

* add feature flag

* patch

* Fix respect --action-cache-path

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>

* add remote reusable workflow to ActionCache

* fixup

---------

Co-authored-by: Björn Brauer <zaubernerd@zaubernerd.de>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
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.

3 participants