4

In my project, which has a folder structure as shown here:

dev-internal-web
-.firebase
-.github
-e2e
-functions
-node_modules
-src
(misc files)

I have a functions folder, which houses firebase functions. I'm looking to automate deployment of that through my actions script as shown below:

name: CI

on:
  push:
    branches:
    - master

jobs:
  hosting-deploy:
    name: Deploy Hosting
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@master
    - uses: actions/setup-node@master
      with:
        node-version: '10.x'
    - run: npm install
    - run: npm run build
    - uses: w9jds/firebase-action@master
      with:
        args: deploy --only hosting --project=tombstone-roleplay
      env:
        FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

  functions-deploy:
      name: Deploy Functions
      runs-on: ubuntu-latest

      steps:
      - uses: actions/checkout@master
      - uses: chrissank/deploy-firebase-functions@1.0.0
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
          TARGET: default

The actions for the firebase hosting on the Angular project inside the folder works fine, but the second script fails with the following error:

=== Deploying to 'tombstone-roleplay'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint /github/workspace/functions
> tslint --project tsconfig.json

sh: 1: tslint: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! functions@ lint: `tslint --project tsconfig.json`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /github/home/.npm/_logs/2020-10-04T14_06_06_215Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code1

After following the instructions in the comment to remove tslint and update my script to what can be found in this article: https://medium.com/mainlycoding-com/automate-firebase-functions-deployment-with-github-actions-ci-a0eb10fa308d, I received the following error:

=== Deploying to 'project-name'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint /github/workspace/functions
> tslint --project tsconfig.json

sh: 1: tslint: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! functions@ lint: `tslint --project tsconfig.json`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /github/home/.npm/_logs/2020-10-04T14_06_06_215Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code1

What am I doing wrong in the "functions-deploy" section?

Display Name
  • 122
  • 2
  • 21
  • I found a link: https://www.npmjs.com/package/tslint There is a red message there that can help: This package has been deprecated Author message: TSLint has been deprecated in favor of ESLint. Please see https://github.com/palantir/tslint/issues/4534 for more information. – MrTech Oct 05 '20 at 20:58
  • @MrTech after trying to remove the tslint (I just re-init'd firebase functions since I hadn't done any work there yet) I now am getting this error: `npm ERR! functions@ build: tsc` – Display Name Oct 06 '20 at 12:57
  • To move this along, I've found a detailed tutorial that can help you. https://medium.com/mainlycoding-com/automate-firebase-functions-deployment-with-github-actions-ci-a0eb10fa308d – MrTech Oct 06 '20 at 16:28
  • @MrTech I've given that a go and it's not working for me. I tried adding it to the end of my original file, and that didn't work, so I tried a new file (which didn't work either). The hosting has no problems but I copied the script at the bottom of that article and it doesn't work. – Display Name Oct 06 '20 at 18:05
  • To look into this further, were there any error messages when it did not work? – MrTech Oct 07 '20 at 17:51
  • I've updated the post to include the second error. – Display Name Oct 09 '20 at 03:05
  • I've found the error message link https://npm.community/t/elifecycle-npm-run-script-build/4722 and it seems like a memory issue (ELIFECYCLE). – MrTech Oct 09 '20 at 19:11
  • I'm not sure how I'd go about doing anything about that since it's GitHub actions; not my own PC. – Display Name Oct 10 '20 at 11:04
  • To uncover more detail, can you please provide /github/home/.npm/_logs/2020-10-04T14_06_06_215Z-debug.log – MrTech Oct 13 '20 at 22:02
  • Unfortunately I don't have access to that file since it's in GitHub actions. I'll look into if I'm able to find a way to access it, but I don't think there is a way to. – Display Name Oct 14 '20 at 18:51

1 Answers1

0

The deploy step is different to the build step (different folders), so you need to run npm install again or bring over the deploy node_module dependencies with your build artifact.

Here is my firebase.json:

{
  "functions": {
    "predeploy": [
      "npm --prefix ./functions/ install",
      "npm --prefix ./functions/ run lint",
      "npm --prefix ./functions/ run build"
    ],
    "source": "functions"
  }
}

There is some discussion over here: https://github.com/w9jds/firebase-action/issues/30

Also, ensure tslint, eslint, and tsc are in your devDependencies in your package.json file.