|
| 1 | +version: 2.1 |
| 2 | +orbs: |
| 3 | + node: circleci/node@5 |
| 4 | + |
| 5 | +aliases: |
| 6 | + - &release-branches |
| 7 | + - master |
| 8 | + - develop |
| 9 | + - /^hotfix\// |
| 10 | + |
| 11 | +executors: |
| 12 | + default-executor: |
| 13 | + docker: |
| 14 | + - image: cimg/node:16.18.1 # Consider switching to LTS when scratch-audio supports that version |
| 15 | + working_directory: ~/project |
| 16 | + resource_class: medium |
| 17 | + |
| 18 | +commands: |
| 19 | + test: |
| 20 | + steps: |
| 21 | + - run: |
| 22 | + name: Test |
| 23 | + command: npm run test |
| 24 | + setup_deploy: |
| 25 | + steps: |
| 26 | + - run: |
| 27 | + name: Setup Deploy |
| 28 | + command: | |
| 29 | + export NODE_ENV=production |
| 30 | + export RELEASE_TIMESTAMP=$(date +'%Y%m%d%H%M%S') |
| 31 | + echo "export NPM_TAG=latest" >> $BASH_ENV |
| 32 | + npm run build |
| 33 | + if [ -z "$BEFORE_DEPLOY_RAN" ]; then |
| 34 | + VPKG=$($(npm bin)/json -f package.json version) |
| 35 | + VERSION=${VPKG}-prerelease.${RELEASE_TIMESTAMP} |
| 36 | + echo "export RELEASE_VERSION=${VPKG}-prerelease.${RELEASE_TIMESTAMP}" >> $BASH_ENV |
| 37 | + npm --no-git-tag-version version $VERSION |
| 38 | + if [[ "$CIRCLE_BRANCH" == hotfix/* ]]; then # double brackets are important for matching the wildcard |
| 39 | + echo "export NPM_TAG=hotfix" >> $BASH_ENV |
| 40 | + fi |
| 41 | + git config --global user.email "$(git log --pretty=format:"%ae" -n1)" |
| 42 | + git config --global user.name "$(git log --pretty=format:"%an" -n1)" |
| 43 | + echo "export BEFORE_DEPLOY_RAN=true" >> $BASH_ENV |
| 44 | + fi |
| 45 | + deploy: |
| 46 | + steps: |
| 47 | + - run: |
| 48 | + name: Deploy |
| 49 | + command: | |
| 50 | + echo "Deploying version $RELEASE_VERSION to $NPM_TAG" |
| 51 | + npm set //registry.npmjs.org/:_authToken=$NPM_TOKEN |
| 52 | + npm publish --tag $NPM_TAG |
| 53 | + if npm info | grep -q $RELEASE_VERSION; then git tag $RELEASE_VERSION && git push https://${GH_TOKEN}@github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}.git $RELEASE_VERSION; fi |
| 54 | +
|
| 55 | +jobs: |
| 56 | + build-and-test: |
| 57 | + executor: default-executor |
| 58 | + steps: |
| 59 | + - checkout |
| 60 | + - node/install-packages |
| 61 | + - test |
| 62 | + - persist_to_workspace: |
| 63 | + root: ~/project |
| 64 | + paths: |
| 65 | + - . |
| 66 | + deploy: |
| 67 | + executor: default-executor |
| 68 | + steps: |
| 69 | + - attach_workspace: |
| 70 | + at: ~/project |
| 71 | + - setup_deploy |
| 72 | + - deploy |
| 73 | + |
| 74 | +workflows: |
| 75 | + build-and-test-workflow: |
| 76 | + jobs: |
| 77 | + - build-and-test: |
| 78 | + filters: |
| 79 | + branches: |
| 80 | + ignore: *release-branches |
| 81 | + deploy-workflow: |
| 82 | + jobs: |
| 83 | + - build-and-test: |
| 84 | + filters: |
| 85 | + branches: |
| 86 | + only: *release-branches |
| 87 | + - deploy: |
| 88 | + context: |
| 89 | + - scratch-npm-creds |
| 90 | + requires: |
| 91 | + - build-and-test |
0 commit comments