Skip to content

Commit 6873662

Browse files
authored
New Publish Path (#231)
1 parent 2940a4b commit 6873662

File tree

10 files changed

+322
-2
lines changed

10 files changed

+322
-2
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"repository": {
1616
"type": "git",
17-
"url": "git+https://github.com/firebase/firebase-functions.git"
17+
"url": "https://github.com/firebase/firebase-functions.git"
1818
},
1919
"license": "MIT",
2020
"author": "Firebase Team",
@@ -23,10 +23,13 @@
2323
],
2424
"main": "lib/index.js",
2525
"types": "lib/index.d.ts",
26+
"publishConfig": {
27+
"registry": "https://wombat-dressing-room.appspot.com"
28+
},
2629
"scripts": {
2730
"apidocs": "node docgen/generate-docs.js",
2831
"build:pack": "rm -rf lib && npm install && tsc -p tsconfig.release.json && npm pack",
29-
"build:release": "npm install --production && npm install typescript firebase-admin && tsc -p tsconfig.release.json",
32+
"build:release": "npm install --production && npm install --no-save typescript firebase-admin && tsc -p tsconfig.release.json",
3033
"build": "tsc -p tsconfig.release.json",
3134
"format": "prettier --check '**/*.{json,md,ts,yml,yaml}'",
3235
"format:fix": "prettier --write '**/*.{json,md,ts,yml,yaml}'",

scripts/publish-container/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
steps:
2+
- name: 'gcr.io/cloud-builders/docker'
3+
args: ['build', '-t', 'gcr.io/$PROJECT_ID/package-builder', '.']
4+
images: ['gcr.io/$PROJECT_ID/package-builder']

scripts/publish.sh

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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/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/twitter.json" "${TEMPDIR}/${REPOSITORY_NAME}/scripts/"
134+
node ./scripts/tweet.js ${NEW_VERSION}
135+
echo "Made the tweet."

scripts/publish/cloudbuild.yaml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
67+
# Clone the repository.
68+
- name: 'gcr.io/cloud-builders/git'
69+
args: ['clone', '[email protected]:${_REPOSITORY_ORG}/${_REPOSITORY_NAME}']
70+
71+
# Set up the Git configuration.
72+
- name: 'gcr.io/cloud-builders/git'
73+
dir: '${_REPOSITORY_NAME}'
74+
args: ['config', '--global', 'user.email', '[email protected]']
75+
- name: 'gcr.io/cloud-builders/git'
76+
dir: '${_REPOSITORY_NAME}'
77+
args: ['config', '--global', 'user.name', 'Google Open Source Bot']
78+
79+
# Set up the Twitter credentials.
80+
- name: 'gcr.io/$PROJECT_ID/package-builder'
81+
entrypoint: 'cp'
82+
args: ['-v', 'twitter.json', '${_REPOSITORY_NAME}/scripts/twitter.json']
83+
84+
# Set up the npm credentials.
85+
- name: 'gcr.io/$PROJECT_ID/package-builder'
86+
entrypoint: 'bash'
87+
args: ['-c', 'cp -v npmrc ~/.npmrc']
88+
89+
# Set up the hub credentials for package-builder.
90+
- name: 'gcr.io/$PROJECT_ID/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/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'

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/twitter.json.enc

337 Bytes
Binary file not shown.

scripts/tweet.js

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

0 commit comments

Comments
 (0)