actions / cache

Cache dependencies and build outputs in GitHub Actions
MIT License
4.45k stars 1.18k forks source link

Pull request triggered workflow run should save cache under it's orginal branch #1124

Closed aguang-xyz closed 8 months ago

aguang-xyz commented 1 year ago

Hi there,

As described in the Cache scopes section, cache entries are isolated by branch level.

The cache is scoped to the key, version, and branch. The default branch cache is available to other branches.

If I understand correctly, the run triggered by pull request should also belong to it's source branch.

But in some of my project, after creating a pull request from dev to main. I can see that the cache entry indicates it's branch name is refs/pull/{pr-id}/merge. That seems wrong and thus pull request triggered runs cannot be speed up at the moment.

I tried to do some investigation my self and seems like the logic of resolving branch name is happend on server side. So feel free to point me where is the better place to track this issue (if this isn't the right space).

Many thanks, Grey

kotewar commented 1 year ago

Hi @aguang-xyz,

You are at the correct place. The caches belonging to the PR branch are only scoped to the respective PRs and not the main branch. Could you please explain further why you think its wrong? There's a big chance that older PRs might make stale caches active as other PRs might have updated the lockfile with different dependencies which might not be a part of the PR branch.

aguang-xyz commented 1 year ago

Hi @kotewar,

Let's say there is an repository:

It contains a CI workflow which will be triggered every time when we create a pull request towards main branch.

name: CI

on:
  pull_request:
    branches:
      - main

jobs:
  bazel-test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup node.js
        uses: actions/setup-node@v3
        with:
          node-version: latest

      - name: Setup bazelisk
        run: npm install -g @bazel/bazelisk

      - name: Setup bazel cache
        uses: actions/cache@v3
        with:
          path: "~/.cache/bazel"
          key: ${{ runner.os }}-bazel

      - name: Run tests
        run: bazel --output_user_root=~/.cache/bazel test //...

As a developer, I may:

Currently these two runs cannot share caches (because as you mentioned "The caches belonging to the PR branch are only scoped to the respective PRs")

But if we scope the caches down to it's source branch dev, we can speed up CI runs in this case.

avivek commented 1 year ago

Hi, Is there any update on this?? We would really be benefitted with this change and save a lot of time and action minutes.

github-actions[bot] commented 8 months ago

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.

github-actions[bot] commented 8 months ago

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

avivek commented 8 months ago

HI,

I see this is marked with the enhancement label. Think this should stay open.