|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Script to be used when deploying |
| 4 | +# Please do not use |
| 5 | + |
| 6 | +echo "1. setup .npmrc" |
| 7 | +echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc |
| 8 | + |
| 9 | +# 1. Version |
| 10 | +if [ -z "${VERSION}" ]; then |
| 11 | + echo "Must provide a VERSION; it can be either patch, minor, major, or specific version. Exiting...." |
| 12 | + echo "Find more information about it here: https://webpro.github.io/release-it/#%EF%B8%8F-usage for an instruction" |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +# 2. NPM TOKEN |
| 17 | +if [ -z "${NPM_TOKEN}" ]; then |
| 18 | + echo "Must provide an NPM TOKEN. Exiting...." |
| 19 | + echo "Find more information about it here: https://docs.npmjs.com/getting-started/working_with_tokens for an instruction" |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +# 3. Github Token |
| 24 | +if [ -z "${GITHUB_TOKEN}" ]; then |
| 25 | + echo "Must provide a GITHUB_TOKEN. Exiting...." |
| 26 | + echo "Find more information about it here: https://github.com/settings/tokens for an instruction" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +# 4. SSH_PUB |
| 31 | +if [ -z "${SSH_PUB}" ]; then |
| 32 | + echo "Must provide a SSH_PUB in base64 format. Exiting...." |
| 33 | + echo "Find more information about it here: https://help.github.com/articles/connecting-to-github-with-ssh/ for an instruction" |
| 34 | + exit 1 |
| 35 | +fi |
| 36 | + |
| 37 | +# 5. SSH_PRIV |
| 38 | +if [ -z "${SSH_PRIV}" ]; then |
| 39 | + echo "Must provide a SSH_PRIV in base64 format. Exiting...." |
| 40 | + echo "Find more information about it here: https://help.github.com/articles/connecting-to-github-with-ssh/ for an instruction" |
| 41 | + exit 1 |
| 42 | +fi |
| 43 | + |
| 44 | +echo "2. Setting up git" |
| 45 | +# Some reference: https://stackoverflow.com/questions/23391839/clone-private-git-repo-with-dockerfile |
| 46 | +mkdir /root/.ssh |
| 47 | + |
| 48 | +# Old approach: |
| 49 | +# cp .ssh/id_rsa /root/.ssh |
| 50 | +# cp .ssh/id_rsa.pub /root/.ssh |
| 51 | + |
| 52 | +# New approach, which uses environment variables: |
| 53 | +echo $SSH_PUB | base64 --decode > /root/.ssh/id_rsa.pub |
| 54 | +echo $SSH_PRIV | base64 --decode > /root/.ssh/id_rsa |
| 55 | +# This is to avoid ssh "permissions are too open" error: reference=https://stackoverflow.com/questions/9270734/ssh-permissions-are-too-open-error |
| 56 | +chmod 400 /root/.ssh/id_rsa |
| 57 | + |
| 58 | +# Creating an empty known_hosts |
| 59 | +touch /root/.ssh/known_hosts |
| 60 | +# Add github key to avoid fingerprint promt |
| 61 | +ssh-keyscan github.com >> /root/.ssh/known_hosts |
| 62 | + |
| 63 | +echo "3. Using /tmp/release as the working directory" |
| 64 | +mkdir /tmp/release |
| 65 | +cd /tmp/release |
| 66 | + |
| 67 | +echo "4. Cloning the machinelearn-node master branch." |
| 68 | +echo "You must have everything up-to-date on the master branch" |
| 69 | +git clone [email protected]:kalimdorjs/machinelearn-node.git . |
| 70 | + |
| 71 | +echo "5. Setting git meta data" |
| 72 | +git config --global user.email "[email protected]" |
| 73 | +git config --global user.name "Jason Shin" |
| 74 | +git config --global push.default matching |
| 75 | + |
| 76 | +echo "6. install packages" |
| 77 | +yarn |
| 78 | + |
| 79 | +echo "7. Run release-it patch with the given config" |
| 80 | + |
| 81 | +npx release-it ${VERSION} -n -c ./scripts/releases/configs/.release-it.json |
0 commit comments