diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..4fc3c2e7 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,68 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/node:10.15.1 + steps: + - checkout + - run: + command: npm ci + - run: + command: make build + - persist_to_workspace: + root: . + paths: + - public + + deploy: + docker: + - image: olizilla/ipfs-dns-deploy + environment: + DOMAIN: docs.libp2p.io + BUILD_DIR: build + steps: + - attach_workspace: + at: /tmp/workspace + - run: + name: Pin website, post notification for PRs or update DNS on master + command: | + # Upload build dir to cluster.ipfs.io + hash=$(ipfs-cluster-ctl \ + --host /dnsaddr/cluster.ipfs.io \ + --basic-auth $CLUSTER_USER:$CLUSTER_PASSWORD \ + add --rmin 3 --rmax 3 --name "$DOMAIN" \ + --recursive /tmp/workspace/$BUILD_DIR | tail -n1 | cut -d " " -f 2 ) + + preview_url=https://ipfs.io/ipfs/$hash + + echo "Website added to IPFS: $preview_url" + + if [ ! -z "$CIRCLE_PULL_REQUEST" ] ; then + # Add website preview as PR Status - https://developer.github.com/v3/repos/statuses/#create-a-status + + status_url="https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/statuses/$CIRCLE_SHA1" + params=$(jq --monochrome-output --null-input \ + --arg target_url $preview_url \ + '{ "state": "success", "target_url": $target_url, description: "Website added to IPFS", "context": "IPFS" }' ) + + echo "Github status update: $params" + curl --silent -X POST -H "Authorization: token $GITHUB_TOKEN" -H 'Content-Type: application/json' --data "$params" $status_url + + elif [ "$CIRCLE_BRANCH" == "master" ] ; then + # Update DNSLink for domain + + dnslink-dnsimple -d $DOMAIN -r _dnslink -l /ipfs/$hash + + else + echo "Not a Pull Request or Master branch. Skipping." + fi + +workflows: + version: 2 + build-deploy: + jobs: + - build + - deploy: + context: ipfs-dns-deploy + requires: + - build