2

每当提交被推送到主分支时,我想使用 git hub 操作来测试和构建我的 elm 包,因为我的操作.yml文件看起来像这样

name: CI

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Setup Elm environment
      uses: JorelAli/setup-elm@v1
      with:
        # Version of Elm to use. E.g. 0.19.1
        elm-version: 0.19.1
    - run: |
        sudo npm install -g elm-test # this fails
        elm-test
        elm make

用于测试我想使用elm-test它可以通过安装npm但命令sudo npm install -g elm-test失败

/usr/local/bin/elm-test -> /usr/local/lib/node_modules/elm-test/bin/elm-test

> elmi-to-json@1.3.0 install /usr/local/lib/node_modules/elm-test/node_modules/elmi-to-json
> binwrap-install

ERR Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/elm-test/node_modules/elmi-to-json/unpacked_bin'
    at Object.mkdirSync (fs.js:823:3)
    at /usr/local/lib/node_modules/elm-test/node_modules/binwrap/binstall.js:46:10
    at new Promise (<anonymous>)
    at untgz (/usr/local/lib/node_modules/elm-test/node_modules/binwrap/binstall.js:21:10)
    at binstall (/usr/local/lib/node_modules/elm-test/node_modules/binwrap/binstall.js:11:12)
    at install (/usr/local/lib/node_modules/elm-test/node_modules/binwrap/install.js:20:10)
    at Object.install (/usr/local/lib/node_modules/elm-test/node_modules/binwrap/index.js:14:14)
    at Object.<anonymous> (/usr/local/lib/node_modules/elm-test/node_modules/binwrap/bin/binwrap-install:18:9)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
    at internal/main/run_main_module.js:17:11 {
  errno: -13,
  syscall: 'mkdir',
  code: 'EACCES',
  path: '/usr/local/lib/node_modules/elm-test/node_modules/elmi-to-json/unpacked_bin'
}
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/elm-test/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! elmi-to-json@1.3.0 install: `binwrap-install`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the elmi-to-json@1.3.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2020-02-03T17_50_06_232Z-debug.log

关于如何elm-test在 git hub 操作中安装的任何建议?

编辑:没有sudo错误变成

npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] {
npm ERR!   stack: "Error: EACCES: permission denied, access '/usr/local/lib/node_modules'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2020-02-04T13_41_34_534Z-debug.log
4

2 回答 2

3

感谢@toastal 评论,我找到了另一个解决方案。即使用命令设置package.json文件npm,然后将其添加elm-test为依赖项

npm install -D elm-test

您也可能想要添加node_modules到您.gitignore的忽略npm安装文件夹中。

然后在yml文件中你可以运行命令npm installelm-test安装。然后你可以调用它

./node_modules/elm-test/bin/elm-test

我的yml文件现在看起来像这样

name: Tests

on: [push]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Setup Elm environment
      uses: JorelAli/setup-elm@v1
      with:
        # Version of Elm to use. E.g. 0.19.1
        elm-version: 0.19.1
    - name: install npm dependencies
      run: npm install
    - name: Test
      run: ./node_modules/elm-test/bin/elm-test
    - name: check documentation
      run: |
        elm make --docs=docs.json
        rm docs.json

于 2020-02-04T19:23:34.157 回答
2

感谢@glennsl,我找到了一个解决方案:指定 npm 全局安装包的位置。由于运行该操作的运行器无法访问/usr/local/libnpm,因此无法在全局级别上安装任何东西。解决方案(如此所述)是创建一个文件夹作为“全局”安装文件夹并配置 npm 以使用它。还需要将新文件夹添加到PATH环境变量中。

所以我的yml文件现在看起来像这样

name: CI

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Setup Elm environment
      uses: JorelAli/setup-elm@v1
      with:
        # Version of Elm to use. E.g. 0.19.1
        elm-version: 0.19.1
    - run: |
        mkdir ~/.npm-global
        npm config set prefix '~/.npm-global'
        PATH=~/.npm-global/bin:$PATH
        npm install -g elm-test
        elm-test
        elm make
于 2020-02-04T15:24:13.597 回答