From 2bc143086bfaaaaa0ab8f135ca11f266a9903106 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Mon, 26 Sep 2022 12:53:19 +0530 Subject: [PATCH] ci: release postject to npm on ci Fixes: https://github.com/postmanlabs/postject/issues/14 Signed-off-by: Darshan Sen --- .circleci/config.yml | 49 ++++++++++++++++++++++++++++++++++++++++++++ .npmignore | 10 +++++++++ 2 files changed, 59 insertions(+) create mode 100644 .npmignore diff --git a/.circleci/config.yml b/.circleci/config.yml index 03fd51b..654f55c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -172,6 +172,42 @@ commands: - store_test_results: path: . + publish: + steps: + - attach_workspace: + at: . + + - run: + name: Remove unnecessary files + command: rm -rf emsdk + + - run: + name: Update version if not on git tag + command: | + if ! git describe --exact-match HEAD 1>/dev/null 2>/dev/null + then + git describe --exact-match HEAD 1>/dev/null 2>/dev/null && exit + CURRENT_VERSION="$(node -p "require('./package.json').version")" + GIT_COMMIT_SHA="$(git rev-parse --short HEAD)" + npm version "$CURRENT_VERSION-$GIT_COMMIT_SHA" + fi + + - run: + name: Login to npm + command: npm set //registry.npmjs.org/:_authToken=$NPM_TOKEN + + - run: + name: Publish to npm + command: | + if git describe --exact-match HEAD 1>/dev/null 2>/dev/null + then + # Publish to latest when a git tag is pushed. + npm publish --tag latest + else + # Publish to beta when not run on a git tag. + npm publish --tag beta + fi + ## JOBS ## jobs: @@ -210,6 +246,14 @@ jobs: os: << parameters.os >> - test + publish: + parameters: + <<: *common_parameters + executor: { name: linux } + steps: + - checkout + - publish + ## WORKFLOWS ## matrix: &matrix @@ -229,4 +273,9 @@ workflows: - test: <<: *matrix requires: [ build-<< matrix.os >> ] + - publish: + matrix: + parameters: + os: [ linux ] + requires: [ test-<< matrix.os >> ] diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..1033ca7 --- /dev/null +++ b/.npmignore @@ -0,0 +1,10 @@ +build/ +.circleci/ +CMakeLists.txt +CODEOWNERS +DEPENDENCIES +postject-api.h +scripts/ +src/ +test/ +vendor/