Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy fails with "This command can only be run in a Serverless service directory." #42

Closed
giorgosera opened this issue Oct 12, 2020 · 9 comments

Comments

@giorgosera
Copy link

I have the following workflow file at .github/workflows/deploy-serverless.yml. It is identical to the one in the README except for the npm ci line.

name: Deploy serverless function

on:
  push:
    branches:
      - master

jobs:
  deploy:
    name: deploy
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [12.x]
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - name: serverless deploy
      uses: serverless/github-action@master
      with:
        args: deploy
      env:
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

When I run this action it fails at the step serverless deploy with the following error:

  Serverless Error ---------------------------------------
 
  This command can only be run in a Serverless service directory. Make sure to reference a valid config file in the current working directory if you're using a custom config file
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              12.19.0
     Framework Version:         2.1.0
     Plugin Version:            4.0.4
     SDK Version:               2.3.2
     Components Version:        3.2.1

Am I supposed to put the workflow file in my service directory? If yes how will github find it and run it? Maybe I'm missing something obvious here so I'd appreciate your help.

Thanks

PS: I can manually deploy my code with no issues.

@giorgosera
Copy link
Author

My bad! I was running the github action in the wrong directory. I set it using the working-directory param and it worked.

Sorry for the unnecessary issue.

@kalepail
Copy link

kalepail commented Mar 1, 2021

@giorgosera Can you share the yml file you used to get this to work? What changes did you make, where did you put the working-directory value?

@fabiopaiva
Copy link

I'm also struggling to configure the working directory

@deathemperor
Copy link

same, would love to know which fixed it

@giorgosera
Copy link
Author

Hey everyone,

Unfortunately, it's been a while and I cannot recall how I fixed it! I thought that my follow up message would help othersin the future but apparently it doesn't.

I hope you find a workaround! I know how frustrating it can be :(

@DavideViolante
Copy link
Contributor

DavideViolante commented Jun 21, 2021

I think he added in the yml the working-directory command supported by the GitHub Actions.
Example taken from here (search for working-directory in the page):

- name: Clean temp directory
  run: rm -rf *
  working-directory: ./temp

If someone can try it I will add some info in the readme for clarity. I'm not currently using this action.

@deathemperor
Copy link

I tried but failed. Ended up doing without serverless@github-action by writing my own

name: GitHub Actions Deploy ID Dev
on:
  push:
    branches:
      - main
jobs:
  deploy:
    name: deploy
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [14.x]
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - run: yarn install
      - run: yarn workspace @berry/shared build
      - run: node ./node_modules/serverless/bin/serverless.js config credentials --provider aws --key ${{ secrets.AWS_ACCESS_KEY_ID }} --secret ${{ secrets.AWS_SECRET_ACCESS_KEY }} --profile papaya --overwrite
      - run: node ../../node_modules/serverless/bin/serverless.js deploy --aws-s3-accelerate --stage dev --verbose
        working-directory: ./services/id
        env:
          SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          SLS_DEBUG: 1

@walkerab
Copy link

walkerab commented Aug 7, 2021

I got around this by moving the serverless project to the root of the repo.

Not ideal but it got me unstuck.

@russellc92
Copy link

See: #53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants