cache icon indicating copy to clipboard operation
cache copied to clipboard

Caching is not working when workflow is triggered by repository dispatch

Open SharonDiskin opened this issue 3 years ago • 1 comments

Hi, I have a workflow that uses cache. The workflow works fine when it triggered on push/manually with 'workflow dispatch' but when it triggered with 'repository dispatch' meaning it is triggered by another job, I never get a cache hit and all the dependencies are installed from scratch.

This is my workflow:

name: Caching with npm
name: build and trigger release
on:
  repository_dispatch:
    types: [ release ]
  workflow_dispatch:
    branches:
      - test-branch
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Configure AWS CLI
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-1
            
      - name: Login to Amazon Public ECR
        uses: docker/login-action@v1
        with:
          registry: ****.dkr.ecr.us-east-1.amazonaws.com
          username: ${{ secrets.AWS_ACCESS_KEY_ID }}
          password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          
      - name: Create ecr repo incase it doesn't exist
        uses: int128/create-ecr-repository-action@v1
        with:
          repository: sharon-test
          lifecycle-policy: lifecycle-policy.json
          
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@master

      - name: Cache Docker layers
        uses: actions/cache@v2
        with:
          path: /tmp/.buildx-sharon-test-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-
            
      - name: Build Docker image
        uses: docker/build-push-action@v2
        with:
          context: .
          builder: ${{ steps.buildx.outputs.name }}
          push: true
          tags: ****.dkr.ecr.us-east-2.amazonaws.com/sharon-test:latest, ****.dkr.ecr.us-east-2.amazonaws.com/sharon-test:${{ github.event.client_payload.tag }}
          cache-from: type=local,src=/tmp/.buildx-sharon-test-cache
          cache-to: type=local,dest=/tmp/.buildx-sharon-test-cache-new
          file: Dockerfile.api

      - name: Move cache
        run: |
          rm -rf /tmp/.buildx-sharon-test-cache
          mv /tmp/.buildx-sharon-test-cache-new /tmp/.buildx-sharon-test-cache

I would also like to mention that In this example you see I am using the local cache but in the 'Build docker image' part I also used github actions global cache:

      - name: Build Docker image
        uses: docker/build-push-action@v2
        with:
          context: .
          builder: ${{ steps.buildx.outputs.name }}
          push: true
          tags: ****.dkr.ecr.us-east-2.amazonaws.com/sharon-test:latest, ****.dkr.ecr.us-east-2.amazonaws.com/sharon-test:${{ github.event.client_payload.tag }}
          cache-from: type=gha
          cache-to: type=gha,mode=max
          file: Dockerfile.api

but it doesn't change a thing, the cache hit fails in 'Cache Docker layers' evreytime.

Does anyone have a clue of what might be the issue with repository dispatch? or any other issue? Thank you!

SharonDiskin avatar Sep 25 '22 09:09 SharonDiskin

Help anyone?

SharonDiskin avatar Sep 29 '22 07:09 SharonDiskin

Hey @SharonDiskin I have verified that cache restore is happening with repository_dispatch event using a workflow that saves and restores cache in two jobs. For further debugging, I would like to have a look at the debug logs, can you please share them.

anuragc617 avatar Oct 19 '22 18:10 anuragc617

Hi @SharonDiskin Are you still facing this issue? If yes then will it be possible to share the debugging logs?

t-dedah avatar Nov 29 '22 22:11 t-dedah

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] avatar Jun 18 '23 08:06 github-actions[bot]

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

github-actions[bot] avatar Jun 23 '23 08:06 github-actions[bot]