Skip to content

Commit 14099d1

Browse files
authored
added scripts, config files and credentials for cloud build process (#646)
1 parent 749e36d commit 14099d1

File tree

9 files changed

+330
-0
lines changed

9 files changed

+330
-0
lines changed

buildtools/container/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:8.16.0
2+
3+
# Install dependencies: curl, git, jq, python2 and jre8.
4+
RUN apt-get update && \
5+
apt-get install -y curl git jq python openjdk-8-jre-headless
6+
7+
# Install npm at 6.10.2.
8+
RUN npm install --global [email protected]
9+
10+
# Install hub
11+
RUN curl -fsSL --output hub.tgz https://github.com/github/hub/releases/download/v2.11.2/hub-linux-amd64-2.11.2.tgz
12+
RUN tar --strip-components=2 -C /usr/bin -xf hub.tgz hub-linux-amd64-2.11.2/bin/hub
13+
14+
# Install the lastest Chrome stable version.
15+
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
16+
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install

buildtools/container/cloudbuild.yaml

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']

buildtools/publish.sh

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/bin/bash
2+
# Copyright 2019 Google Inc. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS-IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Publishes a new version of the firebaseui NPM package. The release notes is
17+
# generated from CHANGELOG.md. You need to login to npm using
18+
# `npm login --registry https://wombat-dressing-room.appspot.com` before running
19+
# this script. The twitter and hub credentials have to be set up.
20+
#
21+
# Usage:
22+
# $ buildtools/publish.sh <major|minor|patch>
23+
24+
# CD to the root FirebaseUI directory, which should be the parent directory of
25+
# buildtools/.
26+
set -e
27+
28+
printusage() {
29+
echo "publish.sh <version>"
30+
echo "REPOSITORY_ORG and REPOSITORY_NAME should be set in the environment."
31+
echo "e.g. REPOSITORY_ORG=user, REPOSITORY_NAME=repo"
32+
echo ""
33+
echo "Arguments:"
34+
echo " version: 'patch', 'minor', or 'major'."
35+
}
36+
37+
VERSION=$1
38+
if [[ $VERSION == "" ]]; then
39+
printusage
40+
exit 1
41+
elif [[ ! ($VERSION == "patch" || \
42+
$VERSION == "minor" || \
43+
$VERSION == "major") ]]; then
44+
printusage
45+
exit 1
46+
fi
47+
48+
if [[ $REPOSITORY_ORG == "" ]]; then
49+
printusage
50+
exit 1
51+
fi
52+
if [[ $REPOSITORY_NAME == "" ]]; then
53+
printusage
54+
exit 1
55+
fi
56+
57+
WDIR=$(pwd)
58+
59+
echo "Checking for commands..."
60+
trap "echo 'Missing hub.'; exit 1" ERR
61+
which hub &> /dev/null
62+
trap - ERR
63+
64+
trap "echo 'Missing node.'; exit 1" ERR
65+
which node &> /dev/null
66+
trap - ERR
67+
68+
trap "echo 'Missing jq.'; exit 1" ERR
69+
which jq &> /dev/null
70+
trap - ERR
71+
72+
trap "echo 'Missing JRE.'; exit 1" ERR
73+
which java &> /dev/null
74+
trap - ERR
75+
76+
trap "echo 'Missing python2.'; exit 1" ERR
77+
which python &> /dev/null
78+
trap - ERR
79+
80+
trap "echo 'Missing Chrome.'; exit 1" ERR
81+
which google-chrome &> /dev/null
82+
trap - ERR
83+
echo "Chrome version:"
84+
google-chrome --version
85+
echo "Checked for commands."
86+
87+
echo "Checking for Twitter credentials..."
88+
trap "echo 'Missing Twitter credentials.'; exit 1" ERR
89+
test -f "${WDIR}/buildtools/twitter.json"
90+
trap - ERR
91+
echo "Checked for Twitter credentials..."
92+
93+
echo "Checking for logged-in npm user..."
94+
trap "echo 'Please login to npm using \`npm login --registry https://wombat-dressing-room.appspot.com\`'; exit 1" ERR
95+
npm whoami --registry https://wombat-dressing-room.appspot.com
96+
trap - ERR
97+
echo "Checked for logged-in npm user."
98+
99+
echo "Moving to temporary directory..."
100+
TEMPDIR=$(mktemp -d)
101+
echo "[DEBUG] ${TEMPDIR}"
102+
cd "${TEMPDIR}"
103+
echo "Moved to temporary directory."
104+
105+
echo "Cloning repository..."
106+
git clone "[email protected]:${REPOSITORY_ORG}/${REPOSITORY_NAME}.git"
107+
cd "${REPOSITORY_NAME}"
108+
echo "Cloned repository."
109+
110+
echo "Making sure there is a changelog..."
111+
if [ ! -s CHANGELOG.md ]; then
112+
echo "CHANGELOG.md is empty. Aborting."
113+
exit 1
114+
fi
115+
echo "Made sure there is a changelog."
116+
117+
echo "Running npm install..."
118+
npm install
119+
echo "Ran npm install."
120+
121+
echo "Making a $VERSION version..."
122+
npm version $VERSION
123+
NEW_VERSION=$(jq -r ".version" package.json)
124+
echo "Made a $VERSION version."
125+
126+
echo "Making the release notes..."
127+
RELEASE_NOTES_FILE=$(mktemp)
128+
echo "[DEBUG] ${RELEASE_NOTES_FILE}"
129+
echo "v${NEW_VERSION}" >> "${RELEASE_NOTES_FILE}"
130+
echo "" >> "${RELEASE_NOTES_FILE}"
131+
cat CHANGELOG.md >> "${RELEASE_NOTES_FILE}"
132+
echo "Made the release notes."
133+
134+
echo "Publishing to npm..."
135+
npm publish
136+
echo "Published to npm."
137+
138+
echo "Cleaning up release notes..."
139+
rm CHANGELOG.md
140+
touch CHANGELOG.md
141+
git commit -m "[firebase-release] Removed change log and reset repo after ${NEW_VERSION} release" CHANGELOG.md
142+
echo "Cleaned up release notes."
143+
144+
echo "Pushing to GitHub..."
145+
git push origin master --tags
146+
echo "Pushed to GitHub."
147+
148+
echo "Publishing release notes..."
149+
hub release create --file "${RELEASE_NOTES_FILE}" "v${NEW_VERSION}"
150+
echo "Published release notes."
151+
152+
echo "Making the tweet..."
153+
npm install --no-save [email protected]
154+
cp -v "${WDIR}/buildtools/twitter.json" "${TEMPDIR}/${REPOSITORY_NAME}/buildtools/"
155+
node ./buildtools/tweet.js ${NEW_VERSION}
156+
echo "Made the tweet."

buildtools/publish/cloudbuild.yaml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
steps:
2+
# Decrypt the SSH key.
3+
- name: 'gcr.io/cloud-builders/gcloud'
4+
args: ['kms', 'decrypt', '--ciphertext-file=deploy_key.enc', '--plaintext-file=/root/.ssh/id_rsa', '--location=global', '--keyring=${_KEY_RING}', '--key=${_KEY_NAME}']
5+
6+
# Decrypt the Twitter credentials.
7+
- name: 'gcr.io/cloud-builders/gcloud'
8+
args: ['kms', 'decrypt', '--ciphertext-file=twitter.json.enc', '--plaintext-file=twitter.json', '--location=global', '--keyring=${_KEY_RING}', '--key=${_KEY_NAME}']
9+
10+
# Decrypt the npm credentials.
11+
- name: 'gcr.io/cloud-builders/gcloud'
12+
args: ['kms', 'decrypt', '--ciphertext-file=npmrc.enc', '--plaintext-file=npmrc', '--location=global', '--keyring=${_KEY_RING}', '--key=${_KEY_NAME}']
13+
14+
# Decrypt the hub (GitHub) credentials.
15+
- name: 'gcr.io/cloud-builders/gcloud'
16+
args: ['kms', 'decrypt', '--ciphertext-file=hub.enc', '--plaintext-file=hub', '--location=global', '--keyring=${_KEY_RING}', '--key=${_KEY_NAME}']
17+
18+
# Set up git with key and domain.
19+
- name: 'gcr.io/cloud-builders/git'
20+
entrypoint: 'bash'
21+
args:
22+
- '-c'
23+
- |
24+
chmod 600 /root/.ssh/id_rsa
25+
cat <<EOF >/root/.ssh/config
26+
Hostname github.com
27+
IdentityFile /root/.ssh/id_rsa
28+
EOF
29+
ssh-keyscan github.com >> /root/.ssh/known_hosts
30+
31+
# Clone the repository.
32+
- name: 'gcr.io/cloud-builders/git'
33+
args: ['clone', '[email protected]:${_REPOSITORY_ORG}/${_REPOSITORY_NAME}']
34+
35+
# Set up the Git configuration.
36+
- name: 'gcr.io/cloud-builders/git'
37+
dir: '${_REPOSITORY_NAME}'
38+
args: ['config', '--global', 'user.email', '[email protected]']
39+
- name: 'gcr.io/cloud-builders/git'
40+
dir: '${_REPOSITORY_NAME}'
41+
args: ['config', '--global', 'user.name', 'Google Open Source Bot']
42+
43+
# Set up the Twitter credentials.
44+
- name: 'gcr.io/$PROJECT_ID/package-builder'
45+
entrypoint: 'cp'
46+
args: ['-v', 'twitter.json', '${_REPOSITORY_NAME}/buildtools/twitter.json']
47+
48+
# Set up the npm credentials.
49+
- name: 'gcr.io/$PROJECT_ID/package-builder'
50+
entrypoint: 'bash'
51+
args: ['-c', 'cp -v npmrc ~/.npmrc']
52+
53+
# Set up the hub credentials.
54+
- name: 'gcr.io/$PROJECT_ID/package-builder'
55+
entrypoint: 'bash'
56+
args: ['-c', 'mkdir -vp ~/.config && cp -v hub ~/.config/hub']
57+
58+
# Publish the package.
59+
- name: 'gcr.io/$PROJECT_ID/package-builder'
60+
dir: '${_REPOSITORY_NAME}'
61+
args: ['bash', './buildtools/publish.sh', '${_VERSION}']
62+
env:
63+
- 'REPOSITORY_ORG=${_REPOSITORY_ORG}'
64+
- 'REPOSITORY_NAME=${_REPOSITORY_NAME}'
65+
66+
timeout: 1800s
67+
68+
options:
69+
volumes:
70+
- name: 'ssh'
71+
path: /root/.ssh
72+
73+
substitutions:
74+
_VERSION: ''
75+
_KEY_RING: 'cloud-build-ring'
76+
_KEY_NAME: 'publish'
77+
_REPOSITORY_ORG: 'firebase'
78+
_REPOSITORY_NAME: 'firebaseui-web'

buildtools/publish/deploy_key.enc

3.42 KB
Binary file not shown.

buildtools/publish/hub.enc

192 Bytes
Binary file not shown.

buildtools/publish/npmrc.enc

184 Bytes
Binary file not shown.

buildtools/publish/twitter.json.enc

337 Bytes
Binary file not shown.

buildtools/tweet.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2019 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
"use strict";
15+
16+
const fs = require('fs');
17+
const Twitter = require('twitter');
18+
19+
/**
20+
* Print the usage of the script.
21+
*/
22+
function printUsage() {
23+
console.error(`
24+
Usage: tweet.js <version>
25+
26+
Credentials must be stored in "twitter.json" in this directory.
27+
28+
Arguments:
29+
- version: Version of module that was released. e.g. "1.2.3"
30+
`);
31+
process.exit(1);
32+
}
33+
34+
/**
35+
* Returns the URL of the release note.
36+
* @param {string} version The version number.
37+
* @return {string} The URL of the release note.
38+
*/
39+
function getUrl(version) {
40+
return `https://github.com/firebase/firebaseui-web/releases/tag/v${version}`;
41+
}
42+
43+
if (process.argv.length !== 3) {
44+
console.error('Missing arguments.');
45+
printUsage();
46+
}
47+
48+
const version = process.argv.pop();
49+
if (!version.match(/^\d+\.\d+\.\d+$/)) {
50+
console.error(`Version "${version}" not a version number.`);
51+
printUsage();
52+
}
53+
54+
// Check Twitter account credential.
55+
if (!fs.existsSync(`${__dirname}/twitter.json`)) {
56+
console.error('Missing credentials.');
57+
printUsage();
58+
}
59+
const creds = require('./twitter.json');
60+
61+
const client = new Twitter(creds);
62+
63+
// Send tweet with release note.
64+
client.post(
65+
'statuses/update',
66+
{
67+
status: `v${version} of @Firebase FirebaseUI for Web is available. ` +
68+
`Release notes: ${getUrl(version)}`
69+
},
70+
(err) => {
71+
if (err) {
72+
console.error(err);
73+
process.exit(1);
74+
}
75+
}
76+
);

0 commit comments

Comments
 (0)