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

Firebase deploy hosting not running predeploy scripts #1113

Closed
nickgzzjr opened this issue Jan 18, 2019 · 19 comments
Closed

Firebase deploy hosting not running predeploy scripts #1113

nickgzzjr opened this issue Jan 18, 2019 · 19 comments

Comments

@nickgzzjr
Copy link

I upgrade to firebase-tools 6.3.0 and when I deploy to hosting, it is not running my predeploy scripts. In specific I am running sass and webpack. I downgraded to 6.2.0 and everything works fine.

Environment info

firebase-tools: 6.3.0

Platform: macOS

Test case

Steps to reproduce

Run firebase deploy --only hosting

Expected behavior

"predeploy" scripts should run.

Actual behavior

"predeploy" scripts are not running.

@mbleigh
Copy link
Contributor

mbleigh commented Jan 18, 2019

Can you provide your firebase.json or the relevant parts? I just tried this locally and my predeploy ran as expected.

@nickgzzjr
Copy link
Author

Absolutely, I don't think there is anything fancy going on.

Actually I just double checked, the rm command is working, but sass and webpack is not working, which is why I noticed the issue. My assets were gone and never repopulated when I deployed.

{
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ],
    "source": "functions"
  },
  "hosting": {
    "predeploy": [
      "rm -f hosting/public/assets/index.js hosting/public/assets/index.js.map hosting/public/assets/vendors.index.js hosting/public/assets/vendors.index.js.map hosting/public/assets/style.css hosting/public/assets/style.css.map",
      "sass --style=compressed --no-source-map hosting/scss/style.scss:hosting/public/assets/style.css",
      "webpack --env=production --config=hosting/webpack.config.js --context=hosting"
    ],
    "public": "hosting/public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "firestore": {
    "rules": "firestore.rules"
  }
}

@mbleigh
Copy link
Contributor

mbleigh commented Jan 18, 2019

What does your output look like when you deploy? Do you see Running command: sass --style=compressed --no-source-map hosting/scss/style.scss:hosting/public/assets/style.css? I just tried another test with multiple commands and they all ran.

Could it perhaps be an issue with not having the correct global modules installed? Wonder if you'd have more success by prepending npx to the last two commands.

@nickgzzjr
Copy link
Author

@mbleigh Yes I do see Running command: ...

I tried using npx, but I am getting the same outcome.

My output looks like this...

i  deploying hosting
Running command: rm -f hosting/public/assets/index.js hosting/public/assets/index.js.map hosting/public/assets/vendors.index.js hosting/public/assets/vendors.index.js.map hosting/public/assets/style.css hosting/public/assets/style.css.map
Running command: npx sass --style=compressed --no-source-map hosting/scss/style.scss:hosting/public/assets/style.css
Running command: npx webpack --env=production --config=hosting/webpack.config.js --context=hosting
✔  hosting: Finished running predeploy script.
i  hosting[atlas-wearables-stage]: beginning deploy...
i  hosting[atlas-wearables-stage]: found 1 files in hosting/public
✔  hosting[atlas-wearables-stage]: file upload complete
i  hosting[atlas-wearables-stage]: finalizing version...
✔  hosting[atlas-wearables-stage]: version finalized
i  hosting[atlas-wearables-stage]: releasing new version...
✔  hosting[atlas-wearables-stage]: release complete

✔  Deploy complete!

@mbleigh
Copy link
Contributor

mbleigh commented Jan 18, 2019

Does running the command do what you expect outside of running it as part of a deploy? What if you added something like && echo 'hello world' to the end of each command that isn't running correctly? That would tell you whether the command is running and silently succeeding without doing what you expect.

@nickgzzjr
Copy link
Author

Yes it works outside of deploy, that's how I was able to get it to work. Also it works with firebase-tools 6.2.0.

That's a good idea: looks like it's not executing the echo.

i  deploying hosting
Running command: rm -f hosting/public/assets/index.js hosting/public/assets/index.js.map hosting/public/assets/vendors.index.js hosting/public/assets/vendors.index.js.map hosting/public/assets/style.css hosting/public/assets/style.css.map && echo 'hello world 1'
hello world 1
Running command: sass --style=compressed --no-source-map hosting/scss/style.scss:hosting/public/assets/style.css && echo 'hello world 2'
Running command: webpack --env=production --config=hosting/webpack.config.js --context=hosting && echo 'hello world 3'
✔  hosting: Finished running predeploy script.

