serverless / github-action

:zap::octocat: A Github Action for deploying with the Serverless Framework
Apache License 2.0
662 stars 174 forks source link

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

Closed giorgosera closed 2 years ago

giorgosera commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

@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 commented 3 years ago

I'm also struggling to configure the working directory

deathemperor commented 3 years ago

same, would love to know which fixed it

giorgosera commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

Not ideal but it got me unstuck.

russellc92 commented 3 years ago

See: #53