[GH-ISSUE #989] Enhancement: Automatically disable unsupported cache actions #581

Open
opened 2026-03-01 21:44:42 +03:00 by kerem · 7 comments
Owner

Originally created by @sschuberth on GitHub (Feb 9, 2022).
Original GitHub issue: https://github.com/nektos/act/issues/989

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.

Originally created by @sschuberth on GitHub (Feb 9, 2022). Original GitHub issue: https://github.com/nektos/act/issues/989 I realize `act` does not support jobs that use [caching](https://github.com/nektos/act/issues/933#issuecomment-997396381) [actions](https://github.com/nektos/act/issues/285#issuecomment-987550101). 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.
Author
Owner

@catthehacker commented on GitHub (Feb 24, 2022):

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

<!-- gh-comment-id:1050092083 --> @catthehacker commented on GitHub (Feb 24, 2022): This is way too much work and almost impossible to get right
Author
Owner

@domaslasauskas commented on GitHub (Mar 5, 2022):

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' }}

<!-- gh-comment-id:1059758786 --> @domaslasauskas commented on GitHub (Mar 5, 2022): As a workaround for the first example, you can set `cache` conditionally: ```yaml - 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' }}`
Author
Owner

@jamesdh commented on GitHub (Jun 15, 2022):

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?

<!-- gh-comment-id:1156759742 --> @jamesdh commented on GitHub (Jun 15, 2022): 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?
Author
Owner

@KnisterPeter commented on GitHub (Jun 15, 2022):

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.

<!-- gh-comment-id:1156766008 --> @KnisterPeter commented on GitHub (Jun 15, 2022): 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.
Author
Owner

@KnisterPeter commented on GitHub (Jun 15, 2022):

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

<!-- gh-comment-id:1156768547 --> @KnisterPeter commented on GitHub (Jun 15, 2022): Instead it would be possible to implement chaching with the embedded artifact server. But that would be up for the requestors to implement.
Author
Owner

@sschuberth commented on GitHub (Nov 10, 2022):

But that would be up for the requestors to implement.

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

<!-- gh-comment-id:1310018266 --> @sschuberth commented on GitHub (Nov 10, 2022): > But that would be up for the requestors to implement. Any hints at what parts of the code base would need to get touched?
Author
Owner

@KnisterPeter commented on GitHub (Nov 10, 2022):

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

<!-- gh-comment-id:1310031668 --> @KnisterPeter commented on GitHub (Nov 10, 2022): These: https://github.com/nektos/act/tree/master/pkg/artifacts :wink:
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
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
starred/act#581
No description provided.