0

Locally, running tsc or tsc -w in parallel to npm t -- --watch all work, but trying to replicate what I have into Github CI hasn't been working. For some reason I'm not even able to print the folders with ls. And the installation of both TypeScript and Jest seem to be successful, though.

When it runs inside Github CI, I simply receive a log of all of the possible commands from tsc right below Run tsc and a Error: Process completed with exit code 1..

This is my current setup inside Github CI:

...

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Installing TypeScript
        run: npm i -D typescript
      - name: Installing Jest
        run: npm i -D jest
      - name: Compiling TypeScript Code
        run: tsc
      - name: Running Tests
        run: npm t

And this is my package.json:

{
  ...
  "main": "dist/content.js",
  "scripts": {
    "test": "jest",
    "testwatch": "jest --watchAll"
  },
  "devDependencies": {
    "@types/jest": "^26.0.15",
    "jest": "^26.6.2",
    "ts-jest": "^26.4.3",
    "typescript": "^4.0.5"
  }
}

And the only things I think are relevant in my tsconfig.json are:

{
  "outDir": "./dist/",
  "rootDir": "./lib/",
}

Have I made a mistake in this setup? What have I missed? Here is the full setup of my project.

Philippe Fanaro
  • 6,148
  • 6
  • 38
  • 76
  • Why don't you install *all* of the dependencies? Also what do you mean it's not working, what *does* happen? – jonrsharpe Nov 07 '20 at 17:43
  • You mean something like `npm i -g -a`? It didn't work either unfortunately. I've also added a link to the run with the log inside Github. And all of my attempts and errors are in the Actions section of the project I linked. – Philippe Fanaro Nov 07 '20 at 17:59
  • No I mean literally just `npm i` (or `npm ci` if you're using the lock file correctly) - use the package file, that's what it's for. – jonrsharpe Nov 07 '20 at 18:03
  • Oh you forgot to actually check out your code, so you don't have the package file or anything else. See e.g. https://docs.github.com/en/free-pro-team@latest/actions/quickstart. – jonrsharpe Nov 07 '20 at 18:04
  • What do you mean with I forgot to check out my code exactly? Isn't it inside the `lib` folder and then `tsc` would compile the rest to JS before the tests with `npm t`? And I thought I didn't have to version-control `package-lock.json` because running `npm i` et al. would recreate it locally. – Philippe Fanaro Nov 07 '20 at 18:10
  • 1
    1. It's presumably in the lib directory in the repo, but you *haven't checked the repo out* into the CI environment. Again, read through the quick start. 2. Yes it will recreate it, but then you've fundamentally undermined the point of the lock file, which is to have a consistent set of dependencies everywhere. – jonrsharpe Nov 07 '20 at 18:13
  • Ah, you're right. I forgot the check out line inside the CI script. It was the first time I created a Github CI without first copying a template from somewhere, so I ended up forgetting that line. – Philippe Fanaro Nov 07 '20 at 18:21
  • With respect to the `package-lock.json`: I thought it's purpose was only to locally save time and space with caching. And I thought that uploading it to version control or using it inside a CI service could be annoying because then the dependencies wouldn't always be totally updated, and we would have to manage the `package-lock.json` file in the end. – Philippe Fanaro Nov 07 '20 at 18:24
  • Anyway, if you wish to answer the question with your `package-lock.json` insight and the correction of my CI with checking out the code, I will accept it as an answer. Or do you think it's better to close this question, as it was kinda like a typo in the end? It's a silly mistake, but I think it might help other people in the future. – Philippe Fanaro Nov 07 '20 at 18:25
  • I'd suggest deletion. You still don't have a proper [mre] in the question, and as you say it's effectively a typo. – jonrsharpe Nov 07 '20 at 18:31
  • But it's tough to minimally reproduce this type of problem, isn't it? Since it's a CI problem, how would I provide a minimal example besides posting the CI scripts and a link to the project itself? And, with respect to deleting the question, I think I'm not going to. Let me know if you wish to answer it, otherwise I'm gonna wait ~1h and then answer it myself. Thanks a lot for the help anyways. – Philippe Fanaro Nov 07 '20 at 18:36
  • No, not particularly. Modern CI where there's a file defining the run makes it quite easy. You have the right files (although the CI config could be cut down - the last command never gets reached and the matrix isn't relevant) but have a vague description instead of the actual output. And this is really an XY problem - you've tried to fix the failing install by adding each package individually, but that wasn't the right thing to solve. – jonrsharpe Nov 07 '20 at 18:42
  • Also it's [tag:jestjs] not [tag:jest] but in this case you don't even get that far, it's not relevant. Not being able to print the folders should have told you the files weren't there, but you didn't actually show that either. – jonrsharpe Nov 07 '20 at 18:46

1 Answers1

0

As mentioned in the comments by @jonrsharpe, the whole problem can be summarized by something close to a typo. I have basically forgotten to check out the code into the CI environment. So, I would have to add this to the start of the steps:

...
steps:
  - name: Checking out the Project's Code
    uses: actions/checkout@v2
  ...

Another issue Jon pointed out was the absence of the package-lock.json file, which would serve the purpose of making the packages installed in the project consistent with those installed in the CI VM — use npm ci instead of npm i then.

Philippe Fanaro
  • 6,148
  • 6
  • 38
  • 76
  • Over the course of the last 24h I've basically incorporated all of @jonrsharpe's suggestions, and they seem to truly pay off. You can check them out in the [project](https://github.com/FanaroEngineering/ogs_kbd_nav) right now. – Philippe Fanaro Nov 08 '20 at 13:49