From 5977e675cfeb6d63ede883ae00321636ca0b5dd9 Mon Sep 17 00:00:00 2001 From: Maciej Lenartowicz Date: Mon, 7 Oct 2019 14:43:57 +0000 Subject: [PATCH] Resolve "Automatic NPM publish." --- .gitlab-ci.yml | 17 +++++++++++++++++ Makefile | 7 +------ README.md | 17 +++++++++++++++++ scripts/publish.sh | 22 ++++++++++++++++++++++ 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 README.md create mode 100755 scripts/publish.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 06fb09c..dac26a3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,6 +3,7 @@ image: node:8-alpine stages: - test - build + - publish before_script: - npm install @@ -24,3 +25,19 @@ build: artifacts: paths: - foris-*.tgz + +publish_beta: + stage: publish + only: + refs: + - dev + script: + - sh scripts/publish.sh beta + +publish_latest: + stage: publish + only: + refs: + - master + script: + - sh scripts/publish.sh latest diff --git a/Makefile b/Makefile index 08ed1ff..d44dba7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all install-js watch-js build-js publish-beta lint-js test-js create-messages update-messages docs clean +.PHONY: all install-js watch-js build-js lint-js test-js create-messages update-messages docs clean all: @echo "make install-js" @@ -7,8 +7,6 @@ all: @echo " Compile JS in watch mode." @echo "make build-js" @echo " Compile JS." - @echo "make publish-beta" - @echo " Publish package with 'beta' tag" @echo "make lint-js" @echo " Run linter" @echo "make test-js" @@ -32,9 +30,6 @@ watch-js: build-js: npm run build -publish-beta: - npm publish --tag beta - lint: npm run lint diff --git a/README.md b/README.md new file mode 100644 index 0000000..2e1611a --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# foris-js + +## Publishing package + +### Beta versions + +Each commit to `dev` branch will result in publishing a new version of library +tagged `beta`. Versions names are based on commit SHA, e.g. +`foris@0.1.0-d9073aa4.0`. + +### Preparing a release + +1. Crete a merge request to `dev` branch with version bumped +2. When merging add `[skip ci]` to commit message to prevent publishing +unnecessary version +3. Create a merge request from `dev` to `master` branch +4. New version should be published automatically diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 0000000..4ad76f2 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +if test -z "$NPM_TOKEN" +then + echo "\$NPM_TOKEN is not set" + exit 1 +else + # Need to replace "_" with "_" as GitLab CI won't accept secret vars with "-" + echo "//registry.npmjs.org/:_authToken=$(echo $NPM_TOKEN | tr _ -)" > .npmrc + echo "unsafe-perm = true" >> ~/.npmrc + if test "$1" = "beta" + then + npm version prerelease --preid=$CI_COMMIT_SHORT_SHA --git-tag-version false + npm publish --tag beta + elif test "$1" = "latest" + then + npm publish + else + echo "Usage: publish.sh [ beta | latest ]" + exit 1 + fi +fi