Skip to content

Feature branch cannot restore cache made in main branch #1011

Closed

Description

@axionos

Goal
create snapshots cache in main branch -> restore cache in feature branch to compare snapshots

Issue
Cache hit doesn't happen in the feature branch when trying to restore the main branch's cache.
Instead, it creates a new cache with the exactly same cache key(version).

Would this be a bug?
The feature branch is based off of main branch so the scope shouldn't be an issue here I believe.
(git checkout -b cache-test on main)
The What am I missing here and how can i make this work?

Screen Shot 2022-12-01 at 12 36 11 PM
Screen Shot 2022-12-01 at 12 16 41 PM

Also noticing searching cache for branch "main" is not returning anything, which seems odd.

Screen Shot 2022-12-01 at 1 17 21 PM

# merge.yml - create cache on merge
- name: Store Snapshots Cache
      id: snapshots-cache
      uses: actions/cache@v3
      with:
          path: packages/**/src/**/*.*.tsx-snapshots
          key: ${{ runner.os }}-snapshots-${{ hashFiles('yarn.lock') }}

# pr-push.yml - restore cache on push
- name: Restore Snapshots Cache
      id: snapshots-cache
      uses: actions/cache@v3
      with:
          path: packages/**/src/**/*.*.tsx-snapshots
          key: ${{ runner.os }}-snapshots-${{ hashFiles('yarn.lock') }}
          restore-keys: |
             ${{ runner.os }}-snapshots-

Activity

  1. Phantsure commented on Dec 2, 2022

    @Phantsure
    Contributor

    Cache should have been restored from main and created a new cache in feature branch from those files. Can you check the logs if that is the case. Can you also check if the path in both cache steps in main and feature-branch same, that is given in debug log

  2. axionos commented on Dec 2, 2022

    @axionos
    Author

    I resolved this issue by creating the cache on push event on the main branch. It was previously triggered on pr close action. It would be great and save much time of other developers who wanna use actions/cache if it's mentioned in the documentation that only the cache that's generated by push can be accessible to its feature branches as nowhere in the documentation mentions this.

  3. kotewar commented on Dec 3, 2022

    @kotewar
    Contributor

    @axionos, can you please share the trigger condition present in your workflow file (both before and after)? Example-

    name: Close Pull Request
    
    # only trigger on pull request closed events
    on:
      pull_request:
        types: [ closed ]
    
  4. axionos commented on Dec 6, 2022

    @axionos
    Author

    @kotewar this will trigger the workflow on pull request push.

    Before:

    name: Pull Request Close
    on:
      pull_request:
        branches:
          - main
        types: [closed]
    

    After:

    name: Snapshot Update
    on:
      push:
        branches:
          - main
    
  5. anuragc617 commented on Dec 12, 2022

    @anuragc617
    Contributor

    Hi @axionos , when the pull_request trigger is used and if there is no cache to be restored i.e there is no matching cache in parent branch or default branch, the cache is created against the refs/pull/<PR_number>/merge( which is a merge branch created by GitHub by merging the PR target branch and the PR branch, check this ). The caches created against ``refs/pull/<PR_number>/merge` can only be used by this PR branch since this is a temp branch created for merging the PR.

    In your case, for trigger type:

    on:
      pull_request:
        branches:
          - main
        types: [closed]
    

    Since there is no cache with key: Linux-snapshots-350c... in main ref, the cache is created against refs/pull/<PR_number>/merge'. If there would have been cache for main` ref, then that cache would have been restored.

  6. cklim483 commented on Dec 21, 2022

    @cklim483

    Goal
    create snapshots cache in main branch -> restore cache in feature branch to compare snapshots

    Issue
    Cache hit doesn't happen in the feature branch when trying to restore the main branch's cache.
    Instead, it creates a new cache with the exactly same cache key(version).

    Would this be a bug?
    The feature branch is based off of main branch so the scope shouldn't be an issue here I believe.
    (git checkout -b cache-test on main)
    The What am I missing here and how can i make this work?

    Screen Shot 2022-12-01 at 12 36 11 PM
    Screen Shot 2022-12-01 at 12 16 41 PM

    Also noticing searching cache for branch "main" is not returning anything, which seems odd.

    Screen Shot 2022-12-01 at 1 17 21 PM

    # merge.yml - create cache on merge
    - name: Store Snapshots Cache
          id: snapshots-cache
          uses: actions/cache@v3
          with:
              path: packages/**/src/**/*.*.tsx-snapshots
              key: ${{ runner.os }}-snapshots-${{ hashFiles('yarn.lock') }}
    
    # pr-push.yml - restore cache on push
    - name: Restore Snapshots Cache
          id: snapshots-cache
          uses: actions/cache@v3
          with:
              path: packages/**/src/**/*.*.tsx-snapshots
              key: ${{ runner.os }}-snapshots-${{ hashFiles('yarn.lock') }}
              restore-keys: |
                 ${{ runner.os }}-snapshots-
    
  7. ivard commented on Feb 24, 2023

    @ivard

    I experience the same issue. The exact cache key exists on the default branch, but it is not used by runs for pull requests.
    image

    In my case, the master's cache was created in another workflow than the one that tries to retrieve the cache. However, it concerns the same composite action.

    https://github.com/privacybydesign/irmamobile/blob/6a684d3a82de5e06371c02fa2e2f9e356a7d4bb4/.github/actions/setup-build-environment/action.yml#L46

  8. github-actions commented on Sep 13, 2023

    @github-actions

    This issue is stale because it has been open for 200 days with no activity. Leave a comment to avoid closing this issue in 5 days.

  9. github-actions commented on Sep 18, 2023

    @github-actions

    This issue was closed because it has been inactive for 5 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions