skip to Main Content

My plan would be to use some GH actions YAML file in my other action YAML file.

I have a list_images.yaml file in my repo: .github/workflows folder. This action looks like this:

name: List Docker Images
on: [push]

jobs:
  list_images:
    runs-on: ubuntu-latest
    steps:
      - name: List Docker images
        run: docker images

It just list the built images in a runner…

I have another action YAML file, this checks out my source code, builds an image, tags it. To test how I an use one of my action YAML file in another action YAML file, I added list_images.yaml file usage in this way:

name: Try to build image and push it into ghcr.io

on:
    push:  
        branches:
            - GhActions_test
    workflow_dispatch: 

jobs:
    build:
        runs-on: ubuntu-latest
        steps:
            - name: checkout app source code
              uses: actions/checkout@v4
            - name: Where I am
              run: pwd
              shell: bash
            - name: List current folder
              run: ls -la
              shell: bash
            - name: List workflows
              run: ls -la ./.github/workflows
              shell: bash
            - name: Build image
              run: docker compose --env-file .env.prod build app_base
            - name: tag image
              run: docker tag app:latest ghcr.io/my_org/app:1.0.0
            - name: List Docker images
              uses: ./.github/workflows/list_images.yaml            
            - name: Login to Docker Hub
              uses: docker/login-action@v3
              with:
                registry: ghcr.io
                username: ${{ secrets.DOCKERHUB_USERNAME }}
                password: ${{ secrets.DOCKERHUB_TOKEN }}              
            - name: Push image to GuitHub package repo
              run: docker push ghcr.io/my_org/app:latest
    

My problem is, that I got an error message when I want to use my list_images.yaml file:

> Error: Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under
> '/home/runner/work/my_repo/my_repo/.github/actions/list_images.yaml'.
> Did you forget to run actions/checkout before running your local
> action?

I really don’t understand why not find the list_imgaes.yaml file, how ever it placed next to the caller action YAML file. The result of some steps:

  1. Where I am: /home/runner/work/my_repo/my_repo

  2. List workflows:

    drwxr-xr-x 2 runner docker 4096 Feb 20 09:34 .
    drwxr-xr-x 4 runner docker 4096 Feb 20 09:34 ..
    -rw-r--r-- 1 runner docker 1976 Feb 20 09:34 build_try.yaml
    -rw-r--r-- 1 runner docker  156 Feb 20 09:34 list_images.yaml
    

Any idea what’s wrong?
I know, I can put the list docker images command into the "main" action YAML file, but this is just a learning step.

2

Answers


  1. Chosen as BEST ANSWER

    Reading a lot, do a tons of research...the result and my understanding is: it is not possible to use any kind of custom (=created by you) action to call it in a job. Reusable is possible in a new job, and it is also not possible to run 2 or more jobs on the same runner, except if the runner is a custom runner...


  2. You can use a composite action instead of a reusable workflow. They execute as part of the same job.

    More information here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search