简体   繁体   中英

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.

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 . This is creating issues because we don't have access to the older versions of our package on the artifactory.

Currently our pipeline in GitHub actions looks like this (summarized):

(runs on linux virtual machine with access to our npm registry)

  1. npm install
  2. Set up a GitHub bot to bump the version and push it to repo
  3. Build the packages for publishing
  4. Create artifacts using Githubs own upload-artifact action (used in the next workflow)
  5. npm publish (to our private registry)
  6. Then our separate deployment pipeline handles the rest after publishing

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.

  1. Setup JFrog CLI (with access token)
  2. Download package A artifact using GitHubs own download-artifact action
  3. Create version string variable (eg "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"
  2. Rename the.tgz file to include version:
mv package-a.tgz "package-a-${PACKAGEVERSION}.tgz"
  1. Upload to artifactory using jf rt u command
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.

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.

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.

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. Did you try to configure it at the workflow level?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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