# npm-cloudartifact-workflow-samples **Repository Path**: HuaweiCloudDeveloper/npm-cloudartifact-workflow-samples ## Basic Information - **Project Name**: npm-cloudartifact-workflow-samples - **Description**: github workflow samples, 华为云cloudartifact npm私仓推送拉取npm package样例 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master-dev - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-05-26 - **Last Updated**: 2022-11-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 使用华为云CloudArtifact npm 私仓workflows样例 **本READEME指导是基于[npm CloudArtifact Action](https://github.com/marketplace/actions/huaweicloud-npm-cloudartifact)使用华为云CloudArtifact npm 私仓Workflows样例** 私有依赖库(CloudArtifact)是发布服务([CloudRelease](https://support.huaweicloud.com/cloudrelease/index.html))的语言软件仓库功能。用于管理私有组件(开发者通俗称之为私服),包括Maven、Npm、Go、PyPI、Rpm等多种仓库格式。 使用华为云CloudArtifact npm 私仓有如下场景: 1.npm publish 推送npm package到 CloudArtifact npm 私仓 2.npm install 拉取CloudArtifact npm 私仓的npm package ## **前置工作** (1) [新建私有依赖库](https://support.huaweicloud.com/usermanual-releaseman/cloudrelease_01_0008.html) (2) [管理用户权限](https://support.huaweicloud.com/usermanual-releaseman/cloudrelease_01_0011.html) (3) CloudArtifact npm 私仓账号信息获取 [私有依赖库首页](https://devcloud.cn-north-4.huaweicloud.com/cloudartifact/repository)->点击需要的npm仓库->右上角操作指导->点击下载配置文件->npm配置在下载的npmrc文件当中 ![图一](imgs/npm-config-download.PNG) ## 参数说明 npm-cloudartifact-action 两个参数`registry_list`(npm仓库源)和`auth_list`(仓库认证信息)都属于npm用户配置文件~/.npmrc文件的配置信息。其中仓库认证信息中${{ secret.NPM_AUTH }},格式为 (user:password).base64,即用户名和密码中间用冒号隔开,通过base64编码后的字符串。如:dGVzdDoxMjM= npm配置信息分为不包含@scope和包含[@scope](https://docs.npmjs.com/cli/v6/using-npm/scope)两种方式。目前华为云CloudArtifact npm 私仓支持的是scope方式,含scope的方式支持配置多仓库。下面给出两个参数的具体的样例。 ### 1.不包含@scope .npmrc配置格式 ``` registry=https://some.npm.registry/ _auth=(user:password).base64 # 用户名和密码中间用冒号隔开,通过base64编码后的字符串。如:_auth=dGVzdDoxMjM= ``` action中参数配置例子 ```yml steps: - uses: huaweicloud/npm-cloudartifact-action@v1.1.0 with: registry_list: | registry=https://some.npm.registry/ auth_list: | _auth=${{ secrets.NPM_AUTH }} ``` ### 2.包含@scope,若@scope为"@cloud" .npmrc配置格式 ``` @cloud:registry=https://devrepo.devcloud.cn-north-4.huaweicloud.com/artgalaxy/api/npm/{{repo_name}}/ //devrepo.devcloud.cn-north-4.huaweicloud.com/artgalaxy/api/npm/{{repo_name}}/:_auth=(user:password).base64 ``` action中参数配置例子 ```yml steps: - uses: huaweicloud/npm-cloudartifact-action@v1.1.0 with: registry_list: | @cloud:registry=https://devrepo.devcloud.cn-north-4.huaweicloud.com/artgalaxy/api/npm/{{repo_name}}/ auth_list: | //devrepo.devcloud.cn-north-4.huaweicloud.com/artgalaxy/api/npm/{{repo_name}}/:_auth=${{ secrets.NPM_AUTH }} ``` ## **CloudArtifact npm 私仓workflows样例** ### 1.npm publish: 推送npm package到 CloudArtifact npm 私仓 步骤说明: (1)代码检出 (2)华为云CloudArtifact npm 私仓配置 (3)npm publish 推送npm package到 CloudArtifact npm 私仓 ```yaml name: npm Cloudartifact Action Publish Demo on: push: branches: master jobs: Publish-to-CloudArtifact-npm: runs-on: ubuntu-latest steps: # 代码检出 - uses: actions/checkout@v2 # GitHub Action环境默认nodejs版本为16,可以根据自己项目需求修改nodejs版本 - name: Setup node uses: actions/setup-node@v3 with: node-version: 16 # 华为云CloudArtifact npm 私仓配置 - name: Setup Huawei Cloud npm CloudArtifact uses: huaweicloud/npm-cloudartifact-action@v1.1.0 with: registry_list: | @cloud:registry=https://devrepo.devcloud.cn-north-4.huaweicloud.com/artgalaxy/api/npm/{{repo_name}}/ auth_list: | //devrepo.devcloud.cn-north-4.huaweicloud.com/artgalaxy/api/npm/{{repo_name}}/:_auth=${{ secrets.NPM_AUTH }} # 推送npm二进制包到华为云CloudArtifact npm 私仓 - name: publish npm package run: | npm publish ``` 详情可参考 ./github/workflows/npm-cloudartifact-action-publish-demo.yml >【注意】 > 1.此样例假设要推送的npm package名称为:@cloud/vue-demo (即本仓库package.json文件中name值) > 2.私有依赖库CloudArtifact中npm私仓路径必须包含@cloud > ![npm-repo-scope](imgs/npm-repo-scope.PNG) > 3.action参数registry_list包含@cloud的npm仓库 > 4.使用到账号密码等敏感信息,建议将参数内容设置在GITHUB的Settings->Secrets->Actions ### 2.npm install: 拉取CloudArtifact npm 私仓的npm package 步骤说明: (1)代码检出 (2)华为云CloudArtifact npm 私仓配置 (3)npm install 拉取CloudArtifact npm 私仓的npm package ```yaml name: npm Cloudartifact Action Install Demo on: push: branches: master jobs: Install-CloudArtifact-npm: runs-on: ubuntu-latest steps: # 代码检出 - uses: actions/checkout@v2 # GitHub Action环境默认nodejs版本为16,可以根据自己项目需求修改nodejs版本 - name: Setup node uses: actions/setup-node@v3 with: node-version: 16 # 华为云CloudArtifact npm 私仓配置 - name: Setup Huawei Cloud npm CloudArtifact uses: huaweicloud/npm-cloudartifact-action@v1.1.0 with: registry_list: | registry=https://registry.npmjs.org/ @cloud:registry=https://devrepo.devcloud.cn-north-4.huaweicloud.com/artgalaxy/api/npm/{{repo_name}}/ auth_list: | //devrepo.devcloud.cn-north-4.huaweicloud.com/artgalaxy/api/npm/{{repo_name}}/:_auth=${{ secrets.NPM_AUTH }} # 拉取CloudArtifact npm 私仓的npm package - name: install npm package run: | npm install ``` 详情可参考 ./github/workflows/npm-cloudartifact-action-install-demo.yml >【注意】 > 1.npm仓库存在npm package @cloud/vue-demo > 2.action参数registry_list包含@cloud的npm仓库 > 3.使用到账号密码等敏感信息,建议将参数内容设置在GITHUB的Settings->Secrets->Actions ## workflow sample中使用公网地址说明 1. [npm官方镜像源](https://registry.npmjs.org) 2. 代码demo使用 [Core Docs](https://vuejs.org) 3. 代码demo使用 [Forum](https://forum.vuejs.org) 4. 代码demo使用 [Gitter Chat](https://gitter.im/vuejs/vue) 5. 代码demo使用 [Twitter](https://twitter.com/vuejs) 6. 代码demo使用 [vue-router](http://router.vuejs.org) 7. 代码demo使用 [vue](http://vuex.vuejs.org) 8. 代码demo使用 [vue-loader](http://vue-loader.vuejs.org) 9. 代码demo使用 [awesome-vue](https://github.com/vuejs/awesome-vue)