Skip to content

duplicate cache with same key? #968

Closed

Description

@nalchevanidze

I don't know if it's a right place, problem can be caused by GitHub cache API. my Github workflow sometimes in Haskell doesn't use cache key. not even more general restore keys.

as you can see there are multiple builds with same kay.

image

where pipeline each time could not find the cache and saves it again.

image

in my case i already have 5 duplicate caches with same key, which evoke my curiosity.
how it is possible? and what can be a reason?

Activity

  1. nalchevanidze commented on Oct 24, 2022

    @nalchevanidze
    Author

    my action description is following:

        - name: Cache Stack
          uses: actions/cache@v2
          with:
            path: ~/.stack
            key: ${{ runner.os  }}-${{ inputs.ghc }}-stack-${{ hashFiles('stack.yaml') }}
            restore-keys: |
              ${{ runner.os }}-${{ inputs.ghc }}-stack
  2. anuragc617 commented on Oct 25, 2022

    @anuragc617
    Contributor

    Hi @nalchevanidze, this is because cache with same key can be restored from the parent branch or main branch and not across the branch. But if the cache with key is not present in parent/main branch, then individual branches which will create their own caches. For more details check this doc

  3. nalchevanidze commented on Oct 25, 2022

    @nalchevanidze
    Author

    thanks @anuragc617. Is there anything I can do to change this behavior? since I don't really care about the branches and I would like to have one cache per key regardless of the branches?

  4. anuragc617 commented on Oct 25, 2022

    @anuragc617
    Contributor

    If you want one cache per key, then you need to ensure that cache is created against main branch and the other branches can restore the cache.
    But if a branch changes the cache key then it will create a cache with new key and this can only be restored by that branch and children of that branch.

  5. sidekick-eimantas commented on Oct 31, 2022

    @sidekick-eimantas

    Is there anything preventing this action from supporting caches that are not scoped to a particular branch?
    I've been using this action for a couple of years now, since v1, and honestly never noticed this behaviour. That is to say, I found this quite unintuitive.

    We run with strict branch protection rules, never allowing anyone to push to main, requiring all changes to come through a pull request. However, now we must run useless tests on push to main (after a PR gets merged), just so we get a cache built, wasting precious minutes.

  6. anuragc617 commented on Nov 11, 2022

    @anuragc617
    Contributor

    @sidekick-eimantas the cross-branch caches protection is necessary because the cache created for a branch may have vulnerabilities and if that cache is used for building the main branch/ parent branch, then the build artifacts generated for main branch will also have those vulnerabilities. It poses a security threat for your production environment.

  7. Avasam commented on Nov 24, 2022

    @Avasam

    But what if it comes from the same PR/Branch? Here I have 5 duplicates:
    image

    https://github.com/Avasam/Auto-Split/actions/caches

    Details
    # https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions
    name: Lint and build
    on:
      workflow_dispatch: #  Allows manual builds
        inputs:
          excludeBuildNumber:
            description: "Exclude build number"
            required: true
            default: false
            type: boolean
      push:
        branches:
          - main
          - master
        paths:
          - "**.py"
          - "**.ui"
          - ".github/workflows/lint-and-build.yml"
          - "**/requirements.txt"
      pull_request:
        branches:
          - main
          - master
          - dev*
          - 2.0.0
        paths:
          - "**.py"
          - "**.pyi"
          - "**.ui"
          - ".github/workflows/lint-and-build.yml"
          - "**/requirements*.txt"
    
    env:
      GITHUB_HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}
      GITHUB_EXCLUDE_BUILD_NUMBER: ${{ inputs.excludeBuildNumber }}
    
    jobs:
      isort:
        runs-on: windows-latest
        steps:
          - name: Checkout ${{ github.repository }}/${{ github.ref }}
            uses: actions/checkout@v3
          - name: Set up Python 3.11
            uses: actions/setup-python@v4
            with:
              python-version: "3.11"
              cache: "pip"
              cache-dependency-path: "scripts/requirements*.txt"
          - uses: actions/cache@v3
            with:
              path: |
                "${{ env.pythonLocation }}/lib/site-packages"
                "${{ env.pythonLocation }}/scripts"
              key: ${{ runner.os }}-pip-${{ hashFiles('scripts/requirements*.txt') }}
          - run: scripts/install.ps1
            shell: pwsh
          - run: Get-Command pyuic6
            shell: pwsh
          - name: Analysing the code with add-trailing-comma
            run: isort src/ typings/ --check-only
      add-trailing-comma:
        runs-on: windows-latest
        steps:
          - name: Checkout ${{ github.repository }}/${{ github.ref }}
            uses: actions/checkout@v3
          - name: Set up Python 3.11
            uses: actions/setup-python@v4
            with:
              python-version: "3.11"
          - run: pip install add-trailing-comma
          - name: Analysing the code with add-trailing-comma
            run: add-trailing-comma $(git ls-files '**.py*') --py36-plus
      Bandit:
        # Bandit only matters on the version deployed. Platform checks are ignored
        runs-on: windows-latest
        steps:
          - name: Checkout ${{ github.repository }}/${{ github.ref }}
            uses: actions/checkout@v3
          - name: Set up Python 3.11
            uses: actions/setup-python@v4
            with:
              python-version: "3.11"
          - run: pip install bandit
          - name: Analysing the code with Bandit
            run: bandit src/ -n 1 --severity-level medium --recursive
      Pyright:
        runs-on: windows-latest
        strategy:
          fail-fast: false
          # Pyright is version and platform sensible
          matrix:
            python-version: ["3.9", "3.10", "3.11"]
        steps:
          - name: Checkout ${{ github.repository }}/${{ github.ref }}
            uses: actions/checkout@v3
          - name: Set up Python ${{ matrix.python-version }}
            uses: actions/setup-python@v4
            with:
              python-version: ${{ matrix.python-version }}
              cache: "pip"
              cache-dependency-path: "scripts/requirements*.txt"
          - uses: actions/cache@v3
            with:
              path: |
                "${{ env.pythonLocation }}/lib/site-packages"
                "${{ env.pythonLocation }}/scripts"
              key: ${{ runner.os }}-pip-${{ hashFiles('scripts/requirements*.txt') }}
          - run: scripts/install.ps1
            shell: pwsh
          - name: Analysing the code with Pyright
            uses: jakebailey/pyright-action@v1
            with:
              working-directory: src/
              extra-args: --warnings
      Pylint:
        runs-on: windows-latest
        strategy:
          fail-fast: false
          # Pylint is version and platform sensible
          matrix:
            python-version: ["3.9", "3.10", "3.11"]
        steps:
          - name: Checkout ${{ github.repository }}/${{ github.ref }}
            uses: actions/checkout@v3
          - name: Set up Python ${{ matrix.python-version }}
            uses: actions/setup-python@v4
            with:
              python-version: ${{ matrix.python-version }}
              cache: "pip"
              cache-dependency-path: "scripts/requirements*.txt"
          - uses: actions/cache@v3
            with:
              path: |
                "${{ env.pythonLocation }}/lib/site-packages"
                "${{ env.pythonLocation }}/scripts"
              key: ${{ runner.os }}-pip-${{ hashFiles('scripts/requirements*.txt') }}
          - run: scripts/install.ps1
            shell: pwsh
          - name: Analysing the code with Pylint
            run: pylint src/ --reports=y --output-format=colorized
      Flake8:
        runs-on: windows-latest
        strategy:
          fail-fast: false
          # Flake8 is tied to the version of Python on which it runs. Platform checks are ignored
          matrix:
            python-version: ["3.9", "3.10", "3.11"]
        steps:
          - name: Checkout ${{ github.repository }}/${{ github.ref }}
            uses: actions/checkout@v3
          - name: Set up Python ${{ matrix.python-version }}
            uses: actions/setup-python@v4
            with:
              python-version: ${{ matrix.python-version }}
              cache: "pip"
              cache-dependency-path: "scripts/requirements*.txt"
          - uses: actions/cache@v3
            with:
              path: |
                "${{ env.pythonLocation }}/lib/site-packages"
                "${{ env.pythonLocation }}/scripts"
              key: ${{ runner.os }}-pip-${{ hashFiles('scripts/requirements*.txt') }}
          - run: scripts/install.ps1
            shell: pwsh
          - name: Analysing the code with Flake8
            run: flake8 src/ typings/
      Build:
        runs-on: windows-latest
        strategy:
          fail-fast: false
          # Only the Python version we plan on shipping matters.
          matrix:
            python-version: ["3.11"]
        steps:
          - name: Checkout ${{ github.repository }}/${{ github.ref }}
            uses: actions/checkout@v3
          - name: Set up Python ${{ matrix.python-version }}
            uses: actions/setup-python@v4
            with:
              python-version: ${{ matrix.python-version }}
              cache: "pip"
              cache-dependency-path: "scripts/requirements.txt"
          - uses: actions/cache@v3
            with:
              path: |
                "${{ env.pythonLocation }}/lib/site-packages"
                "${{ env.pythonLocation }}/scripts"
              key: ${{ runner.os }}-pip-${{ hashFiles('scripts/requirements.txt') }}
          - run: scripts/install.ps1
            shell: pwsh
          - run: scripts/build.ps1
            shell: pwsh
          - name: Upload Build Artifact
            uses: actions/upload-artifact@v3
            with:
              name: AutoSplit (Python ${{ matrix.python-version }})
              path: dist/AutoSplit*
              if-no-files-found: error
          - name: Upload Build logs
            uses: actions/upload-artifact@v3
            with:
              name: Build logs (Python ${{ matrix.python-version }})
              path: |
                build/AutoSplit/*.toc
                build/AutoSplit/*.txt
                build/AutoSplit/*.html
              if-no-files-found: error
  8. dreamscached commented on Nov 26, 2022

    @dreamscached

    Having the same issue on the same branch with the exact same cache key.
    obrazek

    The workflow ignores it completely, claiming that cache hit did not occur and uploading cache with the exact same key, creating more and more duplicates. However, when I re-run the workflow, it picks it up.

    Another note: using cache inside a composite action.

  9. bishal-pdMSFT commented on Dec 1, 2022

    @bishal-pdMSFT

    Please see the doc to know how cache matching is done and why cache may not match in your case.

  10. axionos commented on Dec 1, 2022

    @axionos

    @dreamscached any luck on this? i have a similar issue #1011

  11. dreamscached commented on Dec 2, 2022

    @dreamscached

    @dreamscached any luck on this? i have a similar issue #1011

    Unfortunately... I only ended up converting it into a reusable workflow, for reusable workflows it works, but usage looks uglier (yet similar) to composite actions.

  12. cklim483 commented on Dec 21, 2022

    @cklim483

    I don't know if it's a right place, problem can be caused by GitHub cache API. my Github workflow sometimes in Haskell doesn't use cache key. not even more general restore keys.

    as you can see there are multiple builds with same kay.

    image

    where pipeline each time could not find the cache and saves it again.

    image

    in my case i already have 5 duplicate caches with same key, which evoke my curiosity.
    how it is possible? and what can be a reason?

  13. dreamscached commented on Dec 21, 2022

    @dreamscached

    @cklim483 these are on different branches

  14. smil2k commented on Feb 21, 2023

    @smil2k

    They are not duplicates, I just learned that there might be different versions of the same hash. So your package.json/pom whatnot hash did not change, but there is a hidden version also present which is another hash of the locations. In effect more or less an OS filter... Just this is nowhere visible and only reported on debug level.

  15. dreamscached commented on Feb 21, 2023

    @dreamscached

    The entire point of cache is that it doesn't need to do any extra work but to do a quickiest possible lookup by unique cache key and return; there shouldn't be even a possibility that one key can have several 'versions', the only exception to that is how it works with different branches.

  16. smil2k commented on Feb 21, 2023

    @smil2k

    I cannot agree more. Cache plugin try to solve an additional problem which is not entirely under his control and it operates with hidden variables which makes it confusing to many.

    What if I would like to use only one cache key for the whole project? What if the stuff in the cache is platform neutral? Why should cache plugin bother? If it does not fit it will fail, then I’ll fix it with a different key, or whatever.

  17. ste00martin commented on May 23, 2023

    @ste00martin

    @smil2k I created a more direct feature ask for this here if you'd like to upvote it: #1175

  18. github-actions commented on Dec 10, 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.

  19. github-actions commented on Dec 15, 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