Skip to content

Instantly share code, notes, and snippets.

@chrisryana
Last active August 20, 2021 08:05
Show Gist options
  • Save chrisryana/7abd68710c264074930f3f286270f0a2 to your computer and use it in GitHub Desktop.
Save chrisryana/7abd68710c264074930f3f286270f0a2 to your computer and use it in GitHub Desktop.
Автоматический релиз в npm после создания тэга вместе с release-it. Автоматическое распознавание npm tag из тэга git
stages:
- lint
- build
- release
.node_cache:
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
lint:
image: node:$GLOBAL_NODE_VERSION
stage: lint
extends:
- .node_cache
script:
- yarn
- yarn lint
build:
image: node:$GLOBAL_NODE_VERSION
stage: build
extends:
- .node_cache
script:
- yarn
- yarn build
artifacts:
paths:
- storybook-static/
expire_in: 1 day
release:
image: node:$GLOBAL_NODE_VERSION
stage: release
when: manual
extends:
- .node_cache
script:
- yarn
- NPM_PRERELEASE=`echo ${CI_BUILD_REF_NAME} | grep -oh "\w*[a-z]\w*" `
- export $NPM_PRERELEASE
- echo $NPM_PRERELEASE
- git clone --branch master https://gitlab-ci-token:${CI_JOB_TOKEN}@pornhub.com/$CI_PROJECT_PATH.git
- git config user.email ${GITLAB_USER_EMAIL}
- git config user.name ${GITLAB_USER_NAME}
- >
if [ "$NPM_PRERELEASE" ]; then
npx release-it $CI_BUILD_REF_NAME --verbose --ci --preRelease=$NPM_PRERELEASE
else
npx release-it $CI_BUILD_REF_NAME --verbose --ci
fi
only:
- /^v?\d+\.\d+\.\d+(-(beta|alpha|rc|canary)\.\d+)?$/
{
"hooks": {
"after:bump": [
"yarn build",
"git add .",
"git commit -m 'Version up: ${version}'",
"git push https://root:${process.env.GITLAB_TOKEN}@pornhub.com/${process.env.CI_PROJECT_PATH}.git HEAD:master"
],
"after:release": [
"echo Successfully released ${name} v${version} to npm"
]
},
"git": {
"commitMessage": "Version up: ${version}",
"requireCleanWorkingDir": false,
"requireUpstream": false,
"push": false,
"pushRepo": "https://root:${process.env.GITLAB_TOKEN}@pornhub.com/${process.env.CI_PROJECT_PATH}.git",
"tag": false
},
"github": {
"release": false
},
"gitlab": {
"release": false,
"tokenRef": "CI_JOB_TOKEN",
"skipChecks": true
},
"npm": {
"publish": true,
"skipChecks": true
}
}
    - NPM_PRERELEASE=`echo ${CI_BUILD_REF_NAME} | grep -oh "\w*[a-z]\w*" `
    - export $NPM_PRERELEASE

– автоматически распознает тэг npm, например тэг 3.0.0-beta.1 –> npm.tag=beta, 3.6.2-rc.34 -> npm.tag=rc, 3.0.0 -> npm.tag=next.

После создания тэга подходящего под регулярку /^v?\d+\.\d+\.\d+(-(beta|alpha|rc|canary)\.\d+)?$/ в pipeline появится 3-ья стадия release. При ее запуске release-it автоматически поднимет версию в package.json до указанной в тэге, сбилдит, создаст коммит, запушит его и отправит пакет в npm. Токен npm при этом должен лежать в .npmrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment