version: 2.1 jobs: checkout-and-version: docker: - image: codacy/git-version working_directory: ~/workdir steps: - checkout - run: name: Get next version command: | export NEXT_VERSION="$(/bin/git-version --folder=$PWD --release-branch=master)" echo "Next version is ${NEXT_VERSION}" echo "${NEXT_VERSION}" > .version - run: name: Get next npm tag name command: | if [ "${CIRCLE_BRANCH}" = "master" ]; then export PUBLISH_TAG="latest" elif [ "${CIRCLE_BRANCH}" = "next" ]; then export PUBLISH_TAG="next" else export PUBLISH_TAG="pr" fi echo "Next tag is ${PUBLISH_TAG}" echo "${PUBLISH_TAG}" > .tag - persist_to_workspace: root: ~/workdir paths: - '*' build-common: &build-common docker: - image: node working_directory: ~/workdir steps: - attach_workspace: at: ~/workdir - restore_cache: key: yarn-cache-{{ checksum "yarn.lock" }} - run: name: Log environment setup command: | node -v yarn -v - run: name: Install dependencies command: yarn install --ignore-engines - save_cache: key: yarn-cache-{{ checksum "yarn.lock" }} paths: - /usr/local/share/.cache/yarn - run: name: Build templates command: yarn run build:templates - run: name: Build library command: yarn run build build-stable: &build-stable docker: - image: node working_directory: ~/workdir steps: - attach_workspace: at: ~/workdir - restore_cache: key: yarn-cache-{{ checksum "yarn.lock" }} - run: name: Log environment setup command: | node -v yarn -v - run: name: Install dependencies command: yarn - save_cache: key: yarn-cache-{{ checksum "yarn.lock" }} paths: - /usr/local/share/.cache/yarn - run: name: Validate & Build command: yarn run validate - store_artifacts: path: coverage - store_test_results: path: coverage - run: yarn run coverage:push - persist_to_workspace: root: ~/workdir paths: - '*' build-node-12: <<: *build-common docker: - image: node:12 build-node-15: <<: *build-common docker: - image: node:15 build-node-14: <<: *build-stable docker: - image: node:14 tag_version: docker: - image: node:14 working_directory: ~/workdir steps: - attach_workspace: at: ~/workdir - run: name: Configure Git command: | git config user.email "circleci@users.noreply.github.com" git config user.name "CircleCI" - run: name: Tag version command: | git tag "$(cat .version)" git push --tags "https://rtfpessoa:$GPR_AUTH_TOKEN@github.com/rtfpessoa/diff2html" publish_library: docker: - image: node:14 working_directory: ~/workdir steps: - attach_workspace: at: ~/workdir - run: name: Configure Yarn version command: | yarn config set version-tag-prefix "" yarn config set version-git-message "Release version %s" - run: name: Configure Git command: | git config user.email "circleci@users.noreply.github.com" git config user.name "CircleCI" - run: name: Version package command: | # Update version in packages to publish yarn version --non-interactive --new-version $(cat .version) - run: name: Setup npm credentials command: | rm -f .npmrc touch .npmrc echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> .npmrc echo "registry=https://registry.npmjs.org/" >> .npmrc echo "access=public" >> .npmrc echo "save-exact=true" >> .npmrc - run: name: Publish npm package command: | # Publish package versions to npmjs.org yarn publish --tag $(cat .tag) --non-interactive --new-version $(cat .version) - run: name: Setup gpr credentials command: | rm -f .npmrc touch .npmrc echo "//npm.pkg.github.com/:_authToken=${GPR_AUTH_TOKEN}" >> .npmrc echo "@rtfpessoa:registry=https://npm.pkg.github.com/" >> .npmrc echo "access=public" >> .npmrc echo "save-exact=true" >> .npmrc - run: name: Publish gpr package command: | # HACK: Override npm package name to be able to publish in GitHub sed -i 's/^ "name":.*/ "name": "@rtfpessoa\/diff2html",/g' package.json echo "Going to publish version $(cat .version) to GitHub" yarn publish --tag $(cat .tag) --non-interactive --new-version $(cat .version) # HACK: Restore npm package name sed -i 's/^ "name":.*/ "name": "diff2html",/g' package.json publish_website: machine: image: ubuntu-1604:202004-01 working_directory: ~/workdir steps: - attach_workspace: at: ~/workdir - run: name: Deploy working_directory: ~/workdir/docs command: | aws s3 sync --region eu-west-1 --delete . s3://diff2html.xyz --metadata-directive REPLACE --cache-control max-age=31557600 aws cloudfront create-invalidation --region eu-west-1 --distribution-id $AWS_CF_DISTRIBUTION_ID --paths /index.html /demo.html /sitemap.xml /robots.txt workflows: validate-and-publish: jobs: - checkout-and-version - build-node-12: requires: - checkout-and-version - build-node-14: requires: - checkout-and-version - build-node-15: requires: - checkout-and-version - publish_approval: type: approval requires: - build-node-12 - build-node-14 - build-node-15 - tag_version: requires: - publish_approval - publish_library: requires: - tag_version - publish_website: requires: - tag_version filters: branches: only: - master