skip to Main Content

I am currently trying to call a reusable workflow from two other workflows both located in the same directory and the same private repository as the reusable workflow. The files look like this:

// .github/workflows/deploy.yml

name: Deploy
on:
    workflow_call:
        inputs:
            bucketFolder:
                type: string
jobs:
    deploy:
        runs-on: ubuntu-latest
        strategy:
            matrix:
                node-version: [18]
        steps:
            - uses: actions/checkout@v3
            - uses: pnpm/action-setup@v2
              with:
                  version: 7
            - uses: actions/setup-node@v3
              with:
                  node-version: ${{ matrix.node-version }}
                  cache: "pnpm"
            - name: Configure AWS Credentials
              uses: aws-actions/configure-aws-credentials@v1-node16
              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: Install modules
              run: pnpm install
            - name: Build application
              run: pnpm run build
            - name: Deploy to S3
              run: aws s3 sync ./dist/ s3://${{ secrets.BUCKET_ID }}/${{ inputs.bucketFolder }}
            - name: Create CloudFront invalidation
              uses: nick-fields/retry@v2
              with:
                  max_attempts: 6
                  retry_on: error
                  timeout_seconds: 60
                  retry_wait_seconds: 600
                  command: aws cloudfront create-invalidation --distribution-id ${{ secrets.DISTRIBUTION_ID }} --paths "/*"

// .github/workflows/production.yml

name: Deploy - Production
on:
    push:
        branches:
            - main
    workflow_dispatch:
        branches:
            - main
jobs:
    awsDeploy:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v3
            - uses: ./.github/workflows/deploy.yml
              with:
                  bucketFolder: production

// .github/workflows/staging.yml

name: Deploy - Staging
on:
    push:
        branches:
            - staging
    workflow_dispatch:
        branches:
            - staging
jobs:
    awsDeploy:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v3
            - uses: ./.github/workflows/deploy.yml
              with:
                  bucketFolder: staging

Can’t find ‘action.yml’, ‘action.yaml’ or ‘Dockerfile’ under ‘/home/runner/work/{repository-name}/{repository-name}/.github/workflows/deploy.yml’. Did you forget to run actions/checkout before running your local action?

Is the fact it is using {repository-name}/{repository-name} in the path the issue and if it is how do I fix it? If not, what is going wrong here?

2

Answers


  1. Chosen as BEST ANSWER

    I found the solution shortly after posting. From the docs:

    You call a reusable workflow by using the uses keyword. Unlike when you are using actions within a workflow, you call reusable workflows directly within a job, and not from within job steps.

    It was a reusable workflow, not an action, so I just had to remove the steps, uses: actions/checkout@v3 and runs-on like so:

    name: Deploy - Staging
    on:
        push:
            branches:
                - staging
        workflow_dispatch:
            branches:
                - staging
    jobs:
        awsDeploy:
            uses: ./.github/workflows/deploy.yml
            with:
                bucketFolder: staging
    

  2. When you specify uses at the step level, as you’ve done with your examples, this tells the parser to look for a GitHub Action not a workflow (which is why you are getting the Can't find 'action.yml' error message).

    In order to call a reusable workflow, the uses must be specified at the job level:

    jobs:
        awsDeploy:
            uses: ./.github/workflows/deploy.yml
            with:
                bucketFolder: staging
    

    For more details, take a look at the Calling a reusable workflow documentation.

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