From d02aff8fd4a4d6e74fe1dd0730dfc367a30748f1 Mon Sep 17 00:00:00 2001 From: Svetla Syrimis Date: Mon, 14 Oct 2024 14:11:18 -0400 Subject: [PATCH] adding cicd workflow --- .github/workflows/publish-npm.yaml | 53 ++++++++++++++++++++++++++++++ Makefile | 10 ++++++ package.json | 4 ++- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish-npm.yaml diff --git a/.github/workflows/publish-npm.yaml b/.github/workflows/publish-npm.yaml new file mode 100644 index 00000000..d62cdbf0 --- /dev/null +++ b/.github/workflows/publish-npm.yaml @@ -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 }} \ No newline at end of file diff --git a/Makefile b/Makefile index 6fab9419..b7a9e7ee 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/package.json b/package.json index aa0dc7f1..73a67cdb 100644 --- a/package.json +++ b/package.json @@ -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",