Skip to content

Commit

Permalink
Create deploy.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Jothi Priyadharshan authored Jul 27, 2021
1 parent cb609a7 commit 0acd415
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: npm-publish
on:
push:
branches:
- master # Change this to your default branch
jobs:
npm-publish:
name: npm-publish
runs-on: ubuntu-latest

steps:
# Publish to Node Package Manager
- name: Checkout Repo
uses: actions/checkout@main

- name: Setup Node.js (NPM)
uses: actions/setup-node@master
with:
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'

- name: Use cached node_modules
uses: actions/cache@master
with:
path: node_modules
key: nodeModules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
nodeModules-
- name: Install dependencies
run: yarn install --frozen-lockfile
env:
CI: true

- name: Update Publish Config
run: sed -i 's^registry-url^registry.npmjs.org^' package.json

- name: Publish to NPM
run: npm publish --access public
env:
CI: true
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

gpr-publish:
name: gpr-publish
runs-on: ubuntu-latest

steps:
# Publish to GitHub Package Registry
- name: Checkout Repo
uses: actions/checkout@main

- name: Store lowercase actor name
run: |
echo 'actor_name<<EOF' >> $GITHUB_ENV
echo ${{ github.actor }} | tr "A-Z" "a-z" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Store package name
run: |
echo 'package_name<<EOF' >> $GITHUB_ENV
grep -Po '"name": *\K"[^"]*"' package.json | grep -oP '"\K[^"\047]+(?=["\047])' >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Setup Node.js (GPR)
uses: actions/setup-node@master
with:
node-version: '12.x'
registry-url: https://npm.pkg.github.com/
scope: '${{ env.actor_name }}'

- name: Use cached node_modules
uses: actions/cache@master
with:
path: node_modules
key: nodeModules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
nodeModules-
- name: Install dependencies
run: yarn install --frozen-lockfile
env:
CI: true

- name: Update Package Name
run: |
sed -i 's,"name": "${{ env.package_name }}","name": "@${{ env.actor_name }}/${{ env.package_name }}",' package.json
cat package.json
- name: Update Publish Config
run: |
sed -i 's^registry-url^npm.pkg.github.com/@${{ env.actor_name }}^' package.json
cat package.json
- name: Publish to GitHub Package Registry
run: npm publish --access public
env:
CI: true
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 0acd415

Please sign in to comment.