Difference between revisions of "Using github instead of npm"

From Logic Wiki
Jump to: navigation, search
Line 54: Line 54:
 
specify the full-scoped package name, such as @my-org/server
 
specify the full-scoped package name, such as @my-org/server
 
  npm install @logicmade/logic-booking
 
  npm install @logicmade/logic-booking
 +
 +
== Creating a GitHub Action to publish automatically ==
 +
in the root create a folder '''.github''' and in .github create another folder '''workflows''' and create a file in it called '''publish.yaml'''
 +
 +
=== Content of publish.yaml ===
 +
secret is not used in github package but it's useful in npm
 +
also in npm  extra line is needed under '''node-version: 14'''
 +
registry-url: https://registry.npmjs.org
 +
 +
<pre>
 +
name : "publish"
 +
 +
on:
 +
  push:
 +
    branches:
 +
      - main
 +
 +
jobs:
 +
  release:
 +
    name: publish
 +
    runs-on: ubuntu-latest
 +
    steps:
 +
      - name: checkout
 +
        uses: actions/checkout@v2.1.1
 +
      - name: node
 +
        uses: actions/setup-node@v2
 +
        with:
 +
          node-version: 14
 +
      - name: publish
 +
        run: npm publish
 +
        env:
 +
          NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
 +
</pre>

Revision as of 12:20, 1 September 2021


Create Personal Access Token in Github

https://github.com/settings/tokens

give full access rights for packages

Login with token

C:\Users\aiybar>npm login --scope=@OWNER --registry=https://npm.pkg.github.com
npm notice Log in on https://npm.pkg.github.com/
Username: aliiybar
Password: <TOKEN>
Email: (this IS public) ali.iybar@gmail.com
Logged in as aliiybar on https://npm.pkg.github.com/.

Publishing a package

Note: Package names and scopes must only use lowercase letters.

By default, GitHub Packages publishes a package in the GitHub repository you specify in the name field of the package.json file.

Publishing a package using a local .npmrc file

In the same directory as your package.json file, create or edit an .npmrc file to include a line specifying GitHub Packages URL and the account owner. Replace OWNER with the name of the user or organization account that owns the repository containing your project.

changes in package.json

"name": "@logicmade/logic-booking",
"repository":"git@github.com:Logicmade/package-logger.git",
"publishConfig": {
      "registry":"https://npm.pkg.github.com"
},

content of .npmrc file

//npm.pkg.github.com/:_authToken=<TOKEN>
@logicmade:registry=https://npm.pkg.github.com

Incrementing Version

npm version minor

publish

npm publish


Using the package

create .npmrc file in project and it shoul contain the line like

@logicmade:registry=https://npm.pkg.github.com

specify the full-scoped package name, such as @my-org/server

npm install @logicmade/logic-booking

Creating a GitHub Action to publish automatically

in the root create a folder .github and in .github create another folder workflows and create a file in it called publish.yaml

Content of publish.yaml

secret is not used in github package but it's useful in npm also in npm extra line is needed under node-version: 14

registry-url: https://registry.npmjs.org
name : "publish"

on: 
  push:
    branches:
      - main

jobs:
  release:
    name: publish
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v2.1.1
      - name: node
        uses: actions/setup-node@v2
        with:
          node-version: 14
      - name: publish
        run: npm publish
        env: 
          NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}