Skip to content

Commit b466948

Browse files
committed
chore: adding release scripts
1 parent 4944a7e commit b466948

File tree

5 files changed

+234
-1
lines changed

5 files changed

+234
-1
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"main": "index.js",
66
"scripts": {
77
"build": "npx tsc index.ts",
8-
"test": "node ./scripts/test-integration.js"
8+
"test": "node ./scripts/test-integration.js",
9+
"release:major": "./scripts/releases/release-it.sh -v major",
10+
"release:minor": "./scripts/releases/release-it.sh -v minor",
11+
"release:patch": "./scripts/releases/release-it.sh -v patch"
912
},
1013
"author": "Jason Shin",
1114
"license": "MIT",

scripts/releases/configs/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"non-interactive": true,
3+
"dry-run": false,
4+
"verbose": true,
5+
"force": false,
6+
"pkgFiles": ["package.json"],
7+
"preReleaseId": null,
8+
"buildCommand": "yarn build",
9+
"safeBump": true,
10+
"beforeChangelogCommand": false,
11+
"changelogCommand": false,
12+
"requireCleanWorkingDir": true,
13+
"requireUpstream": true,
14+
"src": {
15+
"commit": true,
16+
"commitMessage": "Release %s",
17+
"commitArgs": "",
18+
"tag": true,
19+
"tagName": "%s",
20+
"tagAnnotation": "Release %s",
21+
"push": true,
22+
"pushArgs": "",
23+
"pushRepo": null,
24+
"beforeStartCommand": false,
25+
"afterReleaseCommand": false,
26+
"addUntrackedFiles": false
27+
},
28+
"npm": {
29+
"publish": true,
30+
"publishPath": "./build/lib",
31+
"tag": "latest",
32+
"private": false,
33+
"access": null
34+
},
35+
"github": {
36+
"release": true,
37+
"releaseName": "Release %s",
38+
"preRelease": false,
39+
"draft": false,
40+
"tokenRef": "GITHUB_TOKEN",
41+
"assets": null,
42+
"host": null,
43+
"timeout": 0
44+
},
45+
"dist": {
46+
"repo": false,
47+
"stageDir": ".stage",
48+
"baseDir": "dist",
49+
"files": ["**/*"],
50+
"pkgFiles": null,
51+
"commit": false,
52+
"commitMessage": "Release %s",
53+
"commitArgs": "",
54+
"tag": false,
55+
"tagName": "%s",
56+
"tagAnnotation": "Release %s",
57+
"push": false,
58+
"pushArgs": "",
59+
"beforeStageCommand": false,
60+
"afterReleaseCommand": false,
61+
"addUntrackedFiles": false,
62+
"github": {
63+
"release": false
64+
},
65+
"npm": {
66+
"publish": false
67+
}
68+
},
69+
"prompt": {
70+
"src": {
71+
"status": false,
72+
"commit": true,
73+
"tag": true,
74+
"push": true,
75+
"release": true,
76+
"publish": true
77+
},
78+
"dist": {
79+
"status": false,
80+
"commit": true,
81+
"tag": false,
82+
"push": true,
83+
"release": false,
84+
"publish": false
85+
}
86+
}
87+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
npm install -g [email protected]
81+
npx release-it ${VERSION} -n -c ./scripts/releases/configs/.release-it.json

scripts/releases/release-it.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
# Starts a container that runs an internal script that runs release-it
4+
# binds any required environment variables
5+
6+
# Handling arg params
7+
while getopts v: option
8+
do
9+
case "${option}"
10+
in
11+
v) VERSION=$OPTARG;;
12+
esac
13+
done
14+
15+
# 1. Version
16+
if [ -z "${VERSION}" ]; then
17+
echo "Must provide a VERSION; it can be either patch, minor, major, or specific version. Exiting...."
18+
echo "Find more information about it here: https://webpro.github.io/release-it/#%EF%B8%8F-usage for an instruction"
19+
exit 1
20+
fi
21+
22+
# 2. NPM TOKEN
23+
if [ -z "${NPM_TOKEN}" ]; then
24+
echo "Must provide an NPM TOKEN. Exiting...."
25+
echo "Find more information about it here: https://docs.npmjs.com/getting-started/working_with_tokens for an instruction"
26+
exit 1
27+
fi
28+
29+
# 3. Github Token
30+
if [ -z "${GITHUB_TOKEN}" ]; then
31+
echo "Must provide a GITHUB_TOKEN. Exiting...."
32+
echo "Find more information about it here: https://github.com/settings/tokens for an instruction"
33+
exit 1
34+
fi
35+
36+
# 4. SSH_PUB
37+
if [ -z "${SSH_PUB}" ]; then
38+
echo "Must provide a SSH_PUB in base64 format. Exiting...."
39+
echo "Find more information about it here: https://help.github.com/articles/connecting-to-github-with-ssh/ for an instruction"
40+
exit 1
41+
fi
42+
43+
# 5. SSH_PRIV
44+
if [ -z "${SSH_PRIV}" ]; then
45+
echo "Must provide a SSH_PRIV in base64 format. Exiting...."
46+
echo "Find more information about it here: https://help.github.com/articles/connecting-to-github-with-ssh/ for an instruction"
47+
exit 1
48+
fi
49+
50+
echo '1. building a kalimdor docker image'
51+
docker build -t kalimdor:latest .
52+
53+
echo '2. Running build-prod.sh in a temporary container'
54+
docker run --rm -it \
55+
-e NPM_TOKEN=${NPM_TOKEN} \
56+
-e GITHUB_TOKEN=${GITHUB_TOKEN} \
57+
-e VERSION=${VERSION} \
58+
-e SSH_PUB=${SSH_PUB} \
59+
-e SSH_PRIV=${SSH_PRIV} \
60+
kalimdor:latest \
61+
'./scripts/releases/docker_internal/release-in-docker.sh'

0 commit comments

Comments
 (0)