Skip to content

Commit ace4f63

Browse files
authored
New Publish Path (#12)
* first pass at new scripts * drop support for node 6 * remove whitespace * changelog was empty - keep it that way * move publish files to the correct directory * add deploy resources * specify a specific package builder image
1 parent d26d559 commit ace4f63

File tree

12 files changed

+329
-7
lines changed

12 files changed

+329
-7
lines changed

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: node_js
22
node_js:
3-
- '8'
4-
- '10'
5-
- stable
6-
sudo: false
3+
- '8'
4+
- '10'
5+
- '12'
File renamed without changes.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"build": "npm i && node_modules/.bin/tsc -p tsconfig.release.json",
88
"build:pack": "npm prune --production && rm -rf lib && npm install && node_modules/.bin/tsc -p tsconfig.release.json && npm pack && npm install",
9-
"build:release": "npm install --production && npm install typescript firebase-functions firebase-admin && node_modules/.bin/tsc -p tsconfig.release.json",
9+
"build:release": "npm install --production && npm install --no-save typescript firebase-functions firebase-admin && node_modules/.bin/tsc -p tsconfig.release.json",
1010
"lint": "node_modules/.bin/tslint src/{**/*,*}.ts spec/{**/*,*}.ts",
1111
"pretest": "node_modules/.bin/tsc",
1212
"test": "mocha .tmp/spec/index.spec.js",
@@ -16,7 +16,7 @@
1616
},
1717
"repository": {
1818
"type": "git",
19-
"url": "git+https://github.com/firebase/firebase-functions-test.git"
19+
"url": "https://github.com/firebase/firebase-functions-test.git"
2020
},
2121
"keywords": [
2222
"firebase",
@@ -30,6 +30,9 @@
3030
"bugs": {
3131
"url": "https://github.com/firebase/firebase-functions-test/issues"
3232
},
33+
"publishConfig": {
34+
"registry": "https://wombat-dressing-room.appspot.com"
35+
},
3336
"homepage": "https://github.com/firebase/firebase-functions-test#readme",
3437
"dependencies": {
3538
"@types/lodash": "^4.14.104",
@@ -52,7 +55,7 @@
5255
"firebase-admin": ">=6.0.0"
5356
},
5457
"engines": {
55-
"node": ">=6.0.0"
58+
"node": ">=8.0.0"
5659
},
5760
"typings": "lib/index.d.ts"
5861
}

scripts/publish-container/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:8
2+
3+
# Install dependencies
4+
RUN apt-get update && \
5+
apt-get install -y curl git jq
6+
7+
# Install npm at latest.
8+
RUN npm install --global npm@latest
9+
10+
# Install hub
11+
RUN curl -fsSL --output hub.tgz https://github.com/github/hub/releases/download/v2.13.0/hub-linux-amd64-2.13.0.tgz
12+
RUN tar --strip-components=2 -C /usr/bin -xf hub.tgz hub-linux-amd64-2.13.0/bin/hub
13+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
steps:
2+
- name: 'gcr.io/cloud-builders/docker'
3+
args: ['build', '-t', 'gcr.io/$PROJECT_ID/fft-package-builder', '.']
4+
images: ['gcr.io/$PROJECT_ID/fft-package-builder']
5+

