NPM access Travis CI package

Operation process

0. Create a Travis account and grant github access

1. Initialization

1.1 Installing the Travis CLI Tool

$ sudo gem install travis
Copy the code

Create an empty.travis. Yml file.

npm auth token

The NPM Auth token gives Travis access to your NPM privileges and the ability to distribute versions.

2.1 Log in to NPM locally. (If you have logged in, you can skip it. If you have not registered, you can register in the link.)

# Tips: If you set the NPM source as an unofficial source, you need to switch back to the official source and log in again
$ npm adduser Then enter your NPM account information
Copy the code

2.3 Obtaining the AuTH Token.

There are two ways to obtain the token in the document, so we can choose one of them

Create new token to https://www.npmjs.com/settings/username/tokens/. Select Read and Publiush. copy token

Then use the Travis CLI to generate the NPM configuration (this step needs to be done in the project root directory)

# log in first
$ travis login --pro Then enter the information
Copy the code

No implicit conversion of nil into String. For a full error report, run Travis Report –pro fails. Issue. In this case, we can go directly to the Travis user Settings, copy our API authentication token, and manually add it to the ~/. Travis /config.yml file.

Verify that the login succeeded

$ travis accounts --pro 
flytam (Flytam): not subscribed, 44 repositories # indicates success
Copy the code
$ travis setup npm  --pro# Generate NPM configuration, there is a step of the API key is just input 'NPM auth token', select 'encrypt', then it will automatically generate something like the following in YML
Copy the code

After completion, the following initial configuration is generated. Indicates that all the tags on the master trigger the NPM to send packets

language: node_js
node_js:
    - "12.13"
deploy:
    provider: npm

    email: [email protected]
    api_key:
        secure: xxxxx
    on:
        tags: true
        branch: master
        repo: flytam/babel-plugin-resolve-config-json
Copy the code

If you run the NPM version XXX command, the system automatically commits the tag and pushes the tag to the remote device according to the following rules. For convenience we can set the NPM hook. (Postversion means the command that is automatically executed after NPM version xx is entered)

# NPM version number// version = v1.0.0 NPM version patch // v1.0.1 NPM version prepatch // v1.0.2-0 NPM version minor // v1.1.0 NPM version Major / / v2.0.0Copy the code
"Postversion ": "git push --follow tags"}Copy the code

At this point, go to Github and CI and you can see that our operation is successful

It is possible to encounter a summary of pits

  • npmLogin remember to cut back to the official source

If taobao source and other related unofficial sources have been switched before, NPM login and release will fail. Run NPM config set Registry http://www.npmjs.org to switch back to the official source. (NRM is recommended for source management)

  • Pro is required for all Travis CLI commands mentioned above. We use travis-ci.com instead of travis-ci.org. Com and org use different solutions. If com uses a command without –pro, it will cause errors such as publishing failure. (If the old project uses travis-ci.org, there is a one-click migration to travis-ci.com, and the official announcement states that the new project can only use travis-ci.com).

  • Travis Login –pro failed. You need to manually configure the API token, as mentioned above

Original address, code word is not easy, your praise is my biggest motivation