act icon indicating copy to clipboard operation
act copied to clipboard

Enhancement: Automatically disable unsupported cache actions

Open sschuberth opened this issue 3 years ago • 7 comments

I realize act does not support jobs that use caching actions. However, for user convenience I wonder whether the work-arounds (by leveraging if: ${{ !env.ACT }}) could be avoided by "patching" the original workflow definition.

For example, if there was some (e.g. regex based) search & replace logic, code like

- name: Setup Java
  uses: actions/setup-java@v2
  with:
    distribution: adopt
    java-version: 11
    cache: gradle

could automatically be replaced with

- name: Setup Java
  uses: actions/setup-java@v2
  with:
    distribution: adopt
    java-version: 11

by omitting the final cache: gradle. For for a more complex example, code like

- name: Build all classes
  uses: burrunan/gradle-cache-action@v1
  with:
    arguments: --stacktrace classes -x :reporter-web-app:yarnBuild

could be replaced with

- name: Build all classes
  run: ./gradlew --stacktrace classes -x :reporter-web-app:yarnBuild

Such a replace logic could either be built into act directly, or be freely configurable via some configuration file.

sschuberth avatar Feb 09 '22 21:02 sschuberth

This is way too much work and almost impossible to get right

catthehacker avatar Feb 24 '22 17:02 catthehacker

As a workaround for the first example, you can set cache conditionally:

    - uses: actions/setup-node@v2
      with:
        cache: ${{ !env.ACT && 'npm' || '' }}

Note: Empty string is considered false, so it can't be first value and this wouldn't work: ${{ env.ACT && '' || 'npm' }}

domaslasauskas avatar Mar 05 '22 12:03 domaslasauskas

Plastering your workflow files with if: ${{ !env.ACT }} is really not a solution, especially given the increasing number of tools that use caching or even how frequently just actions/cache is used in ordinary workflows.

Would it not be possible to just stub this out such that it always returns a negative cache hit, and thus essentially just skips the caching altogether?

jamesdh avatar Jun 15 '22 17:06 jamesdh

Since act is not only used for local execution this is not an option. Also, for example the setup-node action, does use the toolkit cache which could not be easily stubbed.

KnisterPeter avatar Jun 15 '22 17:06 KnisterPeter

Instead it would be possible to implement chaching with the embedded artifact server. But that would be up for the requestors to implement.

KnisterPeter avatar Jun 15 '22 17:06 KnisterPeter

But that would be up for the requestors to implement.

Any hints at what parts of the code base would need to get touched?

sschuberth avatar Nov 10 '22 09:11 sschuberth

These: https://github.com/nektos/act/tree/master/pkg/artifacts :wink:

KnisterPeter avatar Nov 10 '22 09:11 KnisterPeter