scripts/publish/cloudbuild.yaml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
steps:
2+
# Decrypt the SSH key.
3+
- name: 'gcr.io/cloud-builders/gcloud'
4+
args:
5+
[
6+
'kms',
7+
'decrypt',
8+
'--ciphertext-file=deploy_key.enc',
9+
'--plaintext-file=/root/.ssh/id_rsa',
10+
'--location=global',
11+
'--keyring=${_KEY_RING}',
12+
'--key=${_KEY_NAME}',
13+
]
14+
15+
# Decrypt the Twitter credentials.
16+
- name: 'gcr.io/cloud-builders/gcloud'
17+
args:
18+
[
19+
'kms',
20+
'decrypt',
21+
'--ciphertext-file=twitter.json.enc',
22+
'--plaintext-file=twitter.json',
23+
'--location=global',
24+
'--keyring=${_KEY_RING}',
25+
'--key=${_KEY_NAME}',
26+
]
27+
28+
# Decrypt the npm credentials.
29+
- name: 'gcr.io/cloud-builders/gcloud'
30+
args:
31+
[
32+
'kms',
33+
'decrypt',
34+
'--ciphertext-file=npmrc.enc',
35+
'--plaintext-file=npmrc',
36+
'--location=global',
37+
'--keyring=${_KEY_RING}',
38+
'--key=${_KEY_NAME}',
39+
]
40+
41+
# Decrypt the hub (GitHub) credentials.
42+
- name: 'gcr.io/cloud-builders/gcloud'
43+
args:
44+
[
45+
'kms',
46+
'decrypt',
47+
'--ciphertext-file=hub.enc',
48+
'--plaintext-file=hub',
49+
'--location=global',
50+
'--keyring=${_KEY_RING}',
51+
'--key=${_KEY_NAME}',
52+
]
53+
54+
# Set up git with key and domain.
55+
- name: 'gcr.io/cloud-builders/git'
56+
entrypoint: 'bash'
57+
args:
58+
- '-c'
59+
- |
60+
chmod 600 /root/.ssh/id_rsa
61+
cat <<EOF >/root/.ssh/config
62+
Hostname github.com
63+
IdentityFile /root/.ssh/id_rsa
64+
EOF
65+
ssh-keyscan github.com >> /root/.ssh/known_hosts
66+
# Clone the repository.
67+
- name: 'gcr.io/cloud-builders/git'
68+
args: ['clone', '[email protected]:${_REPOSITORY_ORG}/${_REPOSITORY_NAME}']
69+
70+
# Set up the Git configuration.
71+
- name: 'gcr.io/cloud-builders/git'
72+
dir: '${_REPOSITORY_NAME}'
73+
args: ['config', '--global', 'user.email', '[email protected]']
74+
- name: 'gcr.io/cloud-builders/git'
75+
dir: '${_REPOSITORY_NAME}'
76+
args: ['config', '--global', 'user.name', 'Google Open Source Bot']
77+
78+
# Set up the Twitter credentials.
79+
- name: 'gcr.io/$PROJECT_ID/fft-package-builder'
80+
entrypoint: 'cp'
81+
args:
82+
['-v', 'twitter.json', '${_REPOSITORY_NAME}/scripts/publish/twitter.json']
83+
84+
# Set up the npm credentials.
85+
- name: 'gcr.io/$PROJECT_ID/fft-package-builder'
86+
entrypoint: 'bash'
87+
args: ['-c', 'cp -v npmrc ~/.npmrc']
88+
89+
# Set up the hub credentials for fft-package-builder.
90+
- name: 'gcr.io/$PROJECT_ID/fft-package-builder'
91+
entrypoint: 'bash'
92+
args: ['-c', 'mkdir -vp ~/.config && cp -v hub ~/.config/hub']
93+
94+
# Publish the package.
95+
- name: 'gcr.io/$PROJECT_ID/fft-package-builder'
96+
dir: '${_REPOSITORY_NAME}'
97+
args: ['bash', './scripts/publish.sh', '${_VERSION}']
98+
env:
99+
- 'REPOSITORY_ORG=${_REPOSITORY_ORG}'
100+
- 'REPOSITORY_NAME=${_REPOSITORY_NAME}'
101+
- 'DRY_RUN=${_DRY_RUN}'
102+
103+
options:
104+
volumes:
105+
- name: 'ssh'
106+
path: /root/.ssh
107+
108+
substitutions:
109+
_VERSION: ''
110+
_DRY_RUN: ''
111+
_KEY_RING: 'npm-publish-keyring'
112+
_KEY_NAME: 'publish'
113+
_REPOSITORY_ORG: 'firebase'
114+
_REPOSITORY_NAME: 'firebase-functions-test'
115+

scripts/publish/deploy_key.enc

3.42 KB
Binary file not shown.

scripts/publish/hub.enc

191 Bytes
Binary file not shown.

scripts/publish/npmrc.enc

185 Bytes
Binary file not shown.

