webstorage-decorators/.gitlab/.gitlab-ci.yml

106 lines
3.0 KiB
YAML
Raw Normal View History

2022-09-23 11:38:55 -04:00
image: node:16
npm:
stage: build
cache:
- key:
files:
2023-03-20 16:26:36 -04:00
- package-lock.json
2022-09-23 11:38:55 -04:00
paths:
- node_modules
policy: pull-push
- key: $CI_PIPELINE_ID
paths:
- dist
policy: push
script:
2023-03-20 16:26:36 -04:00
- npm install
2022-09-23 11:38:55 -04:00
- npm run build
2023-03-20 16:26:36 -04:00
artifacts:
paths:
- dist
expire_in: 1 week
2022-09-23 11:38:55 -04:00
rules:
- if: $CI_COMMIT_BRANCH
audit:
stage: test
cache:
- key:
files:
2023-03-20 16:26:36 -04:00
- package-lock.json
2022-09-23 11:38:55 -04:00
paths:
- node_modules
policy: pull
script:
2023-03-20 16:26:36 -04:00
- echo "vulnerabilities_high $(npm audit | grep -oE '[0-9]+ high' | grep -oE '[0-9]+' || echo 0)" > metrics.txt
- echo "vulnerabilities_medium $(npm audit | grep -oE '[0-9]+ moderate' | grep -oE '[0-9]+' || echo 0)" >> metrics.txt
- echo "vulnerabilities_low $(npm audit | grep -oE '[0-9]+ low' | grep -oE '[0-9]+' || echo 0)" >> metrics.txt
2022-09-23 11:38:55 -04:00
artifacts:
reports:
metrics: metrics.txt
rules:
- if: $CI_COMMIT_BRANCH
jest:
stage: test
cache:
- key:
files:
- package.json
paths:
- node_modules
policy: pull
script:
- npm run test:coverage
coverage: /All\sfiles.*?\s+(\d+.\d+)/
artifacts:
when: always
reports:
junit: junit.xml
rules:
- if: $CI_COMMIT_BRANCH
2023-03-20 16:26:36 -04:00
registry:
stage: publish
2022-09-23 11:38:55 -04:00
cache:
- key:
files:
- package.json
paths:
- node_modules
policy: pull
- key: $CI_PIPELINE_ID
paths:
- dist
policy: pull
before_script:
- VERSION=$(cat package.json | grep version | grep -Eo ':.+' | grep -Eo '[[:alnum:]\.\/\-]+')
- if [ "$CI_COMMIT_BRANCH" != "$CI_DEFAULT_BRANCH" ] && [ "$VERSION" != *"-$CI_COMMIT_BRANCH" ]; then VERSION="$VERSION-$(echo "$CI_COMMIT_BRANCH" | sed -E "s/[_/]/-/g")"; npm version --no-git-tag-version $VERSION; fi
script:
2023-03-20 16:26:36 -04:00
- PACKAGES=$(curl -s -H "PRIVATE-TOKEN:$DEPLOY_TOKEN" https://$CI_SERVER_HOST/api/v4/projects/$CI_PROJECT_ID/packages)
2022-09-23 11:38:55 -04:00
- ID=$(node -pe "JSON.parse(process.argv[1]).find(p => p['version'] == process.argv[2])?.id || ''" $PACKAGES $VERSION)
- if [ -n "$ID" ]; then curl -s -X DELETE -H "PRIVATE-TOKEN:$DEPLOY_TOKEN" https://$CI_SERVER_HOST/api/v4/projects/$CI_PROJECT_ID/packages/$ID; fi
2023-03-20 16:26:36 -04:00
- printf "@transmute:registry=https://$CI_SERVER_HOST/api/v4/projects/$CI_PROJECT_ID/packages/npm/\n//$CI_SERVER_HOST/api/v4/projects/$CI_PROJECT_ID/packages/npm/:_authToken=$DEPLOY_TOKEN" > .npmrc
2022-09-23 11:38:55 -04:00
- npm publish
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- if: $CI_COMMIT_BRANCH
when: manual
allow_failure: true
tag:
2023-03-20 16:26:36 -04:00
stage: publish
2022-09-23 11:38:55 -04:00
image:
name: alpine/git
2023-03-20 16:26:36 -04:00
entrypoint: [""]
cache: []
2022-09-23 11:38:55 -04:00
before_script:
2023-03-20 16:26:36 -04:00
- git remote set-url origin "https://ReleaseBot:$DEPLOY_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git"
2022-09-23 11:38:55 -04:00
script:
- VERSION=$(cat package.json | grep version | grep -Eo ':.+' | grep -Eo '[[:alnum:]\.\/\-]+')
- git tag -f $VERSION $CI_COMMIT_SHA
- git push -f origin $VERSION
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'