diff --git a/.circleci/conditional_upload.sh b/.circleci/conditional_upload.sh deleted file mode 100755 index 605ff0fd5d2..00000000000 --- a/.circleci/conditional_upload.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# The situation occasionally arises where our docs build successfully, -# but due to caching and other unopportune CI events the files aren't -# actually there. So make sure they're there before uploading. -if [ -z "$(ls -A .public/patternfly-3 2>/dev/null)" ] -then - echo "Missing PF3 docs, skipping upload" - exit 1 -fi -if [ -z "$(ls -A .public/patternfly-4 2>/dev/null)" ] -then - echo "Missing PF4 docs, skipping upload" - exit 1 -fi - -if yarn run surge --project .public --domain patternfly-react.surge.sh -then - # Sends a POST request to Travis that triggers browser tests from here: - # https://github.com/quarckster/widgetastic.patternfly4/tree/master/testing - curl -s -X POST \ - -H "Content-Type: application/json" \ - -H "Accept: application/json" \ - -H "Travis-API-Version: 3" \ - -H "Authorization: token $QUARCKSTER_TOKEN" \ - -d '{"request": {"branch": "master"}}' \ - https://api.travis-ci.org/repo/quarckster%2Fwidgetastic.patternfly4/requests -fi \ No newline at end of file diff --git a/.circleci/config.yml b/.circleci/config.yml index 9402853315c..b97cb9d4b80 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,47 +1,226 @@ version: 2 + +# Adapted from https://github.com/circleci/circleci-docs/blob/master/.circleci/config.yml +# I'd love to find docs on this syntax. +references: + js_deps_paths: &js_deps_paths + - node_modules/ + - packages/patternfly-3/patternfly-react-extensions/node_modules/ + - packages/patternfly-3/patternfly-react-wooden-tree/node_modules/ + - packages/patternfly-3/patternfly-react/node_modules/ + - packages/patternfly-3/react-console/node_modules/ + - packages/patternfly-4/react-charts/node_modules/ + - packages/patternfly-4/react-core/node_modules/ + - packages/patternfly-4/react-docs/node_modules/ + - packages/patternfly-4/react-docs/plugins/gatsby-transformer-react-docgen-typescript/node_modules/ + - packages/patternfly-4/react-inline-edit-extension/node_modules/ + - packages/patternfly-4/react-integration/demo-app-ts/node_modules/ + - packages/patternfly-4/react-integration/node_modules/ + - packages/patternfly-4/react-styled-system/node_modules/ + - packages/patternfly-4/react-styles/node_modules/ + - packages/patternfly-4/react-table/node_modules/ + - packages/patternfly-4/react-tokens/node_modules/ + - packages/patternfly-4/react-topology/node_modules/ + - packages/patternfly-4/react-virtualized-extension/node_modules/ + - packages/react-codemods/node_modules/ + - packages/react-icons/node_modules/ + build_cache_paths: &build_cache_paths + - .cache/ + - packages/patternfly-3/patternfly-react-extensions/dist/ + - packages/patternfly-3/patternfly-react-wooden-tree/dist/ + - packages/patternfly-3/patternfly-react/dist/ + - packages/patternfly-3/react-console/dist/ + - packages/patternfly-4/react-charts/dist/ + - packages/patternfly-4/react-core/dist/ + - packages/patternfly-4/react-inline-edit-extension/dist/ + - packages/patternfly-4/react-styled-system/dist/ + - packages/patternfly-4/react-styles/css/ + - packages/patternfly-4/react-styles/dist/ + - packages/patternfly-4/react-table/dist/ + - packages/patternfly-4/react-tokens/dist/ + - packages/patternfly-4/react-topology/dist/ + - packages/patternfly-4/react-virtualized-extension/dist/ + - packages/react-icons/dist/ + js_deps_cache_key: &js_deps_cache_key + js-deps-v{{.Environment.CACHE_VERSION}}-{{checksum "yarn.lock"}} + build_cache_key: &build_cache_key + build-cache-v{{.Environment.CACHE_VERSION}}-{{checksum "yarn.lock"}} + attach_workspace: &attach_workspace + attach_workspace: + at: ~/project + +workflows: + version: 2 + build_test_deploy: + jobs: + - build + - build_pf4_docs: + requires: + - build + - build_pf3_docs: + requires: + - build + - test_jest_pf4: + requires: + - build + - test_jest_other: + requires: + - build + - build_integration: + requires: + - build + - lint: + requires: + - build + - upload_docs: + requires: + - build_pf3_docs + - build_pf4_docs + - deploy_prerelease: + requires: + - test_jest_pf4 + - test_jest_other + - build_pf3_docs + - build_pf4_docs + filters: + branches: + only: master jobs: build: - branches: - ignore: - - master - docker: - - image: circleci/node:8.15 - working_directory: ~/repo - steps: - - checkout - # Download and cache dependencies - - restore_cache: - keys: - - v{{ .Environment.CACHE_VERSION }}-deps-{{ .Branch }}-{{ checksum "yarn.lock" }} - - run: - name: Conditional install - command: if [ ! -d node_modules ]; then yarn install --frozen-lockfile; fi - - save_cache: - paths: - - node_modules - - packages/react-icons/node_modules - - packages/patternfly-4/react-core/node_modules - - packages/patternfly-4/react-docs/node_modules - - packages/patternfly-4/react-charts/node_modules - - packages/patternfly-4/react-styles/node_modules - - packages/patternfly-3/patternfly-react/node_modules - - .cache # Incremental builds - key: v{{ .Environment.CACHE_VERSION }}-deps-{{ .Branch }}-{{ checksum "yarn.lock" }} - - run: - name: Build Dist - command: yarn build - - run: - name: (PF3) Build Storybook - command: | - yarn build:storybook && - cp -r .out .public/patternfly-3 - - run: - name: (PF4) Build Docs - command: | - yarn build:docs && - cp -r packages/patternfly-4/react-docs/public .public/patternfly-4 && - cp -r .public/patternfly-4/assets .public/assets && - cp .public/patternfly-4/favicon* .public - - run: - name: Deploy Docs - command: if [ -n "$CIRCLE_PULL_REQUEST" ]; then .circleci/upload_preview.sh; fi + docker: + - image: circleci/node:8.15 + steps: + - checkout + - persist_to_workspace: + root: ~/project + paths: + - "*" + - restore_cache: + keys: + - *js_deps_cache_key + - run: + name: Conditional install + command: if [ ! -d node_modules ]; then yarn install --frozen-lockfile; fi + - save_cache: + paths: *js_deps_paths + key: *js_deps_cache_key + - restore_cache: + keys: + - *build_cache_key + - run: + name: Build Dist + command: yarn build + - save_cache: + paths: *build_cache_paths + key: *build_cache_key + - persist_to_workspace: + root: ~/project + paths: *build_cache_paths + test_jest_pf4: + docker: + - image: circleci/node:8.15 + steps: + - *attach_workspace + - restore_cache: + keys: + - *js_deps_cache_key + - run: + name: PF4 Jest Tests + command: yarn test:pf4 --maxWorkers=2 + test_jest_other: + docker: + - image: circleci/node:8.15 + steps: + - *attach_workspace + - restore_cache: + keys: + - *js_deps_cache_key + - run: + name: PF3 Jest Tests + command: yarn test:pf3 --maxWorkers=2 + - run: + name: Other Tests + command: yarn test:misc --maxWorkers=2 + build_integration: + docker: + - image: circleci/node:8.15 + steps: + - *attach_workspace + - restore_cache: + keys: + - *js_deps_cache_key + - run: + name: Build Cypress Integration Tests + command: yarn build:integration + lint: + docker: + - image: circleci/node:8.15 + steps: + - *attach_workspace + - restore_cache: + keys: + - *js_deps_cache_key + - run: + name: TSLint + command: yarn lint:ts + - run: + name: ESLint + command: yarn lint:js + - run: + name: "@patternfly/patternfly Versions Match" + command: yarn lint:versions + - run: + name: StyleLint + command: yarn lint:style + build_pf3_docs: + docker: + - image: circleci/node:8.15 + steps: + - *attach_workspace + - restore_cache: + keys: + - *js_deps_cache_key + - run: + name: Build PF3 Storybook Static Site + command: yarn build:storybook + - persist_to_workspace: + root: ~/project + paths: + - .out/ + build_pf4_docs: + docker: + - image: circleci/node:8.15 + steps: + - *attach_workspace + - restore_cache: + keys: + - *js_deps_cache_key + - run: + name: Build PF4 Gatsby Static Site + command: yarn build:docs + - persist_to_workspace: + root: ~/project + paths: + - packages/patternfly-4/react-docs/public/ + upload_docs: + docker: + - image: circleci/node:8.15 + steps: + - *attach_workspace + - run: + name: Build docs Folder + command: .circleci/copy-docs.sh + - run: + name: Upload docs to surge.sh + command: .circleci/upload-docs.sh + deploy_prerelease: + docker: + - image: circleci/node:8.15 + steps: + - *attach_workspace + - run: + name: Avoid hosts unknown for github + command: mkdir ~/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config + - run: + name: Deploy to NPM and Github + command: .circleci/release.sh diff --git a/.circleci/copy-docs.sh b/.circleci/copy-docs.sh new file mode 100755 index 00000000000..c21adf585ee --- /dev/null +++ b/.circleci/copy-docs.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# Build the docs/ folder from pf3 and pf4 docs +mkdir -p docs +cp -r .out docs/patternfly-3 +cp -r packages/patternfly-4/react-docs/public docs/patternfly-4 +cp .circleci/index.html docs/index.html +# These need to be at the root for CSS variables +cp -r docs/patternfly-4/assets docs/assets +# Use newer favicon +cp docs/patternfly-4/favicon* docs diff --git a/.public/index.html b/.circleci/index.html similarity index 100% rename from .public/index.html rename to .circleci/index.html diff --git a/.circleci/release.sh b/.circleci/release.sh index 473a7ae4392..2842ac0b28a 100755 --- a/.circleci/release.sh +++ b/.circleci/release.sh @@ -1,39 +1,16 @@ #!/bin/bash -# Note: do not do set -x or the passwords will leak! -set -e +GIT_USERNAME="patternfly-build" +REPO="github.com:${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}.git" echo "Preparing release environment..." git config --global user.email "patternfly-build@redhat.com" -git config --global user.name "patternfly-build" +git config --global user.name ${GIT_USERNAME} git config credential.helper store - -echo "https://${GH_USERNAME}:${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git" > ~/.git-credentials +echo "https://${GIT_USERNAME}:${GH_TOKEN}@${REPO}" > ~/.git-credentials echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc echo "Doing a release..." # Lerna is complicated. Commands: https://github.com/lerna/lerna/tree/master/commands -git checkout $TRAVIS_BRANCH # Lerna can't have a detached HEAD -git rev-parse HEAD - # Identify packages that have been updated since the previous tagged release # Update their versions and changelogs -npx lerna version --conventional-commits --no-git-tag-version --no-commit-hooks --no-push --yes - -# Amend the commit to avoid lerna ERR! EUNCOMMIT -git add **/package.json **/CHANGELOG.md -git commit --amend --no-edit --no-verify - -# Check each package.json and determine if any package version is not present in the registry; -# any versions not present in the registry will be published -if npx lerna publish from-package --no-git-tag-version --no-push --yes ; then - # Undo that last amended commit locally, because we don't actually want to push it - git reset --hard $TRAVIS_COMMIT - # Now only if it publishes should we also push this commit to Github and do a Github release - if ! npx lerna version --conventional-commits --github-release --no-commit-hooks --yes ; then - echo "Something went wrong committing or making a Github release." - exit 0 # Publishing to the registry is what matters... - fi -else # Failed to publish to npm - echo "Failed to publish to npm :(" - exit 1 -fi \ No newline at end of file +npx lerna publish --conventional-commits --create-release=github --yes diff --git a/.circleci/upload-docs.sh b/.circleci/upload-docs.sh new file mode 100755 index 00000000000..939d2684c64 --- /dev/null +++ b/.circleci/upload-docs.sh @@ -0,0 +1,31 @@ +#!/bin/bash +USERNAME=${CIRCLE_PROJECT_USERNAME} +REPONAME=${CIRCLE_PROJECT_REPONAME} + +if [ -n "${CIRCLE_PULL_REQUEST}" ] # If build is a PR +then + # Split on "/" to get last part of URL, ref: http://stackoverflow.com/a/5257398/689223 + URL_SPLIT=(${CIRCLE_PULL_REQUEST//\// }) + PR_NUM=$(printf %s\\n "${URL_SPLIT[@]:(-1)}") + # Domain names follow the RFC1123 spec [a-Z] [0-9] [-] limited to 253 characters + # https://en.wikipedia.org/wiki/Domain_Name_System#Domain_name_syntax + # So, just replace "/" or "." with "-" + DEPLOY_SUBDOMAIN=`echo "${REPONAME}-pr-$PR_NUM" | tr '[\/|\.]' '-' | cut -c1-253` + ALREADY_DEPLOYED=`npx surge list | grep ${DEPLOY_SUBDOMAIN}` +else + DEPLOY_SUBDOMAIN=${REPONAME} +fi + +DEPLOY_DOMAIN="https://${DEPLOY_SUBDOMAIN}.surge.sh" +npx surge --project docs --domain $DEPLOY_DOMAIN; + +if [ -n "${CIRCLE_PULL_REQUEST}" ] && [ -z "${ALREADY_DEPLOYED}" ] # Leave a Github comment +then + # Use Issues api instead of PR api because + # PR api requires comments be made on specific files of specific commits + GITHUB_PR_COMMENTS="https://api.github.com/repos/${USERNAME}/${REPONAME}/issues/${PR_NUM}/comments" + echo "Adding github PR comment ${GITHUB_PR_COMMENTS}" + curl -H "Authorization: token ${GH_PR_TOKEN}" --request POST ${GITHUB_PR_COMMENTS} --data '{"body":"PatternFly-React preview: '${DEPLOY_DOMAIN}'"}' +else + echo "Already deployed ${DEPLOY_DOMAIN}" +fi \ No newline at end of file diff --git a/.circleci/upload_preview.sh b/.circleci/upload_preview.sh deleted file mode 100755 index 005cb6e9d20..00000000000 --- a/.circleci/upload_preview.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -# Split on "/" to get last part of URL, ref: http://stackoverflow.com/a/5257398/689223 -URL_SPLIT=(${CIRCLE_PULL_REQUEST//\// }) -PR_NUM=$(printf %s\\n "${URL_SPLIT[@]:(-1)}") -# Domain names follow the RFC1123 spec [a-Z] [0-9] [-] limited to 253 characters -# https://en.wikipedia.org/wiki/Domain_Name_System#Domain_name_syntax -# So, just replace "/" or "." with "-" -DEPLOY_SUBDOMAIN=`echo "$PR_NUM-pr-${CIRCLE_PROJECT_REPONAME}-${CIRCLE_PROJECT_USERNAME}" | tr '[\/|\.]' '-' | cut -c1-253` -DEPLOY_DOMAIN="https://${DEPLOY_SUBDOMAIN}.surge.sh" -ALREADY_DEPLOYED=`yarn run surge list | grep ${DEPLOY_SUBDOMAIN}` - -yarn run surge --project .public --domain $DEPLOY_DOMAIN; - -if [ -z "$ALREADY_DEPLOYED" ] -then - # Using the Issues api instead of the PR api - # Done so because every PR is an issue, and the issues api allows to post general comments, - # while the PR api requires that comments are made to specific files and specific commits - GITHUB_PR_COMMENTS="https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/issues/${PR_NUM}/comments" - echo "Adding github PR comment ${GITHUB_PR_COMMENTS}" - curl -H "Authorization: token ${GH_PR_TOKEN}" --request POST ${GITHUB_PR_COMMENTS} --data '{"body":"PatternFly-React preview: '${DEPLOY_DOMAIN}'"}' -else - echo "Already deployed ${DEPLOY_DOMAIN}" -fi \ No newline at end of file diff --git a/.gitignore b/.gitignore index 341b8e6976b..2d7b16dfe96 100644 --- a/.gitignore +++ b/.gitignore @@ -32,5 +32,4 @@ lerna-debug.log *.swp # Deploy directory -.public -!.public/index.html +docs diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b8a1b836cde..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,106 +0,0 @@ -dist: xenial -language: node_js -node_js: - - "8" # Also included in .nvmrc, but this saves a few seconds -cache: - yarn: false - directories: - - node_modules # God help us... - - packages/react-icons/node_modules/ - - packages/patternfly-4/react-core/node_modules - - packages/patternfly-4/react-docs/node_modules - - packages/patternfly-4/react-docs/plugins/gatsby-transformer-react-docgen-typescript/node_modules - - packages/patternfly-4/react-docs/plugins/gatsby-transformer-react-examples/node_modules - - packages/patternfly-4/react-charts/node_modules - - packages/patternfly-4/react-styles/node_modules - - packages/patternfly-3/patternfly-react/node_modules - - packages/patternfly-4/react-integration/node_modules - - packages/patternfly-4/react-integration/demo-app-ts/node_modules - - packages/react-icons/dist - - packages/react-icons/src/icons - - packages/react-icons/src/index.d.ts - - packages/react-icons/src/index.js - - packages/patternfly-3/patternfly-react-extensions/dist - - packages/patternfly-3/patternfly-react/dist - - packages/patternfly-3/react-console/dist - - packages/patternfly-4/react-charts/dist - - packages/patternfly-4/react-core/dist - - packages/patternfly-4/react-styled-system/dist - - packages/patternfly-4/react-styles/dist - - packages/patternfly-4/react-styles/css - - packages/patternfly-4/react-table/dist - - packages/patternfly-4/react-tokens/dist - - packages/patternfly-4/react-inline-edit-extension/dist - - packages/patternfly-4/react-integration/demo-app-ts/build - - packages/patternfly-4/react-virtualized-extension/dist - - packages/patternfly-4/react-topology/dist - - packages/patternfly-4/react-docs/public # To cache PF4 docs - - .cache # For incremental builds -git: - depth: 10 -branches: - except: - - "/^chore/bump-.*$/" # Avoid hookbot double-builds -notifications: - email: false - -stages: - - Build - - Test - - name: Deploy - if: branch = master && type != pull_request && fork = false - -install: - - yarn install --frozen-lockfile -jobs: - include: - - stage: Build - name: Build Dist - script: - - yarn build - - - stage: Test # Nothing can be cached in this stage since steps run in parallel. - name: (PF4) Jest Tests - install: skip - script: - - ls packages/patternfly-4/react-styles - - yarn test:pf4 - - npx codecov -F patternfly4 - - name: (PF3 and Misc) Jest Tests - install: skip - script: - - yarn test:pf3 - - npx codecov -F patternfly3 - - rm -rf coverage - - yarn test:misc - - npx codecov -F patternflymisc - - name: Integration test - install: skip - script: - - yarn build:integration - - name: (PF4) Build Docs - if: branch = master && type != pull_request && fork = false - install: skip - script: - - yarn build:docs - - name: TSLint, ESLint, and Stylelint - install: skip - script: - - yarn lint:ts - - yarn lint:js - - yarn lint:versions - - yarn lint:style - - - stage: Deploy - name: NPM and Github Release - install: skip - script: .circleci/release.sh - - name: (PF3) Build Storybook and Deploy Docs - install: skip - script: - - yarn build:storybook - - mv .out .public/patternfly-3 - - mv packages/patternfly-4/react-docs/public .public/patternfly-4 - - cp .public/patternfly-4/favicon* .public - - cp -r .public/patternfly-4/assets .public/assets - - .circleci/conditional_upload.sh