Also I tried running 3 simple commands. Looks like that's working...

i  deploying hosting
Running command: echo 'hello world 1'
hello world 1
Running command: echo 'hello world 2'
hello world 2
Running command: echo 'hello world 3'
hello world 3
✔  hosting: Finished running predeploy script.

I tried deleting the sass command, and the webpack command, but same outcome. I also tried running the sass and webpack (without rm) command by itself and they don't work.

@mbleigh
Copy link
Contributor

mbleigh commented Jan 31, 2019

It seems like it's silently failing the commands...but perhaps returning a success exit code? I'm at a bit of a loss as to what to ask you to try next, because I haven't been able to replicate this behavior. Are there any flags you can add to the sass/webpack commands to make them more verbose? If you do sass ... || echo "hello world" does that output?

@mbleigh mbleigh added the Needs: Author Feedback Issues awaiting author feedback label Jan 31, 2019
@google-oss-bot
Copy link
Contributor

Hey @nickgzzjr. We need more information to resolve this issue but there hasn't been an update in 7 days. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Contributor

Since there haven't been any recent updates here, I am going to close this issue.

@nickgzzjr if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@ahaverty
Copy link

I'm seeing a similar issues since updating to version 6.3.0
I have been setting a variable and passing it into a script (simplified example of my use case below).

"predeploy": [
"TEST=123 && echo $TEST"
]

I've added a console log to see the translated command, which seems to be fine, but it doesn't actually attempt to execute the echo (or anything I try). I have a feeling it's something to do with some characters like '$' in my case or ':' in @nickgzzjr case.
image

It's not my exact issue, but I'm finding similar bug reports on the cross-env library that firebase tools is using kentcdodds/cross-env#192

@ahaverty
Copy link

Actually, it works for me on v6.2.2 but since v6.3.0 it hasn't executed properly.
I think it has something to do with the regex introduced here v6.2.2...v6.3.0#diff-14e512e4127bbadd8843e44146995faa

My previous example probably isn't the best, my real example is:

"predeploy": [
    "FIREBASE_PROJECT=$(firebase use) npm run setup-functions-config"
]

where my package.json has:

"scripts": {
        ...
        "setup-functions-config": "ts-node config-generator.ts",
        ...
    },

which uses process.env.FIREBASE_PROJECT within the typescript program.

@ahaverty
Copy link

Ah, there was a change from cross-env.js to cross-env-shell.js at that time. Looking at their README, variable assigning works differently 🤔

@ahaverty
Copy link

Found the PR: #1068

image

@AbeHaskins oops, but you caught us 😅
Any tips on how we can set an environment variable and then execute an npm script since v6.3.0?

@ahaverty
Copy link

Also, @AbeHaskins the change caused one of our very important predeploy scripts that we use to setup configurations in CI to silently not execute. It was very lucky that we caught it in our local environment, perhaps it's worthy of a warning or throwing an error in the next tools release if possible.

@ahaverty
Copy link

Your PR comment reminded me of this 😅
image

@ahaverty
Copy link

Worked around it by moving the variable assigning into the npm script, which isn't ideal but will do for now.

@nickgzzjr
Copy link
Author

Anyone still having the original issue I was having, a good work around is to use npm scripts.

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Apr 22, 2019
@danieldanielecki
Copy link

Exactly the same problem, predeploy isn't executed automatically anymore. We have to execute it explicitly in the CI's, at least it was my case with GitLab CI.

@tkhduracell
Copy link

I was using npm scripts to do my predeploy but my npm command was silently failing when setting envs before the command. After removing my variables set before the command (ENV=.. npm run ... ) the error became apparent again.

I was using npm --prefix \"$RESOURCE_DIR\" run predeploy but hosting targets with the "public": "app/dist" the RESOURCE_DIR is set to that folder which is not the module root in my case. Hence npm --prefix \"$RESOURCE_DIR\"/.. run predeploy -- ...args

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

No branches or pull requests

6 participants