Skip to content

Commit

Permalink
adding cicd workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
bearcubsvet committed Oct 14, 2024
1 parent f770a98 commit d02aff8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
53 changes: 53 additions & 0 deletions .github/workflows/publish-npm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Deploy to npm

on:
push:
tags:
- 'v*' # Only trigger when a version tag (e.g., v1.0.0) is pushed

jobs:
publish:
runs-on: ubuntu-latest

env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Display Git Information
run: |
echo "GITHUB_REF: $GITHUB_REF"
echo "GITHUB_SHA: $GITHUB_SHA"
git log -1
- name: Get the tag name
id: get_tag
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Use the tag name
run: echo "The tag name is $TAG_NAME"
env:
TAG_NAME: ${{ env.TAG_NAME }}

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18.18.0
registry-url: 'https://registry.npmjs.org'
scope: '@wireio'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build
run: make lib

- name: Run make publish
run: make ci-publish
env:
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ publish: | distclean node_modules
@git push && git push --tags
@curl -X POST -H 'Content-type: application/json' --data '{ "channel": "#npm-notifications","username": "npm bot", "icon_url": "https://static-00.iconduck.com/assets.00/megaphone-emoji-512x390-7a60feky.png","text": "#### New Deployment!\n\n**Package Name:** $(PACKAGE_NAME) \n**Version:** $(PACKAGE_VERSION) **Published on**: $(PUBLISH_DATE)" }' $(WEBHOOK_URL)

# used for GitHub Deploy Action
.PHONY: ci-publish
ci-publish: | distclean node_modules
@echo "Publishing package..."
@if [ -z "$${NODE_AUTH_TOKEN}" ]; then echo "NPM token is not set."; exit 1; fi
@if [ -z "$${WEBHOOK_URL}" ]; then echo "WEBHOOK_URL is not set."; exit 1; fi
@npm publish --access restricted --non-interactive
@curl -X POST -H 'Content-type: application/json' --data '{ "channel": "#npm-notifications","username": "npm bot", "icon_url": "https://static-00.iconduck.com/assets.00/megaphone-emoji-512x390-7a60feky.png","text": "#### New Deployment!\n\n**Package Name:** $(PACKAGE_NAME) \n**Version:** $(PACKAGE_VERSION) **Published on**: $(PUBLISH_DATE)" }' $(WEBHOOK_URL)



.PHONY: docs
docs: build/docs
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"publish-package": "make publish",
"deploy-site": "make deploy-site",
"clean": "make clean",
"distclean": "make distclean"
"distclean": "make distclean",
"lint": "eslint 'src/**/*.{js,ts}'",
"lint:fix": "eslint 'src/**/*.{js,ts}' --fix"
},
"dependencies": {
"bn.js": "^4.11.9",
Expand Down

0 comments on commit d02aff8

Please sign in to comment.