简体   繁体   English

发布 NPM package 时如何在 JFrog CLI 中包含版本号?

[英]How to include version number in JFrog CLI when publishing NPM package?

I've been working with the JFrog CLI tool a lot lately to upload our NPM package to our company artifactory which is working fine, however it requires a bit of "ugly" solutions with manual renaming in our GitHub actions pipeline among other things to get it to work as I want it to and I have one problem left before I can be happy with the uploading process.我最近一直在使用 JFrog CLI 工具来将我们的 NPM package 上传到我们公司的工件,这工作正常,但是它需要一些“丑陋”的解决方案,在我们的 ZD3B7C913CD04EBFEC0 管道中手动重命名以获取其他操作等它可以按我的意愿工作,但在我对上传过程感到满意之前,我还有一个问题。

The issue is that the.tgz file that gets uploaded to the artifactory isn't including the version in the file name so instead of being called file-name-1.0.0.tgz it's just file-name.tgz .问题是上传到工件的 .tgz 文件不包括文件名中的版本,因此它不是被称为file-name-1.0.0.tgz它只是file-name.tgz This is creating issues because we don't have access to the older versions of our package on the artifactory.这会造成问题,因为我们无法访问工件上旧版本的 package。

Currently our pipeline in GitHub actions looks like this (summarized):目前我们在 GitHub 动作中的管道看起来像这样(总结):

(runs on linux virtual machine with access to our npm registry) (在 linux 虚拟机上运行,可以访问我们的 npm 注册表)

  1. npm install npm安装
  2. Set up a GitHub bot to bump the version and push it to repo设置一个 GitHub 机器人来提升版本并将其推送到 repo
  3. Build the packages for publishing构建发布包
  4. Create artifacts using Githubs own upload-artifact action (used in the next workflow)使用 Githubs 自己的上传工件操作创建工件(在下一个工作流程中使用)
  5. npm publish (to our private registry) npm 发布(到我们的私有注册表)
  6. Then our separate deployment pipeline handles the rest after publishing然后我们单独的部署管道在发布后处理 rest

Once this workflow is finished, a second workflow is triggered to upload to the JFrog artifactory, using a self hosted linux runner with credentials for the artifactory.此工作流完成后,将触发第二个工作流上传到 JFrog 工件,使用带有工件凭据的自托管 linux 运行器。

  1. Setup JFrog CLI (with access token)设置 JFrog CLI(带有访问令牌)
  2. Download package A artifact using GitHubs own download-artifact action下载 package 使用 GitHub 自己的下载神器动作的神器
  3. Create version string variable (eg "1.0.1-alpha.1")创建版本字符串变量(例如“1.0.1-alpha.1”)
    - name: Create version string variable
        run: |
          PACKAGEVERSION=`jq -r .version package/package.json`
          echo $PACKAGEVERSION
  1. Compress package A using a7ul/tar-action@v1.1.0 to a tar file named "package-a.tgz"使用a7ul/tar-action@v1.1.0将 package A 压缩为名为“package-a.tgz”的 tar 文件
  2. Rename the.tgz file to include version:重命名 .tgz 文件以包含版本:
mv package-a.tgz "package-a-${PACKAGEVERSION}.tgz"
  1. Upload to artifactory using jf rt u command使用jf rt u命令上传到工件
jf rt u "package-a-${PACKAGEVERSION}.tgz"  "path/to/upload/directory/package-a-${PACKAGEVERSION}.tgz"

And then it downloads the other package and does the same thing.然后它下载另一个 package 并做同样的事情。

On the artifactory it doesn't show the version in the.tgz file name, instead it's just called package-a-.tgz so something in the renaming step goes wrong and I can't find a solution for it, even though I've tried many different approaches to this.在工件上,它没有在 .tgz 文件名中显示版本,而只是称为package-a-.tgz所以在重命名步骤中出现了问题,我找不到解决方案,即使我'为此尝试了许多不同的方法。

I'm also aware that the JFrog CLI has npm support built in, however we can't use it in our pipeline because of the credentials required, or at least I don't know how.我也知道 JFrog CLI 内置了 npm 支持,但是由于需要凭据,我们不能在管道中使用它,或者至少我不知道如何使用。

I'm very close to getting it to work as we want, it's just this short renaming that's not working out.我非常接近让它按照我们的意愿工作,只是这个简短的重命名没有成功。 Any help is very much appreciated.很感谢任何形式的帮助。 Thank you谢谢

My guess is that your PACKAGEVERSION variable is out of scope, and is empty in the stages of renaming and upload.我的猜测是您的PACKAGEVERSION变量超出了 scope,并且在重命名和上传阶段为空。 Did you try to configure it at the workflow level?您是否尝试在工作流级别对其进行配置?

https://docs.github.com/en/actions/learn-github-actions/environment-variables https://docs.github.com/en/actions/learn-github-actions/environment-variables

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM