简体   繁体   English

构建后使用 gzip 进行 Github Actions

[英]Github Actions with gzip after build

I have been trying to work out a way to gzip my build files after a build within a github action.我一直在尝试找出一种在 github 操作中构建后 gzip 构建文件的方法。 My build doesn't automatically do this, and I'm not sure where or when it should be zipping.我的构建不会自动执行此操作,而且我不确定应该在何处或何时进行压缩。

My action has a working run command that builds the project, but then the zipping either fails or just doesn't work depending on how I run it.我的操作有一个构建项目的运行命令,但随后压缩要么失败,要么根本不起作用,这取决于我如何运行它。

This is how I've tried lately:这是我最近尝试的方式:

- name: Build
  run: |
    npm ci
    npm run build --prod --aot

- name: GZIP
  run: |
    npm install gzip-cli
    gzip ./dist/*.js -k -9

I'm sure the answer here is either "you can't do that" or "you can't do that", but I don't know where to go from here.我确定这里的答案是“你不能那样做”或“你不能那样做”,但我不知道从哪里开始。 My server does not zip the files itself and I'm not sure how to make github do it.我的服务器本身不会压缩文件,我不确定如何让 github 做到这一点。 I need all of the js files to have gz files.我需要所有的js文件都有gz文件。

I have tried using gzipper as well as gzip-cli and the console usually outputs this:我曾尝试使用gzippergzip-cli ,控制台通常会输出:

  npm install gzipper
  gzipper --exclude jpg,jpeg,png,svg ./dist
  shell: /bin/bash -e {0}
npm WARN karma-jasmine-html-reporter@1.5.1 requires a peer of jasmine-core@>=3.5 but none is installed. You must install peer dependencies yourself.

+ gzipper@3.4.2
updated 1 package and audited 19029 packages in 11.676s

33 packages are looking for funding
  run `npm fund` for details

found 2 high severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details
/home/runner/work/_temp/96763ca6-0048-4812-a8bb-72bf33d14fcc.sh: line 2: gzipper: command not found
##[error]Process completed with exit code 127.

It looks like it installs just fine, but then it shows the command can't be found (whether gzipper or gzip-cli).看起来它安装得很好,但是它显示找不到命令(无论是 gzipper 还是 gzip-cli)。

If I were to use plain old gzip , I don't get any error.如果我使用普通的旧gzip ,我不会收到任何错误。 It runs, but does not actually zip anything.它运行,但实际上并没有压缩任何东西。 Could it be github is temporarily storing the files somewhere before uploading it?可能是 github 在上传文件之前暂时将文件存储在某个地方吗?

With the current method you're using to install gzip-cli or gzipper , they'll be saved to the current project's node_modules folder.使用当前用于安装gzip-cligzipper ,它们将被保存到当前项目的node_modules文件夹中。 Their executables will also be installed in node_modules/.bin (which can be found by running npm bin ).它们的可执行文件也将安装在node_modules/.bin (可以通过运行npm bin找到)。 However, your project dependency executables will typically not be available in the PATH environment variable unless you install them globally.但是,除非您全局安装它们,否则您的项目依赖可执行文件通常在PATH环境变量中不可用。

From the docs for the bin field for a dependency's package.json :来自依赖项package.jsonbin字段文档

On install, npm will symlink that file intoprefix /bin for global installs, or ./node_modules/.bin/ for local installs.在安装时,npm 会将该文件符号链接到prefix /bin以用于全局安装,或./node_modules/.bin/用于本地安装。

As such, you should either:因此,您应该:

  • Install the dependencies globally with the -g flag.使用-g标志全局安装依赖项。 If npm's .bin directory is included in the PATH , you can easily execute the commands.如果PATH包含 npm 的.bin目录,则可以轻松执行命令。

  • Run the commands with $(npm bin)/ appended to the command:运行带有$(npm bin)/附加到命令的命令:

     $(npm bin)/gzip ./dist/*.js -k -9
  • Or add a script that does the same thing.或者添加一个执行相同操作的脚本 Typically npm scripts will have dependency executables available to them in the PATH environment variable :通常,npm 脚本将PATH环境变量中具有可用的依赖可执行文件

     { "scripts: { "gzip-files": "gzip ./dist/*.js -k -9" }, "dependencies": { "gzip-cli": "/* version range */" } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 webpack 在 GitHub Actions 中为生产构建 - Cannot build for production in GitHub Actions using webpack GitHub 操作 - 为什么使用不同的节点版本构建? - GitHub Actions - Why build with different Node versions? npm 错误! 在 github 操作上构建脚本期间失败 - npm ERR! Failed during build script on github actions Github 操作 - CI 因构建工件而卡住(将 typescript 转换为 javascript) - Github actions - CI is stuck because of build artifacts (to convert typescript to javascript) 使用 Github 操作构建 Node/Express 并部署到 Azure Web 应用程序 - Build Node/Express using Github Actions and deploy to Azure Web App 通过 Github Actions 部署后 POST 到 /generate OpenAPI 上的 405 - NextJS - 405 on POST to /generate OpenAPI after deployment through Github Actions - NextJS 从 Github Actions 部署后应用程序立即崩溃 - App crashing right away after deploy from Github Actions Github 动作笑话 - Github Actions Jest github-actions 如何在(生产)构建结果而不是开发模式上运行测试 - How github-actions run test on (production) build results instead of develop mode Electron 构建在本地工作,但在代码提交到 Github 后它会中断 - Electron build works locally but after code is committed to Github it breaks
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM