[英]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:我曾尝试使用
gzipper
和gzip-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-cli
或gzipper
,它们将被保存到当前项目的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.json
的bin
字段的文档:
On install, npm will symlink that file into
prefix
/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.