Skip to content

Commit

Permalink
Merge pull request #2 from rsksmart/ca-publish-package
Browse files Browse the repository at this point in the history
Updated project for publication
  • Loading branch information
ezequiel-rodriguez authored Sep 25, 2024
2 parents 5610e72 + e2be55d commit 1eec163
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Deploy library on NPM

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: "Check file existence"
id: check_files
uses: andstor/file-existence-action@v3
with:
files: "package.json, README.md"

- name: File exists
if: steps.check_files.outputs.files_exists != 'true'
# Only runs if all of the files exists
run: exit 1

- name: Get package.json package name and match with repository name
run: |
echo PACKAGE_NAME=$(cat package.json | jq .name | cut -f2 -d"\"" | cut -f2 -d"@") >> $GITHUB_OUTPUT
echo PACKAGE_VERSION="refs/tags/v"$(cat package.json | jq .version | cut -f2 -d"\"") >> $GITHUB_OUTPUT
echo PACKAGE_REPOSITORY=$(cat package.json | jq .repository | cut -f2 -d"\"" | sed 's/:/\//' | sed 's/@/:\/\//') >> $GITHUB_OUTPUT
id: get_package_info

- name: Check if package_name matches with repository name
if: github.repository != steps.get_package_info.outputs.PACKAGE_NAME
# Fail if package name not properly configured
run: exit 1

- name: Check if package version matches with tag
if: github.ref != steps.get_package_info.outputs.PACKAGE_VERSION
# Fail if package version not properly setted
run: exit 1

- name: Check if package repository matches with repository
if: github.repositoryUrl != steps.get_package_info.outputs.PACKAGE_REPOSITORY
# Fail if package repository doesn't match with repository
run: exit 1

- name: Push package to npmjs.com
uses: actions/setup-node@v1
with:
node-version: 20
registry-url: https://registry.npmjs.org/

- name: Install dependencies
run: npm install

- name: Pre upload validation
id: pack
run: |
npm pack --dry-run >> output 2>&1
echo PRE_UPLOAD_HASH=$(cat output| grep shasum | cut -f4 -d" ") >> $GITHUB_OUTPUT
- name: Upload package
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

- name: Post upload validation
id: unpack
run: |
PACKAGE_NAME=$(cat package.json | jq .name | cut -f2 -d"\"")@$(cat package.json | jq .version | cut -f2 -d"\"")
echo POST_UPLOAD_HASH=$(npm view $PACKAGE_NAME) >> $GITHUB_OUTPUT
- name: Pre and Post Upload validation
if: steps.pack.outputs.PRE_UPLOAD_HASH != steps.unpack.outputs.POST_UPLOAD_HASH
# Fail if package hashes doesn't match
run: exit 1
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "rsk-cli",
"name": "@rsksmart/rsk-cli",
"version": "1.0.0",
"description": "CLI tool for Rootstock blockchain using viem",
"description": "CLI tool for Rootstock network using Viem",
"repository": "git@github.com:rsksmart/rsk-cli.git",
"main": "dist/bin/index.js",
"bin": {
"rsk-cli": "./dist/bin/index.js"
Expand Down

0 comments on commit 1eec163

Please sign in to comment.