scripts/publish/publish.sh

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#!/bin/bash
2+
set -e
3+
4+
printusage() {
5+
echo "publish.sh <version>"
6+
echo "REPOSITORY_ORG and REPOSITORY_NAME should be set in the environment."
7+
echo "e.g. REPOSITORY_ORG=user, REPOSITORY_NAME=repo"
8+
echo ""
9+
echo "Arguments:"
10+
echo " version: 'patch', 'minor', or 'major'."
11+
}
12+
13+
VERSION=$1
14+
if [[ $VERSION == "" ]]; then
15+
printusage
16+
exit 1
17+
elif [[ ! ($VERSION == "patch" || $VERSION == "minor" || $VERSION == "major") ]]; then
18+
printusage
19+
exit 1
20+
fi
21+
22+
if [[ $REPOSITORY_ORG == "" ]]; then
23+
printusage
24+
exit 1
25+
fi
26+
if [[ $REPOSITORY_NAME == "" ]]; then
27+
printusage
28+
exit 1
29+
fi
30+
31+
WDIR=$(pwd)
32+
33+
echo "Checking for commands..."
34+
trap "echo 'Missing hub.'; exit 1" ERR
35+
which hub &> /dev/null
36+
trap - ERR
37+
38+
trap "echo 'Missing node.'; exit 1" ERR
39+
which node &> /dev/null
40+
trap - ERR
41+
42+
trap "echo 'Missing jq.'; exit 1" ERR
43+
which jq &> /dev/null
44+
trap - ERR
45+
echo "Checked for commands."
46+
47+
echo "Checking for Twitter credentials..."
48+
trap "echo 'Missing Twitter credentials.'; exit 1" ERR
49+
test -f "${WDIR}/scripts/publish/twitter.json"
50+
trap - ERR
51+
echo "Checked for Twitter credentials..."
52+
53+
echo "Checking for logged-in npm user..."
54+
trap "echo 'Please login to npm using \`npm login --registry https://wombat-dressing-room.appspot.com\`'; exit 1" ERR
55+
npm whoami --registry https://wombat-dressing-room.appspot.com
56+
trap - ERR
57+
echo "Checked for logged-in npm user."
58+
59+
echo "Moving to temporary directory.."
60+
TEMPDIR=$(mktemp -d)
61+
echo "[DEBUG] ${TEMPDIR}"
62+
cd "${TEMPDIR}"
63+
echo "Moved to temporary directory."
64+
65+
echo "Cloning repository..."
66+
git clone "[email protected]:${REPOSITORY_ORG}/${REPOSITORY_NAME}.git"
67+
cd "${REPOSITORY_NAME}"
68+
echo "Cloned repository."
69+
70+
echo "Making sure there is a changelog..."
71+
if [ ! -s CHANGELOG.md ]; then
72+
echo "CHANGELOG.md is empty. aborting."
73+
exit 1
74+
fi
75+
echo "Made sure there is a changelog."
76+
77+
echo "Running npm install..."
78+
npm install
79+
echo "Ran npm install."
80+
81+
echo "Running tests..."
82+
npm test
83+
echo "Ran tests."
84+
85+
echo "Running publish build..."
86+
npm run build:release
87+
echo "Ran publish build."
88+
89+
echo "Making a $VERSION version..."
90+
npm version $VERSION
91+
NEW_VERSION=$(jq -r ".version" package.json)
92+
echo "Made a $VERSION version."
93+
94+
echo "Making the release notes..."
95+
RELEASE_NOTES_FILE=$(mktemp)
96+
echo "[DEBUG] ${RELEASE_NOTES_FILE}"
97+
echo "v${NEW_VERSION}" >> "${RELEASE_NOTES_FILE}"
98+
echo "" >> "${RELEASE_NOTES_FILE}"
99+
cat CHANGELOG.md >> "${RELEASE_NOTES_FILE}"
100+
echo "Made the release notes."
101+
102+
echo "Publishing to npm..."
103+
if [[ $DRY_RUN == "" ]]; then
104+
npm publish
105+
else
106+
echo "DRY RUN: running publish with --dry-run"
107+
npm publish --dry-run
108+
fi
109+
echo "Published to npm."
110+
111+
if [[ $DRY_RUN != "" ]]; then
112+
echo "All other commands are mutations, and we are doing a dry run."
113+
echo "Terminating."
114+
exit
115+
fi
116+
117+
echo "Cleaning up release notes..."
118+
rm CHANGELOG.md
119+
touch CHANGELOG.md
120+
git commit -m "[firebase-release] Removed change log and reset repo after ${NEW_VERSION} release" CHANGELOG.md
121+
echo "Cleaned up release notes."
122+
123+
echo "Pushing to GitHub..."
124+
git push origin master --tags
125+
echo "Pushed to GitHub."
126+
127+
echo "Publishing release notes..."
128+
hub release create --file "${RELEASE_NOTES_FILE}" "v${NEW_VERSION}"
129+
echo "Published release notes."
130+
131+
echo "Making the tweet..."
132+
npm install --no-save [email protected]
133+
cp -v "${WDIR}/scripts/publish/twitter.json" "${TEMPDIR}/${REPOSITORY_NAME}/scripts/"
134+
node ./scripts/publish/tweet.js ${NEW_VERSION}
135+
echo "Made the tweet."
136+

scripts/publish/tweet.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"use strict";
2+
3+
const fs = require("fs");
4+
const Twitter = require("twitter");
5+
6+
function printUsage() {
7+
console.error(
8+
`
9+
Usage: tweet.js <version>
10+
Credentials must be stored in "twitter.json" in this directory.
11+
Arguments:
12+
- version: Version of module that was released. e.g. "1.2.3"
13+
`
14+
);
15+
process.exit(1);
16+
}
17+
18+
function getUrl(version) {
19+
return `https://github.com/firebase/firebase-functions-test/releases/tag/v${version}`;
20+
}
21+
22+
if (process.argv.length !== 3) {
23+
console.error("Missing arguments.");
24+
printUsage();
25+
}
26+
27+
const version = process.argv.pop();
28+
if (!version.match(/^\d+\.\d+\.\d+$/)) {
29+
console.error(`Version "${version}" not a version number.`);
30+
printUsage();
31+
}
32+
33+
if (!fs.existsSync(`${__dirname}/twitter.json`)) {
34+
console.error("Missing credentials.");
35+
printUsage();
36+
}
37+
const creds = require("./twitter.json");
38+
39+
const client = new Twitter(creds);
40+
41+
client.post(
42+
"statuses/update",
43+
{ status: `v${version} of @Firebase Test SDK for Cloud Functions is available. Release notes: ${getUrl(version)}` },
44+
(err) => {
45+
if (err) {
46+
console.error(err);
47+
process.exit(1);
48+
}
49+
}
50+
);
51+

scripts/publish/twitter.json.enc

337 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)